@trpc/server 9.20.3 → 9.23.0
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 +6 -6
- package/adapters/express/dist/trpc-server-adapters-express.cjs.prod.js +6 -6
- package/adapters/express/dist/trpc-server-adapters-express.esm.js +6 -6
- package/adapters/fastify/dist/trpc-server-adapters-fastify.cjs.dev.js +17 -10
- package/adapters/fastify/dist/trpc-server-adapters-fastify.cjs.prod.js +17 -10
- package/adapters/fastify/dist/trpc-server-adapters-fastify.esm.js +17 -10
- package/adapters/next/dist/trpc-server-adapters-next.cjs.dev.js +4 -4
- package/adapters/next/dist/trpc-server-adapters-next.cjs.prod.js +4 -4
- package/adapters/next/dist/trpc-server-adapters-next.esm.js +4 -4
- package/adapters/node-http/dist/trpc-server-adapters-node-http.cjs.dev.js +4 -4
- package/adapters/node-http/dist/trpc-server-adapters-node-http.cjs.prod.js +4 -4
- package/adapters/node-http/dist/trpc-server-adapters-node-http.esm.js +4 -4
- package/adapters/standalone/dist/trpc-server-adapters-standalone.cjs.dev.js +4 -4
- package/adapters/standalone/dist/trpc-server-adapters-standalone.cjs.prod.js +4 -4
- package/adapters/standalone/dist/trpc-server-adapters-standalone.esm.js +4 -4
- package/adapters/ws/dist/trpc-server-adapters-ws.cjs.dev.js +4 -4
- package/adapters/ws/dist/trpc-server-adapters-ws.cjs.prod.js +4 -4
- package/adapters/ws/dist/trpc-server-adapters-ws.esm.js +4 -4
- package/dist/{codes-33cef953.cjs.dev.js → codes-130e62df.cjs.dev.js} +2 -0
- package/dist/{codes-fe07bf82.esm.js → codes-5678cc97.esm.js} +2 -0
- package/dist/{codes-e0df67c4.cjs.prod.js → codes-aff770a3.cjs.prod.js} +2 -0
- package/dist/declarations/src/TRPCError.d.ts +1 -1
- package/dist/declarations/src/TRPCError.d.ts.map +1 -1
- package/dist/declarations/src/adapters/fastify/fastifyRequestHandler.d.ts +2 -2
- package/dist/declarations/src/adapters/fastify/fastifyRequestHandler.d.ts.map +1 -1
- package/dist/declarations/src/adapters/fastify/fastifyTRPCPlugin.d.ts +1 -1
- package/dist/declarations/src/adapters/fastify/fastifyTRPCPlugin.d.ts.map +1 -1
- package/dist/declarations/src/adapters/next.d.ts +1 -1
- package/dist/declarations/src/adapters/next.d.ts.map +1 -1
- package/dist/declarations/src/adapters/node-http/nodeHTTPRequestHandler.d.ts +1 -1
- package/dist/declarations/src/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
- package/dist/declarations/src/adapters/standalone.d.ts.map +1 -1
- package/dist/declarations/src/adapters/ws.d.ts.map +1 -1
- package/dist/declarations/src/deprecated/createHttpServer.d.ts +1 -1
- package/dist/declarations/src/deprecated/createHttpServer.d.ts.map +1 -1
- package/dist/declarations/src/deprecated/requestHandler.d.ts +1 -1
- package/dist/declarations/src/deprecated/requestHandler.d.ts.map +1 -1
- package/dist/declarations/src/http/internals/getHTTPStatusCode.d.ts +2 -1
- package/dist/declarations/src/http/internals/getHTTPStatusCode.d.ts.map +1 -1
- package/dist/declarations/src/http/internals/types.d.ts +1 -1
- package/dist/declarations/src/http/internals/types.d.ts.map +1 -1
- package/dist/declarations/src/http/resolveHTTPResponse.d.ts +2 -2
- package/dist/declarations/src/http/resolveHTTPResponse.d.ts.map +1 -1
- package/dist/declarations/src/internals/BaseHandlerOptions.d.ts +1 -1
- package/dist/declarations/src/internals/BaseHandlerOptions.d.ts.map +1 -1
- package/dist/declarations/src/internals/OnErrorFunction.d.ts +1 -1
- package/dist/declarations/src/internals/OnErrorFunction.d.ts.map +1 -1
- package/dist/declarations/src/internals/middlewares.d.ts +3 -2
- package/dist/declarations/src/internals/middlewares.d.ts.map +1 -1
- package/dist/declarations/src/internals/procedure.d.ts +47 -34
- package/dist/declarations/src/internals/procedure.d.ts.map +1 -1
- package/dist/declarations/src/router.d.ts +34 -30
- package/dist/declarations/src/router.d.ts.map +1 -1
- package/dist/declarations/src/rpc/codes.d.ts +2 -0
- package/dist/declarations/src/rpc/codes.d.ts.map +1 -1
- package/dist/declarations/src/types.d.ts +8 -0
- package/dist/declarations/src/types.d.ts.map +1 -1
- package/dist/{nodeHTTPRequestHandler-2cc444d8.cjs.dev.js → nodeHTTPRequestHandler-36ddaba2.cjs.dev.js} +2 -2
- package/dist/{nodeHTTPRequestHandler-d00c1126.esm.js → nodeHTTPRequestHandler-372a4a4f.esm.js} +2 -2
- package/dist/{nodeHTTPRequestHandler-8ddacc19.cjs.prod.js → nodeHTTPRequestHandler-91e7ca3d.cjs.prod.js} +2 -2
- package/dist/{resolveHTTPResponse-562c3d62.cjs.prod.js → resolveHTTPResponse-02e61299.cjs.prod.js} +3 -2
- package/dist/{resolveHTTPResponse-3867844c.cjs.dev.js → resolveHTTPResponse-55b2c9bd.cjs.dev.js} +3 -2
- package/dist/{resolveHTTPResponse-85f3f5df.esm.js → resolveHTTPResponse-ddb56677.esm.js} +3 -2
- package/dist/{subscription-fbda2888.esm.js → subscription-2ea469a3.esm.js} +2 -2
- package/dist/{subscription-c2e0bfbc.cjs.prod.js → subscription-7de48383.cjs.dev.js} +2 -2
- package/dist/{subscription-b8831081.cjs.dev.js → subscription-f03bec71.cjs.prod.js} +2 -2
- package/dist/{transformTRPCResponse-8248515e.cjs.dev.js → transformTRPCResponse-1e125b28.cjs.prod.js} +38 -38
- package/dist/{transformTRPCResponse-f73dc4a2.esm.js → transformTRPCResponse-45c225c3.esm.js} +38 -38
- package/dist/{transformTRPCResponse-dcbf66c5.cjs.prod.js → transformTRPCResponse-c654ea92.cjs.dev.js} +38 -38
- package/dist/trpc-server.cjs.dev.js +45 -19
- package/dist/trpc-server.cjs.prod.js +45 -19
- package/dist/trpc-server.esm.js +47 -21
- package/package.json +4 -4
- package/rpc/dist/trpc-server-rpc.cjs.dev.js +1 -1
- package/rpc/dist/trpc-server-rpc.cjs.prod.js +1 -1
- package/rpc/dist/trpc-server-rpc.esm.js +1 -1
- package/src/TRPCError.ts +1 -1
- package/src/adapters/express.ts +2 -2
- package/src/adapters/fastify/fastifyRequestHandler.ts +7 -8
- package/src/adapters/fastify/fastifyTRPCPlugin.ts +14 -6
- package/src/adapters/next.ts +6 -2
- package/src/adapters/node-http/internals/getPostBody.test.ts +2 -1
- package/src/adapters/node-http/nodeHTTPRequestHandler.ts +5 -5
- package/src/adapters/standalone.ts +1 -0
- package/src/adapters/ws.ts +4 -4
- package/src/deprecated/createHttpServer.ts +2 -2
- package/src/deprecated/requestHandler.ts +2 -2
- package/src/http/internals/getHTTPStatusCode.ts +2 -1
- package/src/http/internals/types.ts +2 -2
- package/src/http/resolveHTTPResponse.ts +3 -3
- package/src/internals/BaseHandlerOptions.ts +1 -1
- package/src/internals/OnErrorFunction.ts +1 -1
- package/src/internals/middlewares.ts +3 -2
- package/src/internals/procedure.ts +176 -68
- package/src/router.ts +172 -52
- package/src/rpc/codes.ts +1 -0
- package/src/subscription.ts +1 -1
- package/src/types.ts +7 -0
- package/ws/dist/trpc-server-ws.cjs.dev.js +2 -2
- package/ws/dist/trpc-server-ws.cjs.prod.js +2 -2
- package/ws/dist/trpc-server-ws.esm.js +2 -2
package/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
|
|
|
@@ -37,20 +38,30 @@ export type ProcedureType = 'query' | 'mutation' | 'subscription';
|
|
|
37
38
|
export type ProcedureRecord<
|
|
38
39
|
TInputContext = any,
|
|
39
40
|
TContext = any,
|
|
41
|
+
TMeta = any,
|
|
40
42
|
TInput = any,
|
|
41
43
|
TParsedInput = any,
|
|
42
44
|
TOutput = any,
|
|
45
|
+
TParsedOutput = any,
|
|
43
46
|
> = Record<
|
|
44
47
|
string,
|
|
45
|
-
Procedure<
|
|
48
|
+
Procedure<
|
|
49
|
+
TInputContext,
|
|
50
|
+
TContext,
|
|
51
|
+
TMeta,
|
|
52
|
+
TInput,
|
|
53
|
+
TParsedInput,
|
|
54
|
+
TOutput,
|
|
55
|
+
TParsedOutput
|
|
56
|
+
>
|
|
46
57
|
>;
|
|
47
58
|
|
|
48
59
|
/**
|
|
49
60
|
* @public
|
|
50
61
|
*/
|
|
51
62
|
export type inferProcedureInput<
|
|
52
|
-
TProcedure extends Procedure<any, any, any, any, any>,
|
|
53
|
-
> = TProcedure extends Procedure<any, any, infer Input, any, any>
|
|
63
|
+
TProcedure extends Procedure<any, any, any, any, any, any, any>,
|
|
64
|
+
> = TProcedure extends Procedure<any, any, any, infer Input, any, any, any>
|
|
54
65
|
? undefined extends Input
|
|
55
66
|
? Input | null | void // void is necessary to allow procedures with nullish input to be called without an input
|
|
56
67
|
: Input
|
|
@@ -66,7 +77,7 @@ export type inferAsyncReturnType<TFunction extends (...args: any) => any> =
|
|
|
66
77
|
* @public
|
|
67
78
|
*/
|
|
68
79
|
export type inferProcedureOutput<
|
|
69
|
-
TProcedure extends Procedure<any, any, any, any, any>,
|
|
80
|
+
TProcedure extends Procedure<any, any, any, any, any, any, any>,
|
|
70
81
|
> = inferAsyncReturnType<TProcedure['call']>;
|
|
71
82
|
|
|
72
83
|
/**
|
|
@@ -94,8 +105,8 @@ function getDataTransformer(
|
|
|
94
105
|
* @internal
|
|
95
106
|
*/
|
|
96
107
|
export type inferHandlerInput<
|
|
97
|
-
TProcedure extends Procedure<any, any, any, any, any>,
|
|
98
|
-
> = TProcedure extends Procedure<any, any, infer TInput, any, any>
|
|
108
|
+
TProcedure extends Procedure<any, any, any, any, any, any, any>,
|
|
109
|
+
> = TProcedure extends Procedure<any, any, any, infer TInput, any, any, any>
|
|
99
110
|
? undefined extends TInput // ? is input optional
|
|
100
111
|
? unknown extends TInput // ? is input unset
|
|
101
112
|
? [(null | undefined)?] // -> there is no input
|
|
@@ -118,6 +129,21 @@ export type inferRouterContext<TRouter extends AnyRouter> = Parameters<
|
|
|
118
129
|
TRouter['createCaller']
|
|
119
130
|
>[0];
|
|
120
131
|
|
|
132
|
+
/**
|
|
133
|
+
* @internal
|
|
134
|
+
*/
|
|
135
|
+
export type inferRouterMeta<TRouter extends AnyRouter> = TRouter extends Router<
|
|
136
|
+
any,
|
|
137
|
+
any,
|
|
138
|
+
infer TMeta,
|
|
139
|
+
any,
|
|
140
|
+
any,
|
|
141
|
+
any,
|
|
142
|
+
any
|
|
143
|
+
>
|
|
144
|
+
? TMeta
|
|
145
|
+
: {};
|
|
146
|
+
|
|
121
147
|
/**
|
|
122
148
|
* @public
|
|
123
149
|
*/
|
|
@@ -127,6 +153,7 @@ export type AnyRouter<TContext = any> = Router<
|
|
|
127
153
|
any,
|
|
128
154
|
any,
|
|
129
155
|
any,
|
|
156
|
+
any,
|
|
130
157
|
any
|
|
131
158
|
>;
|
|
132
159
|
|
|
@@ -205,21 +232,31 @@ const defaultTransformer: CombinedDataTransformer = {
|
|
|
205
232
|
};
|
|
206
233
|
|
|
207
234
|
type SwapProcedureContext<
|
|
208
|
-
TProcedure extends Procedure<any, any, any, any, any>,
|
|
235
|
+
TProcedure extends Procedure<any, any, any, any, any, any, any>,
|
|
209
236
|
TNewContext,
|
|
210
237
|
> = TProcedure extends Procedure<
|
|
211
238
|
infer TInputContext,
|
|
212
239
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
213
240
|
infer _TOldContext,
|
|
241
|
+
infer TMeta,
|
|
214
242
|
infer TInput,
|
|
215
243
|
infer TParsedInput,
|
|
216
|
-
infer TOutput
|
|
244
|
+
infer TOutput,
|
|
245
|
+
infer TParsedOutput
|
|
217
246
|
>
|
|
218
|
-
? Procedure<
|
|
247
|
+
? Procedure<
|
|
248
|
+
TInputContext,
|
|
249
|
+
TNewContext,
|
|
250
|
+
TMeta,
|
|
251
|
+
TInput,
|
|
252
|
+
TParsedInput,
|
|
253
|
+
TOutput,
|
|
254
|
+
TParsedOutput
|
|
255
|
+
>
|
|
219
256
|
: never;
|
|
220
257
|
|
|
221
258
|
type SwapContext<
|
|
222
|
-
TObj extends ProcedureRecord<any, any, any, any>,
|
|
259
|
+
TObj extends ProcedureRecord<any, any, any, any, any, any>,
|
|
223
260
|
TNewContext,
|
|
224
261
|
> = {
|
|
225
262
|
[P in keyof TObj]: SwapProcedureContext<TObj[P], TNewContext>;
|
|
@@ -231,13 +268,33 @@ type SwapContext<
|
|
|
231
268
|
export class Router<
|
|
232
269
|
TInputContext,
|
|
233
270
|
TContext,
|
|
234
|
-
|
|
235
|
-
|
|
271
|
+
TMeta extends Record<string, any>,
|
|
272
|
+
TQueries extends ProcedureRecord<
|
|
273
|
+
TInputContext,
|
|
274
|
+
TContext,
|
|
275
|
+
any,
|
|
276
|
+
any,
|
|
277
|
+
any,
|
|
278
|
+
any,
|
|
279
|
+
any
|
|
280
|
+
>,
|
|
281
|
+
TMutations extends ProcedureRecord<
|
|
282
|
+
TInputContext,
|
|
283
|
+
TContext,
|
|
284
|
+
any,
|
|
285
|
+
any,
|
|
286
|
+
any,
|
|
287
|
+
any,
|
|
288
|
+
any
|
|
289
|
+
>,
|
|
236
290
|
TSubscriptions extends ProcedureRecord<
|
|
237
291
|
TInputContext,
|
|
238
292
|
TContext,
|
|
239
293
|
unknown,
|
|
240
|
-
|
|
294
|
+
unknown,
|
|
295
|
+
Subscription<unknown>,
|
|
296
|
+
unknown,
|
|
297
|
+
unknown
|
|
241
298
|
>,
|
|
242
299
|
TErrorShape extends TRPCErrorShape<number>,
|
|
243
300
|
> {
|
|
@@ -245,7 +302,7 @@ export class Router<
|
|
|
245
302
|
queries: TQueries;
|
|
246
303
|
mutations: TMutations;
|
|
247
304
|
subscriptions: TSubscriptions;
|
|
248
|
-
middlewares: MiddlewareFunction<TInputContext, TContext>[];
|
|
305
|
+
middlewares: MiddlewareFunction<TInputContext, TContext, TMeta>[];
|
|
249
306
|
errorFormatter: ErrorFormatter<TContext, TErrorShape>;
|
|
250
307
|
transformer: CombinedDataTransformer;
|
|
251
308
|
};
|
|
@@ -254,7 +311,7 @@ export class Router<
|
|
|
254
311
|
queries?: TQueries;
|
|
255
312
|
mutations?: TMutations;
|
|
256
313
|
subscriptions?: TSubscriptions;
|
|
257
|
-
middlewares?: MiddlewareFunction<TInputContext, TContext>[];
|
|
314
|
+
middlewares?: MiddlewareFunction<TInputContext, TContext, TMeta>[];
|
|
258
315
|
errorFormatter?: ErrorFormatter<TContext, TErrorShape>;
|
|
259
316
|
transformer?: CombinedDataTransformer;
|
|
260
317
|
}) {
|
|
@@ -279,29 +336,40 @@ export class Router<
|
|
|
279
336
|
return eps as any;
|
|
280
337
|
}
|
|
281
338
|
|
|
282
|
-
public query<
|
|
339
|
+
public query<
|
|
340
|
+
TPath extends string,
|
|
341
|
+
TInput,
|
|
342
|
+
TParsedInput,
|
|
343
|
+
TOutput,
|
|
344
|
+
TParsedOutput,
|
|
345
|
+
>(
|
|
283
346
|
path: TPath,
|
|
284
347
|
procedure: CreateProcedureWithInputOutputParser<
|
|
285
348
|
TContext,
|
|
349
|
+
TMeta,
|
|
286
350
|
TInput,
|
|
287
351
|
TParsedInput,
|
|
288
|
-
TOutput
|
|
352
|
+
TOutput,
|
|
353
|
+
TParsedOutput
|
|
289
354
|
>,
|
|
290
355
|
): Router<
|
|
291
356
|
TInputContext,
|
|
292
357
|
TContext,
|
|
358
|
+
TMeta,
|
|
293
359
|
TQueries &
|
|
294
360
|
Record<TPath, inferProcedureFromOptions<TInputContext, typeof procedure>>,
|
|
295
361
|
TMutations,
|
|
296
362
|
TSubscriptions,
|
|
297
363
|
TErrorShape
|
|
298
364
|
>;
|
|
365
|
+
|
|
299
366
|
public query<TPath extends string, TInput, TOutput>(
|
|
300
367
|
path: TPath,
|
|
301
|
-
procedure: CreateProcedureWithInput<TContext,
|
|
368
|
+
procedure: CreateProcedureWithInput<TContext, TMeta, TInput, TOutput>,
|
|
302
369
|
): Router<
|
|
303
370
|
TInputContext,
|
|
304
371
|
TContext,
|
|
372
|
+
TMeta,
|
|
305
373
|
TQueries &
|
|
306
374
|
Record<TPath, inferProcedureFromOptions<TInputContext, typeof procedure>>,
|
|
307
375
|
TMutations,
|
|
@@ -309,12 +377,18 @@ export class Router<
|
|
|
309
377
|
TErrorShape
|
|
310
378
|
>;
|
|
311
379
|
|
|
312
|
-
public query<TPath extends string, TOutput>(
|
|
380
|
+
public query<TPath extends string, TOutput, TParsedOutput>(
|
|
313
381
|
path: TPath,
|
|
314
|
-
procedure: CreateProcedureWithoutInput<
|
|
382
|
+
procedure: CreateProcedureWithoutInput<
|
|
383
|
+
TContext,
|
|
384
|
+
TMeta,
|
|
385
|
+
TOutput,
|
|
386
|
+
TParsedOutput
|
|
387
|
+
>,
|
|
315
388
|
): Router<
|
|
316
389
|
TInputContext,
|
|
317
390
|
TContext,
|
|
391
|
+
TMeta,
|
|
318
392
|
TQueries &
|
|
319
393
|
Record<TPath, inferProcedureFromOptions<TInputContext, typeof procedure>>,
|
|
320
394
|
TMutations,
|
|
@@ -324,9 +398,9 @@ export class Router<
|
|
|
324
398
|
|
|
325
399
|
query(
|
|
326
400
|
path: string,
|
|
327
|
-
procedure: CreateProcedureOptions<TContext, any, any, any>,
|
|
401
|
+
procedure: CreateProcedureOptions<TContext, TMeta, any, any, any, any>,
|
|
328
402
|
) {
|
|
329
|
-
const router = new Router<TContext, TContext, any, {}, {}, any>({
|
|
403
|
+
const router = new Router<TContext, TContext, TMeta, any, {}, {}, any>({
|
|
330
404
|
queries: safeObject({
|
|
331
405
|
[path]: createProcedure(procedure),
|
|
332
406
|
}),
|
|
@@ -335,29 +409,40 @@ export class Router<
|
|
|
335
409
|
return this.merge(router);
|
|
336
410
|
}
|
|
337
411
|
|
|
338
|
-
public mutation<
|
|
412
|
+
public mutation<
|
|
413
|
+
TPath extends string,
|
|
414
|
+
TInput,
|
|
415
|
+
TParsedInput,
|
|
416
|
+
TOutput,
|
|
417
|
+
TParsedOutput,
|
|
418
|
+
>(
|
|
339
419
|
path: TPath,
|
|
340
420
|
procedure: CreateProcedureWithInputOutputParser<
|
|
341
421
|
TContext,
|
|
422
|
+
TMeta,
|
|
342
423
|
TInput,
|
|
343
424
|
TParsedInput,
|
|
344
|
-
TOutput
|
|
425
|
+
TOutput,
|
|
426
|
+
TParsedOutput
|
|
345
427
|
>,
|
|
346
428
|
): Router<
|
|
347
429
|
TInputContext,
|
|
348
430
|
TContext,
|
|
431
|
+
TMeta,
|
|
349
432
|
TQueries,
|
|
350
433
|
TMutations &
|
|
351
434
|
Record<TPath, inferProcedureFromOptions<TInputContext, typeof procedure>>,
|
|
352
435
|
TSubscriptions,
|
|
353
436
|
TErrorShape
|
|
354
437
|
>;
|
|
438
|
+
|
|
355
439
|
public mutation<TPath extends string, TInput, TOutput>(
|
|
356
440
|
path: TPath,
|
|
357
|
-
procedure: CreateProcedureWithInput<TContext,
|
|
441
|
+
procedure: CreateProcedureWithInput<TContext, TMeta, TInput, TOutput>,
|
|
358
442
|
): Router<
|
|
359
443
|
TInputContext,
|
|
360
444
|
TContext,
|
|
445
|
+
TMeta,
|
|
361
446
|
TQueries,
|
|
362
447
|
TMutations &
|
|
363
448
|
Record<TPath, inferProcedureFromOptions<TInputContext, typeof procedure>>,
|
|
@@ -365,12 +450,18 @@ export class Router<
|
|
|
365
450
|
TErrorShape
|
|
366
451
|
>;
|
|
367
452
|
|
|
368
|
-
public mutation<TPath extends string, TOutput>(
|
|
453
|
+
public mutation<TPath extends string, TOutput, TParsedOutput>(
|
|
369
454
|
path: TPath,
|
|
370
|
-
procedure: CreateProcedureWithoutInput<
|
|
455
|
+
procedure: CreateProcedureWithoutInput<
|
|
456
|
+
TContext,
|
|
457
|
+
TMeta,
|
|
458
|
+
TOutput,
|
|
459
|
+
TParsedOutput
|
|
460
|
+
>,
|
|
371
461
|
): Router<
|
|
372
462
|
TInputContext,
|
|
373
463
|
TContext,
|
|
464
|
+
TMeta,
|
|
374
465
|
TQueries,
|
|
375
466
|
TMutations &
|
|
376
467
|
Record<TPath, inferProcedureFromOptions<TInputContext, typeof procedure>>,
|
|
@@ -380,9 +471,9 @@ export class Router<
|
|
|
380
471
|
|
|
381
472
|
public mutation(
|
|
382
473
|
path: string,
|
|
383
|
-
procedure: CreateProcedureOptions<TContext, any, any, any>,
|
|
474
|
+
procedure: CreateProcedureOptions<TContext, TMeta, any, any, any, any>,
|
|
384
475
|
) {
|
|
385
|
-
const router = new Router<TContext, TContext, {}, any, {}, any>({
|
|
476
|
+
const router = new Router<TContext, TContext, TMeta, {}, any, {}, any>({
|
|
386
477
|
mutations: safeObject({
|
|
387
478
|
[path]: createProcedure(procedure),
|
|
388
479
|
}),
|
|
@@ -401,15 +492,21 @@ export class Router<
|
|
|
401
492
|
TOutput extends Subscription<unknown>,
|
|
402
493
|
>(
|
|
403
494
|
path: TPath,
|
|
404
|
-
procedure:
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
495
|
+
procedure: Omit<
|
|
496
|
+
CreateProcedureWithInputOutputParser<
|
|
497
|
+
TContext,
|
|
498
|
+
TMeta,
|
|
499
|
+
TInput,
|
|
500
|
+
TParsedInput,
|
|
501
|
+
TOutput,
|
|
502
|
+
unknown
|
|
503
|
+
>,
|
|
504
|
+
'output'
|
|
409
505
|
>,
|
|
410
506
|
): Router<
|
|
411
507
|
TInputContext,
|
|
412
508
|
TContext,
|
|
509
|
+
TMeta,
|
|
413
510
|
TQueries,
|
|
414
511
|
TMutations,
|
|
415
512
|
TSubscriptions &
|
|
@@ -426,10 +523,14 @@ export class Router<
|
|
|
426
523
|
TOutput extends Subscription<unknown>,
|
|
427
524
|
>(
|
|
428
525
|
path: TPath,
|
|
429
|
-
procedure:
|
|
526
|
+
procedure: Omit<
|
|
527
|
+
CreateProcedureWithInput<TContext, TMeta, TInput, TOutput>,
|
|
528
|
+
'output'
|
|
529
|
+
>,
|
|
430
530
|
): Router<
|
|
431
531
|
TInputContext,
|
|
432
532
|
TContext,
|
|
533
|
+
TMeta,
|
|
433
534
|
TQueries,
|
|
434
535
|
TMutations,
|
|
435
536
|
TSubscriptions &
|
|
@@ -445,10 +546,14 @@ export class Router<
|
|
|
445
546
|
TOutput extends Subscription<unknown>,
|
|
446
547
|
>(
|
|
447
548
|
path: TPath,
|
|
448
|
-
procedure:
|
|
549
|
+
procedure: Omit<
|
|
550
|
+
CreateProcedureWithoutInput<TContext, TMeta, TOutput, unknown>,
|
|
551
|
+
'output'
|
|
552
|
+
>,
|
|
449
553
|
): Router<
|
|
450
554
|
TInputContext,
|
|
451
555
|
TContext,
|
|
556
|
+
TMeta,
|
|
452
557
|
TQueries,
|
|
453
558
|
TMutations,
|
|
454
559
|
TSubscriptions &
|
|
@@ -458,9 +563,12 @@ export class Router<
|
|
|
458
563
|
|
|
459
564
|
public subscription(
|
|
460
565
|
path: string,
|
|
461
|
-
procedure:
|
|
566
|
+
procedure: Omit<
|
|
567
|
+
CreateProcedureOptions<TContext, TMeta, any, any, any, any>,
|
|
568
|
+
'output'
|
|
569
|
+
>,
|
|
462
570
|
) {
|
|
463
|
-
const router = new Router<TContext, TContext, {}, {}, any, any>({
|
|
571
|
+
const router = new Router<TContext, TContext, TMeta, {}, {}, any, any>({
|
|
464
572
|
subscriptions: safeObject({
|
|
465
573
|
[path]: createProcedure(procedure),
|
|
466
574
|
}),
|
|
@@ -473,11 +581,14 @@ export class Router<
|
|
|
473
581
|
* Merge router with other router
|
|
474
582
|
* @param router
|
|
475
583
|
*/
|
|
476
|
-
public merge<
|
|
584
|
+
public merge<
|
|
585
|
+
TChildRouter extends Router<TContext, any, TMeta, any, any, any, any>,
|
|
586
|
+
>(
|
|
477
587
|
router: TChildRouter,
|
|
478
588
|
): Router<
|
|
479
589
|
TInputContext,
|
|
480
590
|
inferRouterContext<TChildRouter>,
|
|
591
|
+
TMeta,
|
|
481
592
|
TQueries & TChildRouter['_def']['queries'],
|
|
482
593
|
TMutations & TChildRouter['_def']['mutations'],
|
|
483
594
|
TSubscriptions & TChildRouter['_def']['subscriptions'],
|
|
@@ -491,13 +602,14 @@ export class Router<
|
|
|
491
602
|
*/
|
|
492
603
|
public merge<
|
|
493
604
|
TPath extends string,
|
|
494
|
-
TChildRouter extends Router<TContext, any, any, any, any, any>,
|
|
605
|
+
TChildRouter extends Router<TContext, any, TMeta, any, any, any, any>,
|
|
495
606
|
>(
|
|
496
607
|
prefix: TPath,
|
|
497
608
|
router: TChildRouter,
|
|
498
609
|
): Router<
|
|
499
610
|
TInputContext,
|
|
500
611
|
inferRouterContext<TChildRouter>,
|
|
612
|
+
TMeta,
|
|
501
613
|
TQueries & Prefixer<TChildRouter['_def']['queries'], `${TPath}`>,
|
|
502
614
|
TMutations & Prefixer<TChildRouter['_def']['mutations'], `${TPath}`>,
|
|
503
615
|
TSubscriptions &
|
|
@@ -550,7 +662,7 @@ export class Router<
|
|
|
550
662
|
return Router.prefixProcedures(newDefs, prefix);
|
|
551
663
|
};
|
|
552
664
|
|
|
553
|
-
return new Router<TInputContext, any, any, any, any, TErrorShape>({
|
|
665
|
+
return new Router<TInputContext, any, TMeta, any, any, any, TErrorShape>({
|
|
554
666
|
...this._def,
|
|
555
667
|
queries: safeObject(
|
|
556
668
|
this._def.queries,
|
|
@@ -577,7 +689,7 @@ export class Router<
|
|
|
577
689
|
const defTarget = PROCEDURE_DEFINITION_MAP[type];
|
|
578
690
|
const defs = this._def[defTarget];
|
|
579
691
|
const procedure = defs[path] as
|
|
580
|
-
| Procedure<TInputContext, TContext, any, any, any>
|
|
692
|
+
| Procedure<TInputContext, TContext, TMeta, any, any, any, any>
|
|
581
693
|
| undefined;
|
|
582
694
|
|
|
583
695
|
if (!procedure) {
|
|
@@ -628,10 +740,11 @@ export class Router<
|
|
|
628
740
|
* @link https://trpc.io/docs/middlewares
|
|
629
741
|
*/
|
|
630
742
|
public middleware<TNewContext>(
|
|
631
|
-
middleware: MiddlewareFunction<TContext, TNewContext>,
|
|
743
|
+
middleware: MiddlewareFunction<TContext, TNewContext, TMeta>,
|
|
632
744
|
): Router<
|
|
633
745
|
TInputContext,
|
|
634
746
|
TNewContext,
|
|
747
|
+
TMeta,
|
|
635
748
|
SwapContext<TQueries, TNewContext>,
|
|
636
749
|
SwapContext<TMutations, TNewContext>,
|
|
637
750
|
SwapContext<TSubscriptions, TNewContext>,
|
|
@@ -658,6 +771,7 @@ export class Router<
|
|
|
658
771
|
return new Router<
|
|
659
772
|
TInputContext,
|
|
660
773
|
TContext,
|
|
774
|
+
TMeta,
|
|
661
775
|
TQueries,
|
|
662
776
|
TMutations,
|
|
663
777
|
TSubscriptions,
|
|
@@ -712,6 +826,7 @@ export class Router<
|
|
|
712
826
|
return new Router<
|
|
713
827
|
TInputContext,
|
|
714
828
|
TContext,
|
|
829
|
+
TMeta,
|
|
715
830
|
TQueries,
|
|
716
831
|
TMutations,
|
|
717
832
|
TSubscriptions,
|
|
@@ -731,6 +846,7 @@ export class Router<
|
|
|
731
846
|
public flat(): Router<
|
|
732
847
|
TInputContext,
|
|
733
848
|
TContext,
|
|
849
|
+
TMeta,
|
|
734
850
|
flatten<{}, TQueries>,
|
|
735
851
|
flatten<{}, TMutations>,
|
|
736
852
|
flatten<{}, TSubscriptions>,
|
|
@@ -747,24 +863,28 @@ export class Router<
|
|
|
747
863
|
*/
|
|
748
864
|
export class LegacyRouter<
|
|
749
865
|
TContext,
|
|
750
|
-
|
|
751
|
-
|
|
866
|
+
TMeta extends Record<string, any>,
|
|
867
|
+
TQueries extends ProcedureRecord<TContext, TContext, any, any, any, any>,
|
|
868
|
+
TMutations extends ProcedureRecord<TContext, TContext, any, any, any, any>,
|
|
752
869
|
TSubscriptions extends ProcedureRecord<
|
|
753
870
|
TContext,
|
|
754
871
|
TContext,
|
|
755
872
|
unknown,
|
|
756
|
-
|
|
873
|
+
unknown,
|
|
874
|
+
Subscription<unknown>,
|
|
875
|
+
unknown
|
|
757
876
|
>,
|
|
758
877
|
TErrorShape extends TRPCErrorShape<number>,
|
|
759
878
|
> extends Router<
|
|
760
879
|
TContext,
|
|
761
880
|
TContext,
|
|
881
|
+
TMeta,
|
|
762
882
|
TQueries,
|
|
763
883
|
TMutations,
|
|
764
884
|
TSubscriptions,
|
|
765
885
|
TErrorShape
|
|
766
886
|
> {}
|
|
767
887
|
|
|
768
|
-
export function router<TContext>() {
|
|
769
|
-
return new Router<TContext, TContext, {}, {}, {}, DefaultErrorShape>();
|
|
888
|
+
export function router<TContext, TMeta extends Record<string, any> = {}>() {
|
|
889
|
+
return new Router<TContext, TContext, TMeta, {}, {}, {}, DefaultErrorShape>();
|
|
770
890
|
}
|
package/src/rpc/codes.ts
CHANGED
|
@@ -28,6 +28,7 @@ export const TRPC_ERROR_CODES_BY_KEY = {
|
|
|
28
28
|
NOT_FOUND: -32004, // 404
|
|
29
29
|
METHOD_NOT_SUPPORTED: -32005, // 405
|
|
30
30
|
TIMEOUT: -32008, // 408
|
|
31
|
+
CONFLICT: -32009, // 409
|
|
31
32
|
PRECONDITION_FAILED: -32012, // 412
|
|
32
33
|
PAYLOAD_TOO_LARGE: -32013, // 413
|
|
33
34
|
CLIENT_CLOSED_REQUEST: -32099, // 499
|
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;
|
package/src/types.ts
CHANGED
|
@@ -55,3 +55,10 @@ export type ThenArg<T> = T extends PromiseLike<infer U> ? ThenArg<U> : T;
|
|
|
55
55
|
* @public
|
|
56
56
|
*/
|
|
57
57
|
export type Dict<T> = Record<string, T | undefined>;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @internal
|
|
61
|
+
* Creates a "lower-priority" type inference.
|
|
62
|
+
* https://github.com/microsoft/TypeScript/issues/14829#issuecomment-322267089
|
|
63
|
+
*/
|
|
64
|
+
export type InferLast<T> = T & { [K in keyof T]: T[K] };
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var adapters_ws_dist_trpcServerAdaptersWs = require('../../adapters/ws/dist/trpc-server-adapters-ws.cjs.dev.js');
|
|
6
|
-
require('../../dist/transformTRPCResponse-
|
|
7
|
-
require('../../dist/subscription-
|
|
6
|
+
require('../../dist/transformTRPCResponse-c654ea92.cjs.dev.js');
|
|
7
|
+
require('../../dist/subscription-7de48383.cjs.dev.js');
|
|
8
8
|
require('events');
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var adapters_ws_dist_trpcServerAdaptersWs = require('../../adapters/ws/dist/trpc-server-adapters-ws.cjs.prod.js');
|
|
6
|
-
require('../../dist/transformTRPCResponse-
|
|
7
|
-
require('../../dist/subscription-
|
|
6
|
+
require('../../dist/transformTRPCResponse-1e125b28.cjs.prod.js');
|
|
7
|
+
require('../../dist/subscription-f03bec71.cjs.prod.js');
|
|
8
8
|
require('events');
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { applyWSSHandler as applyWSSHandler$1 } from '../../adapters/ws/dist/trpc-server-adapters-ws.esm.js';
|
|
2
|
-
import '../../dist/transformTRPCResponse-
|
|
3
|
-
import '../../dist/subscription-
|
|
2
|
+
import '../../dist/transformTRPCResponse-45c225c3.esm.js';
|
|
3
|
+
import '../../dist/subscription-2ea469a3.esm.js';
|
|
4
4
|
import 'events';
|
|
5
5
|
|
|
6
6
|
/**
|