@trpc/server 9.21.0 → 9.22.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 +3 -3
- package/adapters/express/dist/trpc-server-adapters-express.cjs.prod.js +3 -3
- package/adapters/express/dist/trpc-server-adapters-express.esm.js +3 -3
- package/adapters/fastify/dist/trpc-server-adapters-fastify.cjs.dev.js +3 -3
- package/adapters/fastify/dist/trpc-server-adapters-fastify.cjs.prod.js +3 -3
- package/adapters/fastify/dist/trpc-server-adapters-fastify.esm.js +3 -3
- package/adapters/next/dist/trpc-server-adapters-next.cjs.dev.js +3 -3
- package/adapters/next/dist/trpc-server-adapters-next.cjs.prod.js +3 -3
- package/adapters/next/dist/trpc-server-adapters-next.esm.js +3 -3
- package/adapters/node-http/dist/trpc-server-adapters-node-http.cjs.dev.js +3 -3
- package/adapters/node-http/dist/trpc-server-adapters-node-http.cjs.prod.js +3 -3
- package/adapters/node-http/dist/trpc-server-adapters-node-http.esm.js +3 -3
- package/adapters/standalone/dist/trpc-server-adapters-standalone.cjs.dev.js +3 -3
- package/adapters/standalone/dist/trpc-server-adapters-standalone.cjs.prod.js +3 -3
- package/adapters/standalone/dist/trpc-server-adapters-standalone.esm.js +3 -3
- package/adapters/ws/dist/trpc-server-adapters-ws.cjs.dev.js +2 -2
- package/adapters/ws/dist/trpc-server-adapters-ws.cjs.prod.js +2 -2
- package/adapters/ws/dist/trpc-server-adapters-ws.esm.js +2 -2
- package/dist/declarations/src/TRPCError.d.ts.map +1 -1
- package/dist/declarations/src/adapters/fastify/fastifyRequestHandler.d.ts +1 -1
- 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.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 +1 -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 +16 -11
- package/dist/declarations/src/internals/procedure.d.ts.map +1 -1
- package/dist/declarations/src/router.d.ts +33 -29
- package/dist/declarations/src/router.d.ts.map +1 -1
- package/dist/{nodeHTTPRequestHandler-2cc444d8.cjs.dev.js → nodeHTTPRequestHandler-620da2b7.cjs.dev.js} +2 -2
- package/dist/{nodeHTTPRequestHandler-d00c1126.esm.js → nodeHTTPRequestHandler-87105aef.esm.js} +2 -2
- package/dist/{nodeHTTPRequestHandler-8ddacc19.cjs.prod.js → nodeHTTPRequestHandler-9cfa7523.cjs.prod.js} +2 -2
- package/dist/{resolveHTTPResponse-85f3f5df.esm.js → resolveHTTPResponse-12cc3012.esm.js} +1 -1
- package/dist/{resolveHTTPResponse-3867844c.cjs.dev.js → resolveHTTPResponse-780f5cab.cjs.dev.js} +1 -1
- package/dist/{resolveHTTPResponse-562c3d62.cjs.prod.js → resolveHTTPResponse-d1d2695d.cjs.prod.js} +1 -1
- package/dist/{subscription-a81120d6.esm.js → subscription-2ea469a3.esm.js} +1 -1
- package/dist/{subscription-9e007280.cjs.dev.js → subscription-7de48383.cjs.dev.js} +1 -1
- package/dist/{subscription-12fb50be.cjs.prod.js → subscription-f03bec71.cjs.prod.js} +1 -1
- 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 +12 -6
- package/dist/trpc-server.cjs.prod.js +12 -6
- package/dist/trpc-server.esm.js +14 -8
- package/package.json +2 -2
- package/src/TRPCError.ts +1 -1
- package/src/adapters/fastify/fastifyRequestHandler.ts +2 -2
- package/src/adapters/fastify/fastifyTRPCPlugin.ts +3 -3
- package/src/adapters/next.ts +1 -1
- 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 +2 -2
- package/src/deprecated/createHttpServer.ts +2 -2
- package/src/deprecated/requestHandler.ts +2 -2
- 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/internals/BaseHandlerOptions.ts +1 -1
- package/src/internals/OnErrorFunction.ts +1 -1
- package/src/internals/middlewares.ts +3 -2
- package/src/internals/procedure.ts +60 -13
- package/src/router.ts +96 -32
- 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,6 +38,7 @@ 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,
|
|
@@ -46,6 +48,7 @@ export type ProcedureRecord<
|
|
|
46
48
|
Procedure<
|
|
47
49
|
TInputContext,
|
|
48
50
|
TContext,
|
|
51
|
+
TMeta,
|
|
49
52
|
TInput,
|
|
50
53
|
TParsedInput,
|
|
51
54
|
TOutput,
|
|
@@ -57,8 +60,8 @@ export type ProcedureRecord<
|
|
|
57
60
|
* @public
|
|
58
61
|
*/
|
|
59
62
|
export type inferProcedureInput<
|
|
60
|
-
TProcedure extends Procedure<any, any, any, any, any, any>,
|
|
61
|
-
> = TProcedure extends Procedure<any, any, infer Input, any, 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>
|
|
62
65
|
? undefined extends Input
|
|
63
66
|
? Input | null | void // void is necessary to allow procedures with nullish input to be called without an input
|
|
64
67
|
: Input
|
|
@@ -74,7 +77,7 @@ export type inferAsyncReturnType<TFunction extends (...args: any) => any> =
|
|
|
74
77
|
* @public
|
|
75
78
|
*/
|
|
76
79
|
export type inferProcedureOutput<
|
|
77
|
-
TProcedure extends Procedure<any, any, any, any, any, any>,
|
|
80
|
+
TProcedure extends Procedure<any, any, any, any, any, any, any>,
|
|
78
81
|
> = inferAsyncReturnType<TProcedure['call']>;
|
|
79
82
|
|
|
80
83
|
/**
|
|
@@ -102,8 +105,8 @@ function getDataTransformer(
|
|
|
102
105
|
* @internal
|
|
103
106
|
*/
|
|
104
107
|
export type inferHandlerInput<
|
|
105
|
-
TProcedure extends Procedure<any, any, any, any, any, any>,
|
|
106
|
-
> = TProcedure extends Procedure<any, any, infer TInput, any, 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>
|
|
107
110
|
? undefined extends TInput // ? is input optional
|
|
108
111
|
? unknown extends TInput // ? is input unset
|
|
109
112
|
? [(null | undefined)?] // -> there is no input
|
|
@@ -126,6 +129,21 @@ export type inferRouterContext<TRouter extends AnyRouter> = Parameters<
|
|
|
126
129
|
TRouter['createCaller']
|
|
127
130
|
>[0];
|
|
128
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
|
+
|
|
129
147
|
/**
|
|
130
148
|
* @public
|
|
131
149
|
*/
|
|
@@ -135,6 +153,7 @@ export type AnyRouter<TContext = any> = Router<
|
|
|
135
153
|
any,
|
|
136
154
|
any,
|
|
137
155
|
any,
|
|
156
|
+
any,
|
|
138
157
|
any
|
|
139
158
|
>;
|
|
140
159
|
|
|
@@ -213,12 +232,13 @@ const defaultTransformer: CombinedDataTransformer = {
|
|
|
213
232
|
};
|
|
214
233
|
|
|
215
234
|
type SwapProcedureContext<
|
|
216
|
-
TProcedure extends Procedure<any, any, any, any, any, any>,
|
|
235
|
+
TProcedure extends Procedure<any, any, any, any, any, any, any>,
|
|
217
236
|
TNewContext,
|
|
218
237
|
> = TProcedure extends Procedure<
|
|
219
238
|
infer TInputContext,
|
|
220
239
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
221
240
|
infer _TOldContext,
|
|
241
|
+
infer TMeta,
|
|
222
242
|
infer TInput,
|
|
223
243
|
infer TParsedInput,
|
|
224
244
|
infer TOutput,
|
|
@@ -227,6 +247,7 @@ type SwapProcedureContext<
|
|
|
227
247
|
? Procedure<
|
|
228
248
|
TInputContext,
|
|
229
249
|
TNewContext,
|
|
250
|
+
TMeta,
|
|
230
251
|
TInput,
|
|
231
252
|
TParsedInput,
|
|
232
253
|
TOutput,
|
|
@@ -247,13 +268,23 @@ type SwapContext<
|
|
|
247
268
|
export class Router<
|
|
248
269
|
TInputContext,
|
|
249
270
|
TContext,
|
|
250
|
-
|
|
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
|
+
>,
|
|
251
281
|
TMutations extends ProcedureRecord<
|
|
252
282
|
TInputContext,
|
|
253
283
|
TContext,
|
|
254
284
|
any,
|
|
255
285
|
any,
|
|
256
286
|
any,
|
|
287
|
+
any,
|
|
257
288
|
any
|
|
258
289
|
>,
|
|
259
290
|
TSubscriptions extends ProcedureRecord<
|
|
@@ -262,6 +293,7 @@ export class Router<
|
|
|
262
293
|
unknown,
|
|
263
294
|
unknown,
|
|
264
295
|
Subscription<unknown>,
|
|
296
|
+
unknown,
|
|
265
297
|
unknown
|
|
266
298
|
>,
|
|
267
299
|
TErrorShape extends TRPCErrorShape<number>,
|
|
@@ -270,7 +302,7 @@ export class Router<
|
|
|
270
302
|
queries: TQueries;
|
|
271
303
|
mutations: TMutations;
|
|
272
304
|
subscriptions: TSubscriptions;
|
|
273
|
-
middlewares: MiddlewareFunction<TInputContext, TContext>[];
|
|
305
|
+
middlewares: MiddlewareFunction<TInputContext, TContext, TMeta>[];
|
|
274
306
|
errorFormatter: ErrorFormatter<TContext, TErrorShape>;
|
|
275
307
|
transformer: CombinedDataTransformer;
|
|
276
308
|
};
|
|
@@ -279,7 +311,7 @@ export class Router<
|
|
|
279
311
|
queries?: TQueries;
|
|
280
312
|
mutations?: TMutations;
|
|
281
313
|
subscriptions?: TSubscriptions;
|
|
282
|
-
middlewares?: MiddlewareFunction<TInputContext, TContext>[];
|
|
314
|
+
middlewares?: MiddlewareFunction<TInputContext, TContext, TMeta>[];
|
|
283
315
|
errorFormatter?: ErrorFormatter<TContext, TErrorShape>;
|
|
284
316
|
transformer?: CombinedDataTransformer;
|
|
285
317
|
}) {
|
|
@@ -314,6 +346,7 @@ export class Router<
|
|
|
314
346
|
path: TPath,
|
|
315
347
|
procedure: CreateProcedureWithInputOutputParser<
|
|
316
348
|
TContext,
|
|
349
|
+
TMeta,
|
|
317
350
|
TInput,
|
|
318
351
|
TParsedInput,
|
|
319
352
|
TOutput,
|
|
@@ -322,6 +355,7 @@ export class Router<
|
|
|
322
355
|
): Router<
|
|
323
356
|
TInputContext,
|
|
324
357
|
TContext,
|
|
358
|
+
TMeta,
|
|
325
359
|
TQueries &
|
|
326
360
|
Record<TPath, inferProcedureFromOptions<TInputContext, typeof procedure>>,
|
|
327
361
|
TMutations,
|
|
@@ -331,10 +365,11 @@ export class Router<
|
|
|
331
365
|
|
|
332
366
|
public query<TPath extends string, TInput, TOutput>(
|
|
333
367
|
path: TPath,
|
|
334
|
-
procedure: CreateProcedureWithInput<TContext, TInput, TOutput>,
|
|
368
|
+
procedure: CreateProcedureWithInput<TContext, TMeta, TInput, TOutput>,
|
|
335
369
|
): Router<
|
|
336
370
|
TInputContext,
|
|
337
371
|
TContext,
|
|
372
|
+
TMeta,
|
|
338
373
|
TQueries &
|
|
339
374
|
Record<TPath, inferProcedureFromOptions<TInputContext, typeof procedure>>,
|
|
340
375
|
TMutations,
|
|
@@ -344,10 +379,16 @@ export class Router<
|
|
|
344
379
|
|
|
345
380
|
public query<TPath extends string, TOutput, TParsedOutput>(
|
|
346
381
|
path: TPath,
|
|
347
|
-
procedure: CreateProcedureWithoutInput<
|
|
382
|
+
procedure: CreateProcedureWithoutInput<
|
|
383
|
+
TContext,
|
|
384
|
+
TMeta,
|
|
385
|
+
TOutput,
|
|
386
|
+
TParsedOutput
|
|
387
|
+
>,
|
|
348
388
|
): Router<
|
|
349
389
|
TInputContext,
|
|
350
390
|
TContext,
|
|
391
|
+
TMeta,
|
|
351
392
|
TQueries &
|
|
352
393
|
Record<TPath, inferProcedureFromOptions<TInputContext, typeof procedure>>,
|
|
353
394
|
TMutations,
|
|
@@ -357,9 +398,9 @@ export class Router<
|
|
|
357
398
|
|
|
358
399
|
query(
|
|
359
400
|
path: string,
|
|
360
|
-
procedure: CreateProcedureOptions<TContext, any, any, any, any>,
|
|
401
|
+
procedure: CreateProcedureOptions<TContext, TMeta, any, any, any, any>,
|
|
361
402
|
) {
|
|
362
|
-
const router = new Router<TContext, TContext, any, {}, {}, any>({
|
|
403
|
+
const router = new Router<TContext, TContext, TMeta, any, {}, {}, any>({
|
|
363
404
|
queries: safeObject({
|
|
364
405
|
[path]: createProcedure(procedure),
|
|
365
406
|
}),
|
|
@@ -378,6 +419,7 @@ export class Router<
|
|
|
378
419
|
path: TPath,
|
|
379
420
|
procedure: CreateProcedureWithInputOutputParser<
|
|
380
421
|
TContext,
|
|
422
|
+
TMeta,
|
|
381
423
|
TInput,
|
|
382
424
|
TParsedInput,
|
|
383
425
|
TOutput,
|
|
@@ -386,6 +428,7 @@ export class Router<
|
|
|
386
428
|
): Router<
|
|
387
429
|
TInputContext,
|
|
388
430
|
TContext,
|
|
431
|
+
TMeta,
|
|
389
432
|
TQueries,
|
|
390
433
|
TMutations &
|
|
391
434
|
Record<TPath, inferProcedureFromOptions<TInputContext, typeof procedure>>,
|
|
@@ -395,10 +438,11 @@ export class Router<
|
|
|
395
438
|
|
|
396
439
|
public mutation<TPath extends string, TInput, TOutput>(
|
|
397
440
|
path: TPath,
|
|
398
|
-
procedure: CreateProcedureWithInput<TContext, TInput, TOutput>,
|
|
441
|
+
procedure: CreateProcedureWithInput<TContext, TMeta, TInput, TOutput>,
|
|
399
442
|
): Router<
|
|
400
443
|
TInputContext,
|
|
401
444
|
TContext,
|
|
445
|
+
TMeta,
|
|
402
446
|
TQueries,
|
|
403
447
|
TMutations &
|
|
404
448
|
Record<TPath, inferProcedureFromOptions<TInputContext, typeof procedure>>,
|
|
@@ -408,10 +452,16 @@ export class Router<
|
|
|
408
452
|
|
|
409
453
|
public mutation<TPath extends string, TOutput, TParsedOutput>(
|
|
410
454
|
path: TPath,
|
|
411
|
-
procedure: CreateProcedureWithoutInput<
|
|
455
|
+
procedure: CreateProcedureWithoutInput<
|
|
456
|
+
TContext,
|
|
457
|
+
TMeta,
|
|
458
|
+
TOutput,
|
|
459
|
+
TParsedOutput
|
|
460
|
+
>,
|
|
412
461
|
): Router<
|
|
413
462
|
TInputContext,
|
|
414
463
|
TContext,
|
|
464
|
+
TMeta,
|
|
415
465
|
TQueries,
|
|
416
466
|
TMutations &
|
|
417
467
|
Record<TPath, inferProcedureFromOptions<TInputContext, typeof procedure>>,
|
|
@@ -421,9 +471,9 @@ export class Router<
|
|
|
421
471
|
|
|
422
472
|
public mutation(
|
|
423
473
|
path: string,
|
|
424
|
-
procedure: CreateProcedureOptions<TContext, any, any, any, any>,
|
|
474
|
+
procedure: CreateProcedureOptions<TContext, TMeta, any, any, any, any>,
|
|
425
475
|
) {
|
|
426
|
-
const router = new Router<TContext, TContext, {}, any, {}, any>({
|
|
476
|
+
const router = new Router<TContext, TContext, TMeta, {}, any, {}, any>({
|
|
427
477
|
mutations: safeObject({
|
|
428
478
|
[path]: createProcedure(procedure),
|
|
429
479
|
}),
|
|
@@ -445,6 +495,7 @@ export class Router<
|
|
|
445
495
|
procedure: Omit<
|
|
446
496
|
CreateProcedureWithInputOutputParser<
|
|
447
497
|
TContext,
|
|
498
|
+
TMeta,
|
|
448
499
|
TInput,
|
|
449
500
|
TParsedInput,
|
|
450
501
|
TOutput,
|
|
@@ -455,6 +506,7 @@ export class Router<
|
|
|
455
506
|
): Router<
|
|
456
507
|
TInputContext,
|
|
457
508
|
TContext,
|
|
509
|
+
TMeta,
|
|
458
510
|
TQueries,
|
|
459
511
|
TMutations,
|
|
460
512
|
TSubscriptions &
|
|
@@ -472,12 +524,13 @@ export class Router<
|
|
|
472
524
|
>(
|
|
473
525
|
path: TPath,
|
|
474
526
|
procedure: Omit<
|
|
475
|
-
CreateProcedureWithInput<TContext, TInput, TOutput>,
|
|
527
|
+
CreateProcedureWithInput<TContext, TMeta, TInput, TOutput>,
|
|
476
528
|
'output'
|
|
477
529
|
>,
|
|
478
530
|
): Router<
|
|
479
531
|
TInputContext,
|
|
480
532
|
TContext,
|
|
533
|
+
TMeta,
|
|
481
534
|
TQueries,
|
|
482
535
|
TMutations,
|
|
483
536
|
TSubscriptions &
|
|
@@ -494,12 +547,13 @@ export class Router<
|
|
|
494
547
|
>(
|
|
495
548
|
path: TPath,
|
|
496
549
|
procedure: Omit<
|
|
497
|
-
CreateProcedureWithoutInput<TContext, TOutput, unknown>,
|
|
550
|
+
CreateProcedureWithoutInput<TContext, TMeta, TOutput, unknown>,
|
|
498
551
|
'output'
|
|
499
552
|
>,
|
|
500
553
|
): Router<
|
|
501
554
|
TInputContext,
|
|
502
555
|
TContext,
|
|
556
|
+
TMeta,
|
|
503
557
|
TQueries,
|
|
504
558
|
TMutations,
|
|
505
559
|
TSubscriptions &
|
|
@@ -510,11 +564,11 @@ export class Router<
|
|
|
510
564
|
public subscription(
|
|
511
565
|
path: string,
|
|
512
566
|
procedure: Omit<
|
|
513
|
-
CreateProcedureOptions<TContext, any, any, any, any>,
|
|
567
|
+
CreateProcedureOptions<TContext, TMeta, any, any, any, any>,
|
|
514
568
|
'output'
|
|
515
569
|
>,
|
|
516
570
|
) {
|
|
517
|
-
const router = new Router<TContext, TContext, {}, {}, any, any>({
|
|
571
|
+
const router = new Router<TContext, TContext, TMeta, {}, {}, any, any>({
|
|
518
572
|
subscriptions: safeObject({
|
|
519
573
|
[path]: createProcedure(procedure),
|
|
520
574
|
}),
|
|
@@ -527,11 +581,14 @@ export class Router<
|
|
|
527
581
|
* Merge router with other router
|
|
528
582
|
* @param router
|
|
529
583
|
*/
|
|
530
|
-
public merge<
|
|
584
|
+
public merge<
|
|
585
|
+
TChildRouter extends Router<TContext, any, TMeta, any, any, any, any>,
|
|
586
|
+
>(
|
|
531
587
|
router: TChildRouter,
|
|
532
588
|
): Router<
|
|
533
589
|
TInputContext,
|
|
534
590
|
inferRouterContext<TChildRouter>,
|
|
591
|
+
TMeta,
|
|
535
592
|
TQueries & TChildRouter['_def']['queries'],
|
|
536
593
|
TMutations & TChildRouter['_def']['mutations'],
|
|
537
594
|
TSubscriptions & TChildRouter['_def']['subscriptions'],
|
|
@@ -545,13 +602,14 @@ export class Router<
|
|
|
545
602
|
*/
|
|
546
603
|
public merge<
|
|
547
604
|
TPath extends string,
|
|
548
|
-
TChildRouter extends Router<TContext, any, any, any, any, any>,
|
|
605
|
+
TChildRouter extends Router<TContext, any, TMeta, any, any, any, any>,
|
|
549
606
|
>(
|
|
550
607
|
prefix: TPath,
|
|
551
608
|
router: TChildRouter,
|
|
552
609
|
): Router<
|
|
553
610
|
TInputContext,
|
|
554
611
|
inferRouterContext<TChildRouter>,
|
|
612
|
+
TMeta,
|
|
555
613
|
TQueries & Prefixer<TChildRouter['_def']['queries'], `${TPath}`>,
|
|
556
614
|
TMutations & Prefixer<TChildRouter['_def']['mutations'], `${TPath}`>,
|
|
557
615
|
TSubscriptions &
|
|
@@ -604,7 +662,7 @@ export class Router<
|
|
|
604
662
|
return Router.prefixProcedures(newDefs, prefix);
|
|
605
663
|
};
|
|
606
664
|
|
|
607
|
-
return new Router<TInputContext, any, any, any, any, TErrorShape>({
|
|
665
|
+
return new Router<TInputContext, any, TMeta, any, any, any, TErrorShape>({
|
|
608
666
|
...this._def,
|
|
609
667
|
queries: safeObject(
|
|
610
668
|
this._def.queries,
|
|
@@ -631,7 +689,7 @@ export class Router<
|
|
|
631
689
|
const defTarget = PROCEDURE_DEFINITION_MAP[type];
|
|
632
690
|
const defs = this._def[defTarget];
|
|
633
691
|
const procedure = defs[path] as
|
|
634
|
-
| Procedure<TInputContext, TContext, any, any, any, any>
|
|
692
|
+
| Procedure<TInputContext, TContext, TMeta, any, any, any, any>
|
|
635
693
|
| undefined;
|
|
636
694
|
|
|
637
695
|
if (!procedure) {
|
|
@@ -682,10 +740,11 @@ export class Router<
|
|
|
682
740
|
* @link https://trpc.io/docs/middlewares
|
|
683
741
|
*/
|
|
684
742
|
public middleware<TNewContext>(
|
|
685
|
-
middleware: MiddlewareFunction<TContext, TNewContext>,
|
|
743
|
+
middleware: MiddlewareFunction<TContext, TNewContext, TMeta>,
|
|
686
744
|
): Router<
|
|
687
745
|
TInputContext,
|
|
688
746
|
TNewContext,
|
|
747
|
+
TMeta,
|
|
689
748
|
SwapContext<TQueries, TNewContext>,
|
|
690
749
|
SwapContext<TMutations, TNewContext>,
|
|
691
750
|
SwapContext<TSubscriptions, TNewContext>,
|
|
@@ -712,6 +771,7 @@ export class Router<
|
|
|
712
771
|
return new Router<
|
|
713
772
|
TInputContext,
|
|
714
773
|
TContext,
|
|
774
|
+
TMeta,
|
|
715
775
|
TQueries,
|
|
716
776
|
TMutations,
|
|
717
777
|
TSubscriptions,
|
|
@@ -766,6 +826,7 @@ export class Router<
|
|
|
766
826
|
return new Router<
|
|
767
827
|
TInputContext,
|
|
768
828
|
TContext,
|
|
829
|
+
TMeta,
|
|
769
830
|
TQueries,
|
|
770
831
|
TMutations,
|
|
771
832
|
TSubscriptions,
|
|
@@ -785,6 +846,7 @@ export class Router<
|
|
|
785
846
|
public flat(): Router<
|
|
786
847
|
TInputContext,
|
|
787
848
|
TContext,
|
|
849
|
+
TMeta,
|
|
788
850
|
flatten<{}, TQueries>,
|
|
789
851
|
flatten<{}, TMutations>,
|
|
790
852
|
flatten<{}, TSubscriptions>,
|
|
@@ -801,6 +863,7 @@ export class Router<
|
|
|
801
863
|
*/
|
|
802
864
|
export class LegacyRouter<
|
|
803
865
|
TContext,
|
|
866
|
+
TMeta extends Record<string, any>,
|
|
804
867
|
TQueries extends ProcedureRecord<TContext, TContext, any, any, any, any>,
|
|
805
868
|
TMutations extends ProcedureRecord<TContext, TContext, any, any, any, any>,
|
|
806
869
|
TSubscriptions extends ProcedureRecord<
|
|
@@ -815,12 +878,13 @@ export class LegacyRouter<
|
|
|
815
878
|
> extends Router<
|
|
816
879
|
TContext,
|
|
817
880
|
TContext,
|
|
881
|
+
TMeta,
|
|
818
882
|
TQueries,
|
|
819
883
|
TMutations,
|
|
820
884
|
TSubscriptions,
|
|
821
885
|
TErrorShape
|
|
822
886
|
> {}
|
|
823
887
|
|
|
824
|
-
export function router<TContext>() {
|
|
825
|
-
return new Router<TContext, TContext, {}, {}, {}, DefaultErrorShape>();
|
|
888
|
+
export function router<TContext, TMeta extends Record<string, any> = {}>() {
|
|
889
|
+
return new Router<TContext, TContext, TMeta, {}, {}, {}, DefaultErrorShape>();
|
|
826
890
|
}
|
|
@@ -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
|
/**
|