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