@trpc/server 11.0.0-rc.383 → 11.0.0-rc.394

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.
@@ -1,12 +1,12 @@
1
1
  {
2
- "bundleSize": 104597,
3
- "bundleOrigSize": 153347,
4
- "bundleReduction": 31.79,
2
+ "bundleSize": 105501,
3
+ "bundleOrigSize": 154208,
4
+ "bundleReduction": 31.59,
5
5
  "modules": [
6
6
  {
7
7
  "id": "/src/unstable-core-do-not-import/stream/stream.ts",
8
- "size": 14457,
9
- "origSize": 15951,
8
+ "size": 14926,
9
+ "origSize": 16301,
10
10
  "renderedExports": [
11
11
  "isPromise",
12
12
  "jsonlStreamProducer",
@@ -17,8 +17,8 @@
17
17
  "/src/unstable-core-do-not-import.ts",
18
18
  "/src/unstable-core-do-not-import/http/resolveResponse.ts"
19
19
  ],
20
- "percent": 13.82,
21
- "reduction": 9.37
20
+ "percent": 14.15,
21
+ "reduction": 8.44
22
22
  },
23
23
  {
24
24
  "id": "/src/adapters/ws.ts",
@@ -32,13 +32,13 @@
32
32
  "dependents": [
33
33
  "/src/adapters/fastify/fastifyTRPCPlugin.ts"
34
34
  ],
35
- "percent": 10.75,
35
+ "percent": 10.65,
36
36
  "reduction": 0
37
37
  },
38
38
  {
39
39
  "id": "/src/unstable-core-do-not-import/http/resolveResponse.ts",
40
- "size": 10457,
41
- "origSize": 10914,
40
+ "size": 10850,
41
+ "origSize": 11195,
42
42
  "renderedExports": [
43
43
  "resolveResponse"
44
44
  ],
@@ -46,8 +46,8 @@
46
46
  "dependents": [
47
47
  "/src/unstable-core-do-not-import.ts"
48
48
  ],
49
- "percent": 10,
50
- "reduction": 4.19
49
+ "percent": 10.28,
50
+ "reduction": 3.08
51
51
  },
52
52
  {
53
53
  "id": "/src/unstable-core-do-not-import/procedureBuilder.ts",
@@ -61,7 +61,7 @@
61
61
  "/src/unstable-core-do-not-import.ts",
62
62
  "/src/unstable-core-do-not-import/initTRPC.ts"
63
63
  ],
64
- "percent": 6.05,
64
+ "percent": 6,
65
65
  "reduction": 59.52
66
66
  },
67
67
  {
@@ -77,10 +77,10 @@
77
77
  "removedExports": [],
78
78
  "dependents": [
79
79
  "/src/unstable-core-do-not-import.ts",
80
- "/src/unstable-core-do-not-import/http/resolveResponse.ts",
81
- "/src/unstable-core-do-not-import/initTRPC.ts"
80
+ "/src/unstable-core-do-not-import/initTRPC.ts",
81
+ "/src/unstable-core-do-not-import/http/resolveResponse.ts"
82
82
  ],
83
- "percent": 5.72,
83
+ "percent": 5.68,
84
84
  "reduction": 41.05
85
85
  },
86
86
  {
@@ -95,7 +95,7 @@
95
95
  "/src/unstable-core-do-not-import.ts",
96
96
  "/src/unstable-core-do-not-import/http/resolveResponse.ts"
97
97
  ],
98
- "percent": 5.3,
98
+ "percent": 5.26,
99
99
  "reduction": 0
100
100
  },
101
101
  {
@@ -109,7 +109,7 @@
109
109
  "dependents": [
110
110
  "/src/adapters/aws-lambda/index.ts"
111
111
  ],
112
- "percent": 4.64,
112
+ "percent": 4.6,
113
113
  "reduction": 13.62
114
114
  },
115
115
  {
@@ -123,7 +123,7 @@
123
123
  "dependents": [
124
124
  "/src/adapters/next-app-dir.ts"
125
125
  ],
126
- "percent": 3,
126
+ "percent": 2.97,
127
127
  "reduction": 22.27
128
128
  },
129
129
  {
@@ -140,7 +140,7 @@
140
140
  "/src/observable/index.ts",
141
141
  "/src/observable/operators.ts"
142
142
  ],
143
- "percent": 2.99,
143
+ "percent": 2.97,
144
144
  "reduction": 0.67
145
145
  },
146
146
  {
@@ -156,7 +156,7 @@
156
156
  "dependents": [
157
157
  "/src/observable/index.ts"
158
158
  ],
159
- "percent": 2.63,
159
+ "percent": 2.61,
160
160
  "reduction": 0
161
161
  },
162
162
  {
@@ -172,11 +172,11 @@
172
172
  "removedExports": [],
173
173
  "dependents": [
174
174
  "/src/unstable-core-do-not-import.ts",
175
- "/src/unstable-core-do-not-import/http/resolveResponse.ts",
176
175
  "/src/unstable-core-do-not-import/router.ts",
177
- "/src/unstable-core-do-not-import/initTRPC.ts"
176
+ "/src/unstable-core-do-not-import/initTRPC.ts",
177
+ "/src/unstable-core-do-not-import/http/resolveResponse.ts"
178
178
  ],
179
- "percent": 2.62,
179
+ "percent": 2.6,
180
180
  "reduction": 45.94
181
181
  },
182
182
  {
@@ -190,7 +190,7 @@
190
190
  "dependents": [
191
191
  "/src/unstable-core-do-not-import.ts"
192
192
  ],
193
- "percent": 2.59,
193
+ "percent": 2.56,
194
194
  "reduction": 40.91
195
195
  },
196
196
  {
@@ -210,7 +210,7 @@
210
210
  "/src/unstable-core-do-not-import/initTRPC.ts",
211
211
  "/src/unstable-core-do-not-import/procedureBuilder.ts"
212
212
  ],
213
- "percent": 2.51,
213
+ "percent": 2.49,
214
214
  "reduction": 55.5
215
215
  },
216
216
  {
@@ -224,7 +224,7 @@
224
224
  "dependents": [
225
225
  "/src/adapters/fetch/index.ts"
226
226
  ],
227
- "percent": 2.16,
227
+ "percent": 2.14,
228
228
  "reduction": 2.17
229
229
  },
230
230
  {
@@ -239,7 +239,7 @@
239
239
  "/src/adapters/node-http/index.ts",
240
240
  "/src/adapters/node-http/nodeHTTPRequestHandler.ts"
241
241
  ],
242
- "percent": 2.08,
242
+ "percent": 2.06,
243
243
  "reduction": 14.12
244
244
  },
245
245
  {
@@ -253,7 +253,7 @@
253
253
  "dependents": [
254
254
  "/src/adapters/next-app-dir/nextAppDirCaller.ts"
255
255
  ],
256
- "percent": 1.96,
256
+ "percent": 1.94,
257
257
  "reduction": 5.79
258
258
  },
259
259
  {
@@ -269,7 +269,7 @@
269
269
  "/src/unstable-core-do-not-import.ts",
270
270
  "/src/unstable-core-do-not-import/router.ts"
271
271
  ],
272
- "percent": 1.91,
272
+ "percent": 1.9,
273
273
  "reduction": 0
274
274
  },
275
275
  {
@@ -284,13 +284,13 @@
284
284
  "removedExports": [],
285
285
  "dependents": [
286
286
  "/src/unstable-core-do-not-import.ts",
287
- "/src/unstable-core-do-not-import/http/resolveResponse.ts",
288
287
  "/src/unstable-core-do-not-import/router.ts",
289
288
  "/src/unstable-core-do-not-import/middleware.ts",
289
+ "/src/unstable-core-do-not-import/http/resolveResponse.ts",
290
290
  "/src/unstable-core-do-not-import/http/contentType.ts",
291
291
  "/src/unstable-core-do-not-import/procedureBuilder.ts"
292
292
  ],
293
- "percent": 1.66,
293
+ "percent": 1.64,
294
294
  "reduction": 19.47
295
295
  },
296
296
  {
@@ -304,7 +304,7 @@
304
304
  "dependents": [
305
305
  "/src/adapters/node-http/index.ts"
306
306
  ],
307
- "percent": 1.65,
307
+ "percent": 1.63,
308
308
  "reduction": 20.03
309
309
  },
310
310
  {
@@ -316,7 +316,7 @@
316
316
  ],
317
317
  "removedExports": [],
318
318
  "dependents": [],
319
- "percent": 1.51,
319
+ "percent": 1.5,
320
320
  "reduction": 21.04
321
321
  },
322
322
  {
@@ -328,7 +328,7 @@
328
328
  ],
329
329
  "removedExports": [],
330
330
  "dependents": [],
331
- "percent": 1.48,
331
+ "percent": 1.46,
332
332
  "reduction": 26.94
333
333
  },
334
334
  {
@@ -341,7 +341,7 @@
341
341
  ],
342
342
  "removedExports": [],
343
343
  "dependents": [],
344
- "percent": 1.46,
344
+ "percent": 1.44,
345
345
  "reduction": 27.6
346
346
  },
347
347
  {
@@ -355,7 +355,7 @@
355
355
  "dependents": [
356
356
  "/src/adapters/fastify/index.ts"
357
357
  ],
358
- "percent": 1.43,
358
+ "percent": 1.42,
359
359
  "reduction": 34.7
360
360
  },
361
361
  {
@@ -369,10 +369,10 @@
369
369
  "removedExports": [],
370
370
  "dependents": [
371
371
  "/src/unstable-core-do-not-import.ts",
372
- "/src/unstable-core-do-not-import/http/resolveResponse.ts",
373
- "/src/unstable-core-do-not-import/error/getErrorShape.ts"
372
+ "/src/unstable-core-do-not-import/error/getErrorShape.ts",
373
+ "/src/unstable-core-do-not-import/http/resolveResponse.ts"
374
374
  ],
375
- "percent": 1.21,
375
+ "percent": 1.2,
376
376
  "reduction": 23.5
377
377
  },
378
378
  {
@@ -390,17 +390,17 @@
390
390
  "removedExports": [],
391
391
  "dependents": [
392
392
  "/src/unstable-core-do-not-import.ts",
393
- "/src/unstable-core-do-not-import/http/resolveResponse.ts",
394
393
  "/src/unstable-core-do-not-import/error/TRPCError.ts",
395
394
  "/src/unstable-core-do-not-import/router.ts",
396
395
  "/src/unstable-core-do-not-import/transformer.ts",
397
396
  "/src/unstable-core-do-not-import/middleware.ts",
397
+ "/src/unstable-core-do-not-import/http/resolveResponse.ts",
398
398
  "/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts",
399
399
  "/src/unstable-core-do-not-import/http/contentType.ts",
400
400
  "/src/unstable-core-do-not-import/procedureBuilder.ts",
401
401
  "/src/unstable-core-do-not-import/stream/stream.ts"
402
402
  ],
403
- "percent": 1.1,
403
+ "percent": 1.09,
404
404
  "reduction": 27.13
405
405
  },
406
406
  {
@@ -415,13 +415,13 @@
415
415
  "/src/adapters/fastify/index.ts",
416
416
  "/src/adapters/fastify/fastifyTRPCPlugin.ts"
417
417
  ],
418
- "percent": 1.08,
418
+ "percent": 1.07,
419
419
  "reduction": 47.59
420
420
  },
421
421
  {
422
422
  "id": "/src/unstable-core-do-not-import/parser.ts",
423
- "size": 992,
424
- "origSize": 2266,
423
+ "size": 1034,
424
+ "origSize": 2496,
425
425
  "renderedExports": [
426
426
  "getParseFn"
427
427
  ],
@@ -430,8 +430,8 @@
430
430
  "/src/unstable-core-do-not-import.ts",
431
431
  "/src/unstable-core-do-not-import/procedureBuilder.ts"
432
432
  ],
433
- "percent": 0.95,
434
- "reduction": 56.22
433
+ "percent": 0.98,
434
+ "reduction": 58.57
435
435
  },
436
436
  {
437
437
  "id": "/src/adapters/next-app-dir/redirect.ts",
@@ -473,7 +473,7 @@
473
473
  ],
474
474
  "removedExports": [],
475
475
  "dependents": [],
476
- "percent": 0.73,
476
+ "percent": 0.72,
477
477
  "reduction": 66.9
478
478
  },
479
479
  {
@@ -487,7 +487,7 @@
487
487
  "dependents": [
488
488
  "/src/unstable-core-do-not-import.ts"
489
489
  ],
490
- "percent": 0.64,
490
+ "percent": 0.63,
491
491
  "reduction": 0.6
492
492
  },
493
493
  {
@@ -502,7 +502,7 @@
502
502
  "/src/unstable-core-do-not-import.ts",
503
503
  "/src/unstable-core-do-not-import/http/resolveResponse.ts"
504
504
  ],
505
- "percent": 0.6,
505
+ "percent": 0.59,
506
506
  "reduction": 43.49
507
507
  },
508
508
  {
@@ -515,7 +515,7 @@
515
515
  ],
516
516
  "removedExports": [],
517
517
  "dependents": [],
518
- "percent": 0.5,
518
+ "percent": 0.49,
519
519
  "reduction": 67.09
520
520
  },
521
521
  {
@@ -633,9 +633,9 @@
633
633
  "reduction": 93.8
634
634
  },
635
635
  {
636
- "id": "/src/http.ts",
636
+ "id": "/src/index.ts",
637
637
  "size": 0,
638
- "origSize": 37,
638
+ "origSize": 32,
639
639
  "renderedExports": [],
640
640
  "removedExports": [],
641
641
  "dependents": [],
@@ -643,9 +643,9 @@
643
643
  "reduction": 100
644
644
  },
645
645
  {
646
- "id": "/src/index.ts",
646
+ "id": "/src/http.ts",
647
647
  "size": 0,
648
- "origSize": 32,
648
+ "origSize": 37,
649
649
  "renderedExports": [],
650
650
  "removedExports": [],
651
651
  "dependents": [],
@@ -1 +1 @@
1
- {"version":3,"file":"resolveResponse.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/http/resolveResponse.ts"],"names":[],"mappings":"AAEA,OAAO,EAA2B,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAExE,OAAO,EAEL,KAAK,SAAS,EAGf,MAAM,WAAW,CAAC;AAOnB,OAAO,KAAK,EACV,sBAAsB,EACtB,kCAAkC,EAEnC,MAAM,SAAS,CAAC;AAUjB,UAAU,yBAAyB,CAAC,OAAO,SAAS,SAAS,CAC3D,SAAQ,sBAAsB,CAAC,OAAO,EAAE,OAAO,CAAC;IAChD,aAAa,EAAE,kCAAkC,CAAC,OAAO,CAAC,CAAC;IAC3D,GAAG,EAAE,OAAO,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;CACzB;AAsHD,wBAAsB,eAAe,CAAC,OAAO,SAAS,SAAS,EAC7D,IAAI,EAAE,yBAAyB,CAAC,OAAO,CAAC,GACvC,OAAO,CAAC,QAAQ,CAAC,CAiQnB"}
1
+ {"version":3,"file":"resolveResponse.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/http/resolveResponse.ts"],"names":[],"mappings":"AAEA,OAAO,EAA2B,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAExE,OAAO,EAEL,KAAK,SAAS,EAGf,MAAM,WAAW,CAAC;AAOnB,OAAO,KAAK,EACV,sBAAsB,EACtB,kCAAkC,EAEnC,MAAM,SAAS,CAAC;AAUjB,UAAU,yBAAyB,CAAC,OAAO,SAAS,SAAS,CAC3D,SAAQ,sBAAsB,CAAC,OAAO,EAAE,OAAO,CAAC;IAChD,aAAa,EAAE,kCAAkC,CAAC,OAAO,CAAC,CAAC;IAC3D,GAAG,EAAE,OAAO,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;CACzB;AAsHD,wBAAsB,eAAe,CAAC,OAAO,SAAS,SAAS,EAC7D,IAAI,EAAE,yBAAyB,CAAC,OAAO,CAAC,GACvC,OAAO,CAAC,QAAQ,CAAC,CA8QnB"}
@@ -92,6 +92,7 @@ async function resolveResponse(opts) {
92
92
  'trpc-accept'
93
93
  ]
94
94
  ]);
95
+ const config = router$1._def._config;
95
96
  const url = new URL(req.url);
96
97
  if (req.method === 'HEAD') {
97
98
  // can be used for lambda warmup
@@ -105,12 +106,12 @@ async function resolveResponse(opts) {
105
106
  let ctx = undefined;
106
107
  let info = undefined;
107
108
  const isStreamCall = req.headers.get('trpc-accept') === 'application/jsonl';
108
- const experimentalIterablesAndDeferreds = router$1._def._config.experimental?.iterablesAndDeferreds ?? false;
109
+ const experimentalIterablesAndDeferreds = config.experimental?.iterablesAndDeferreds ?? false;
109
110
  try {
110
111
  info = contentType.getRequestInfo({
111
112
  req,
112
113
  path: decodeURIComponent(opts.path),
113
- config: router$1._def._config,
114
+ config: config,
114
115
  searchParams: url.searchParams
115
116
  });
116
117
  // we create context early so that error handlers may access context information
@@ -176,7 +177,7 @@ async function resolveResponse(opts) {
176
177
  });
177
178
  return {
178
179
  error: getErrorShape.getErrorShape({
179
- config: opts.router._def._config,
180
+ config,
180
181
  error,
181
182
  type,
182
183
  path: call.path,
@@ -244,6 +245,17 @@ async function resolveResponse(opts) {
244
245
  * }
245
246
  * }
246
247
  */ maxDepth: experimentalIterablesAndDeferreds ? 4 : 3,
248
+ formatError (errorOpts) {
249
+ const call = info?.calls[errorOpts.path[0]];
250
+ return getErrorShape.getErrorShape({
251
+ config,
252
+ ctx,
253
+ error: TRPCError.getTRPCErrorFromUnknown(errorOpts.error),
254
+ input: call?.result(),
255
+ path: call?.path,
256
+ type
257
+ });
258
+ },
247
259
  data: promises.map(async (it)=>{
248
260
  const response = await it;
249
261
  if ('result' in response) {
@@ -260,7 +272,7 @@ async function resolveResponse(opts) {
260
272
  }
261
273
  return response;
262
274
  }),
263
- serialize: opts.router._def._config.transformer.output.serialize,
275
+ serialize: config.transformer.output.serialize,
264
276
  onError: (cause)=>{
265
277
  opts.onError?.({
266
278
  error: TRPCError.getTRPCErrorFromUnknown(cause),
@@ -90,6 +90,7 @@ async function resolveResponse(opts) {
90
90
  'trpc-accept'
91
91
  ]
92
92
  ]);
93
+ const config = router._def._config;
93
94
  const url = new URL(req.url);
94
95
  if (req.method === 'HEAD') {
95
96
  // can be used for lambda warmup
@@ -103,12 +104,12 @@ async function resolveResponse(opts) {
103
104
  let ctx = undefined;
104
105
  let info = undefined;
105
106
  const isStreamCall = req.headers.get('trpc-accept') === 'application/jsonl';
106
- const experimentalIterablesAndDeferreds = router._def._config.experimental?.iterablesAndDeferreds ?? false;
107
+ const experimentalIterablesAndDeferreds = config.experimental?.iterablesAndDeferreds ?? false;
107
108
  try {
108
109
  info = getRequestInfo({
109
110
  req,
110
111
  path: decodeURIComponent(opts.path),
111
- config: router._def._config,
112
+ config: config,
112
113
  searchParams: url.searchParams
113
114
  });
114
115
  // we create context early so that error handlers may access context information
@@ -174,7 +175,7 @@ async function resolveResponse(opts) {
174
175
  });
175
176
  return {
176
177
  error: getErrorShape({
177
- config: opts.router._def._config,
178
+ config,
178
179
  error,
179
180
  type,
180
181
  path: call.path,
@@ -242,6 +243,17 @@ async function resolveResponse(opts) {
242
243
  * }
243
244
  * }
244
245
  */ maxDepth: experimentalIterablesAndDeferreds ? 4 : 3,
246
+ formatError (errorOpts) {
247
+ const call = info?.calls[errorOpts.path[0]];
248
+ return getErrorShape({
249
+ config,
250
+ ctx,
251
+ error: getTRPCErrorFromUnknown(errorOpts.error),
252
+ input: call?.result(),
253
+ path: call?.path,
254
+ type
255
+ });
256
+ },
245
257
  data: promises.map(async (it)=>{
246
258
  const response = await it;
247
259
  if ('result' in response) {
@@ -258,7 +270,7 @@ async function resolveResponse(opts) {
258
270
  }
259
271
  return response;
260
272
  }),
261
- serialize: opts.router._def._config.transformer.output.serialize,
273
+ serialize: config.transformer.output.serialize,
262
274
  onError: (cause)=>{
263
275
  opts.onError?.({
264
276
  error: getTRPCErrorFromUnknown(cause),
@@ -2,6 +2,14 @@ export type ParserZodEsque<TInput, TParsedInput> = {
2
2
  _input: TInput;
3
3
  _output: TParsedInput;
4
4
  };
5
+ export type ParserValibotEsque<TInput, TParsedInput> = {
6
+ schema: {
7
+ _types?: {
8
+ input: TInput;
9
+ output: TParsedInput;
10
+ };
11
+ };
12
+ };
5
13
  export type ParserMyZodEsque<TInput> = {
6
14
  parse: (input: any) => TInput;
7
15
  };
@@ -16,7 +24,7 @@ export type ParserScaleEsque<TInput> = {
16
24
  assert(value: unknown): asserts value is TInput;
17
25
  };
18
26
  export type ParserWithoutInput<TInput> = ParserCustomValidatorEsque<TInput> | ParserMyZodEsque<TInput> | ParserScaleEsque<TInput> | ParserSuperstructEsque<TInput> | ParserYupEsque<TInput>;
19
- export type ParserWithInputOutput<TInput, TParsedInput> = ParserZodEsque<TInput, TParsedInput>;
27
+ export type ParserWithInputOutput<TInput, TParsedInput> = ParserZodEsque<TInput, TParsedInput> | ParserValibotEsque<TInput, TParsedInput>;
20
28
  export type Parser = ParserWithInputOutput<any, any> | ParserWithoutInput<any>;
21
29
  export type inferParser<TParser extends Parser> = TParser extends ParserWithInputOutput<infer $TIn, infer $TOut> ? {
22
30
  in: $TIn;
@@ -1 +1 @@
1
- {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/unstable-core-do-not-import/parser.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,cAAc,CAAC,MAAM,EAAE,YAAY,IAAI;IACjD,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,YAAY,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,gBAAgB,CAAC,MAAM,IAAI;IACrC,KAAK,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,MAAM,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,sBAAsB,CAAC,MAAM,IAAI;IAC3C,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,CAAC;CACpC,CAAC;AAEF,MAAM,MAAM,0BAA0B,CAAC,MAAM,IAAI,CAC/C,KAAK,EAAE,OAAO,KACX,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;AAE9B,MAAM,MAAM,cAAc,CAAC,MAAM,IAAI;IACnC,YAAY,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,gBAAgB,CAAC,MAAM,IAAI;IACrC,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,IAAI,MAAM,CAAC;CACjD,CAAC;AAEF,MAAM,MAAM,kBAA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C,MAAM,IAAI,EAAE,MAAM,KAAK,CAAC,GAC1D;IACE,EAAE,EAAE,IAAI,CAAC;IACT,GAAG,EAAE,KAAK,CAAC;CACZ,GACD,OAAO,SAAS,kBAAkB,CAAC,MAAM,MAAM,CAAC,GAChD;IACE,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;CACb,GACD,KAAK,CAAC;AAEZ,MAAM,MAAM,OAAO,CAAC,KAAK,IAAI,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC;AAExE,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAuCzE"}
@@ -4,6 +4,7 @@
4
4
  function getParseFn(procedureParser) {
5
5
  const parser = procedureParser;
6
6
  if (typeof parser === 'function') {
7
+ // ParserValibotEsque (>= v0.31.0)
7
8
  // ParserCustomValidatorEsque
8
9
  return parser;
9
10
  }
@@ -13,7 +14,7 @@ function getParseFn(procedureParser) {
13
14
  }
14
15
  if (typeof parser.parse === 'function') {
15
16
  // ParserZodEsque
16
- // ParserValibotEsque (<= v0.12.X)
17
+ // ParserValibotEsque (< v0.13.0)
17
18
  return parser.parse.bind(parser);
18
19
  }
19
20
  if (typeof parser.validateSync === 'function') {
@@ -2,6 +2,7 @@
2
2
  function getParseFn(procedureParser) {
3
3
  const parser = procedureParser;
4
4
  if (typeof parser === 'function') {
5
+ // ParserValibotEsque (>= v0.31.0)
5
6
  // ParserCustomValidatorEsque
6
7
  return parser;
7
8
  }
@@ -11,7 +12,7 @@ function getParseFn(procedureParser) {
11
12
  }
12
13
  if (typeof parser.parse === 'function') {
13
14
  // ParserZodEsque
14
- // ParserValibotEsque (<= v0.12.X)
15
+ // ParserValibotEsque (< v0.13.0)
15
16
  return parser.parse.bind(parser);
16
17
  }
17
18
  if (typeof parser.validateSync === 'function') {
@@ -42,17 +42,15 @@ type PromiseChunk = [
42
42
  chunkIndex: ChunkIndex,
43
43
  status: PROMISE_STATUS_FULFILLED,
44
44
  value: HydratedValue
45
- ] | [
46
- chunkIndex: ChunkIndex,
47
- status: PROMISE_STATUS_REJECTED
48
- ];
45
+ ] | [chunkIndex: ChunkIndex, status: PROMISE_STATUS_REJECTED, error: unknown];
49
46
  type IterableChunk = [chunkIndex: ChunkIndex, status: ASYNC_ITERABLE_STATUS_DONE] | [
50
47
  chunkIndex: ChunkIndex,
51
48
  status: ASYNC_ITERABLE_STATUS_VALUE,
52
49
  value: HydratedValue
53
50
  ] | [
54
51
  chunkIndex: ChunkIndex,
55
- status: ASYNC_ITERABLE_STATUS_ERROR
52
+ status: ASYNC_ITERABLE_STATUS_ERROR,
53
+ error: unknown
56
54
  ];
57
55
  type ChunkData = PromiseChunk | IterableChunk;
58
56
  export declare function isPromise(value: unknown): value is Promise<unknown>;
@@ -66,6 +64,10 @@ export interface ProducerOptions {
66
64
  serialize?: Serialize;
67
65
  data: Record<number, unknown>;
68
66
  onError?: ProducerOnError;
67
+ formatError?: (opts: {
68
+ error: unknown;
69
+ path: (string | number)[];
70
+ }) => unknown;
69
71
  maxDepth?: number;
70
72
  }
71
73
  /**
@@ -87,6 +89,9 @@ export declare function jsonlStreamConsumer<THead>(opts: {
87
89
  from: NodeJSReadableStreamEsque | WebReadableStreamEsque;
88
90
  deserialize?: Deserialize;
89
91
  onError?: ConsumerOnError;
92
+ formatError?: (opts: {
93
+ error: unknown;
94
+ }) => Error;
90
95
  }): Promise<readonly [Awaited<THead>, {
91
96
  readonly controllers: Map<ChunkIndex, ReadableStreamDefaultController<ChunkData | StreamInterruptedError>>;
92
97
  }]>;
@@ -1 +1 @@
1
- {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/stream/stream.ts"],"names":[],"mappings":"AAiBA;;;GAGG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,SAAS,EAAE,MAAM,2BAA2B,CAAC,UAAU,CAAC,CAAC;CA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,IAAI,CAAC;AACX,MAAM,WAAW,eAAe;IAC9B,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE;QACnB,KAAK,EAAE,OAAO,CAAC;QACf,IAAI,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;KAC3B,KAAK,OAAO,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAkJD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,eAAe,8BA2BxD;AACD,cAAM,sBAAuB,SAAQ,KAAK;gBAC5B,KAAK,CAAC,EAAE,OAAO;CAK5B;AAMD,MAAM,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE;IAAE,KAAK,EAAE,OAAO,CAAA;CAAE,KAAK,IAAI,CAAC;AA6FjE;;;GAGG;AACH,wBAAsB,mBAAmB,CAAC,KAAK,EAAE,IAAI,EAAE;IACrD,IAAI,EAAE,yBAAyB,GAAG,sBAAsB,CAAC;IACzD,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE;QAAE,KAAK,EAAE,OAAO,CAAA;KAAE,KAAK,KAAK,CAAC;CACnD;;IAkLA"}
@@ -63,14 +63,18 @@ function createBatchStreamProducer(opts) {
63
63
  PROMISE_STATUS_FULFILLED,
64
64
  hydrate(it, path)
65
65
  ]);
66
- }).catch((err)=>{
66
+ }).catch((error)=>{
67
67
  opts.onError?.({
68
- error: err,
68
+ error,
69
69
  path
70
70
  });
71
71
  enqueue([
72
72
  idx,
73
- PROMISE_STATUS_REJECTED
73
+ PROMISE_STATUS_REJECTED,
74
+ opts.formatError?.({
75
+ error,
76
+ path
77
+ })
74
78
  ]);
75
79
  }).finally(()=>{
76
80
  pending.delete(idx);
@@ -109,7 +113,11 @@ function createBatchStreamProducer(opts) {
109
113
  });
110
114
  controller.enqueue([
111
115
  idx,
112
- ASYNC_ITERABLE_STATUS_ERROR
116
+ ASYNC_ITERABLE_STATUS_ERROR,
117
+ opts.formatError?.({
118
+ error,
119
+ path
120
+ })
113
121
  ]);
114
122
  } finally{
115
123
  pending.delete(idx);
@@ -355,7 +363,9 @@ function createDeferred() {
355
363
  resolve(dehydrate(data));
356
364
  break;
357
365
  case PROMISE_STATUS_REJECTED:
358
- reject(new AsyncError(data));
366
+ reject(opts.formatError?.({
367
+ error: data
368
+ }) ?? new AsyncError(data));
359
369
  break;
360
370
  }
361
371
  }).catch(reject).finally(()=>{
@@ -387,7 +397,9 @@ function createDeferred() {
387
397
  return;
388
398
  case ASYNC_ITERABLE_STATUS_ERROR:
389
399
  controllers.delete(chunkId);
390
- throw new AsyncError(data);
400
+ throw opts.formatError?.({
401
+ error: data
402
+ }) ?? new AsyncError(data);
391
403
  }
392
404
  }
393
405
  }
@@ -61,14 +61,18 @@ function createBatchStreamProducer(opts) {
61
61
  PROMISE_STATUS_FULFILLED,
62
62
  hydrate(it, path)
63
63
  ]);
64
- }).catch((err)=>{
64
+ }).catch((error)=>{
65
65
  opts.onError?.({
66
- error: err,
66
+ error,
67
67
  path
68
68
  });
69
69
  enqueue([
70
70
  idx,
71
- PROMISE_STATUS_REJECTED
71
+ PROMISE_STATUS_REJECTED,
72
+ opts.formatError?.({
73
+ error,
74
+ path
75
+ })
72
76
  ]);
73
77
  }).finally(()=>{
74
78
  pending.delete(idx);
@@ -107,7 +111,11 @@ function createBatchStreamProducer(opts) {
107
111
  });
108
112
  controller.enqueue([
109
113
  idx,
110
- ASYNC_ITERABLE_STATUS_ERROR
114
+ ASYNC_ITERABLE_STATUS_ERROR,
115
+ opts.formatError?.({
116
+ error,
117
+ path
118
+ })
111
119
  ]);
112
120
  } finally{
113
121
  pending.delete(idx);
@@ -353,7 +361,9 @@ function createDeferred() {
353
361
  resolve(dehydrate(data));
354
362
  break;
355
363
  case PROMISE_STATUS_REJECTED:
356
- reject(new AsyncError(data));
364
+ reject(opts.formatError?.({
365
+ error: data
366
+ }) ?? new AsyncError(data));
357
367
  break;
358
368
  }
359
369
  }).catch(reject).finally(()=>{
@@ -385,7 +395,9 @@ function createDeferred() {
385
395
  return;
386
396
  case ASYNC_ITERABLE_STATUS_ERROR:
387
397
  controllers.delete(chunkId);
388
- throw new AsyncError(data);
398
+ throw opts.formatError?.({
399
+ error: data
400
+ }) ?? new AsyncError(data);
389
401
  }
390
402
  }
391
403
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/server",
3
- "version": "11.0.0-rc.383+f8e40bff5",
3
+ "version": "11.0.0-rc.394+eab054f77",
4
4
  "description": "The tRPC server library",
5
5
  "author": "KATT",
6
6
  "license": "MIT",
@@ -141,7 +141,7 @@
141
141
  "tslib": "^2.5.0",
142
142
  "tsx": "^4.0.0",
143
143
  "typescript": "^5.4.0",
144
- "valibot": "^0.30.0",
144
+ "valibot": "^0.31.0",
145
145
  "ws": "^8.0.0",
146
146
  "yup": "^1.0.0",
147
147
  "zod": "^3.0.0"
@@ -149,5 +149,5 @@
149
149
  "funding": [
150
150
  "https://trpc.io/sponsor"
151
151
  ],
152
- "gitHead": "f8e40bff51b7efca762c8a2bad35492ec71e83a3"
152
+ "gitHead": "eab054f77f6c86bee3a3959b8312fdefd739378a"
153
153
  }
@@ -160,6 +160,7 @@ export async function resolveResponse<TRouter extends AnyRouter>(
160
160
  ): Promise<Response> {
161
161
  const { router, req } = opts;
162
162
  const headers = new Headers([['vary', 'trpc-accept']]);
163
+ const config = router._def._config;
163
164
 
164
165
  const url = new URL(req.url);
165
166
 
@@ -181,13 +182,13 @@ export async function resolveResponse<TRouter extends AnyRouter>(
181
182
  const isStreamCall = req.headers.get('trpc-accept') === 'application/jsonl';
182
183
 
183
184
  const experimentalIterablesAndDeferreds =
184
- router._def._config.experimental?.iterablesAndDeferreds ?? false;
185
+ config.experimental?.iterablesAndDeferreds ?? false;
185
186
 
186
187
  try {
187
188
  info = getRequestInfo({
188
189
  req,
189
190
  path: decodeURIComponent(opts.path),
190
- config: router._def._config,
191
+ config: config,
191
192
  searchParams: url.searchParams,
192
193
  });
193
194
 
@@ -268,7 +269,7 @@ export async function resolveResponse<TRouter extends AnyRouter>(
268
269
 
269
270
  return {
270
271
  error: getErrorShape({
271
- config: opts.router._def._config,
272
+ config,
272
273
  error,
273
274
  type,
274
275
  path: call.path,
@@ -351,6 +352,18 @@ export async function resolveResponse<TRouter extends AnyRouter>(
351
352
  * }
352
353
  */
353
354
  maxDepth: experimentalIterablesAndDeferreds ? 4 : 3,
355
+ formatError(errorOpts) {
356
+ const call = info?.calls[errorOpts.path[0] as any];
357
+
358
+ return getErrorShape({
359
+ config,
360
+ ctx,
361
+ error: getTRPCErrorFromUnknown(errorOpts.error),
362
+ input: call?.result(),
363
+ path: call?.path,
364
+ type,
365
+ });
366
+ },
354
367
  data: promises.map(async (it) => {
355
368
  const response = await it;
356
369
  if ('result' in response) {
@@ -368,7 +381,7 @@ export async function resolveResponse<TRouter extends AnyRouter>(
368
381
  }
369
382
  return response;
370
383
  }),
371
- serialize: opts.router._def._config.transformer.output.serialize,
384
+ serialize: config.transformer.output.serialize,
372
385
  onError: (cause) => {
373
386
  opts.onError?.({
374
387
  error: getTRPCErrorFromUnknown(cause),
@@ -4,6 +4,15 @@ export type ParserZodEsque<TInput, TParsedInput> = {
4
4
  _output: TParsedInput;
5
5
  };
6
6
 
7
+ export type ParserValibotEsque<TInput, TParsedInput> = {
8
+ schema: {
9
+ _types?: {
10
+ input: TInput;
11
+ output: TParsedInput;
12
+ };
13
+ };
14
+ };
15
+
7
16
  export type ParserMyZodEsque<TInput> = {
8
17
  parse: (input: any) => TInput;
9
18
  };
@@ -31,10 +40,9 @@ export type ParserWithoutInput<TInput> =
31
40
  | ParserSuperstructEsque<TInput>
32
41
  | ParserYupEsque<TInput>;
33
42
 
34
- export type ParserWithInputOutput<TInput, TParsedInput> = ParserZodEsque<
35
- TInput,
36
- TParsedInput
37
- >;
43
+ export type ParserWithInputOutput<TInput, TParsedInput> =
44
+ | ParserZodEsque<TInput, TParsedInput>
45
+ | ParserValibotEsque<TInput, TParsedInput>;
38
46
 
39
47
  export type Parser = ParserWithInputOutput<any, any> | ParserWithoutInput<any>;
40
48
 
@@ -57,6 +65,7 @@ export function getParseFn<TType>(procedureParser: Parser): ParseFn<TType> {
57
65
  const parser = procedureParser as any;
58
66
 
59
67
  if (typeof parser === 'function') {
68
+ // ParserValibotEsque (>= v0.31.0)
60
69
  // ParserCustomValidatorEsque
61
70
  return parser;
62
71
  }
@@ -68,7 +77,7 @@ export function getParseFn<TType>(procedureParser: Parser): ParseFn<TType> {
68
77
 
69
78
  if (typeof parser.parse === 'function') {
70
79
  // ParserZodEsque
71
- // ParserValibotEsque (<= v0.12.X)
80
+ // ParserValibotEsque (< v0.13.0)
72
81
  return parser.parse.bind(parser);
73
82
  }
74
83
 
@@ -79,12 +79,7 @@ type PromiseChunk =
79
79
  status: PROMISE_STATUS_FULFILLED,
80
80
  value: HydratedValue,
81
81
  ]
82
- | [
83
- chunkIndex: ChunkIndex,
84
- status: PROMISE_STATUS_REJECTED,
85
- // do we want to serialize errors?
86
- // , error?: unknown
87
- ];
82
+ | [chunkIndex: ChunkIndex, status: PROMISE_STATUS_REJECTED, error: unknown];
88
83
  type IterableChunk =
89
84
  | [chunkIndex: ChunkIndex, status: ASYNC_ITERABLE_STATUS_DONE]
90
85
  | [
@@ -95,8 +90,7 @@ type IterableChunk =
95
90
  | [
96
91
  chunkIndex: ChunkIndex,
97
92
  status: ASYNC_ITERABLE_STATUS_ERROR,
98
- // do we want to serialize errors?
99
- // , error?: unknown
93
+ error: unknown,
100
94
  ];
101
95
  type ChunkData = PromiseChunk | IterableChunk;
102
96
  type PlaceholderValue = 0 & { __placeholder: true };
@@ -119,6 +113,10 @@ export interface ProducerOptions {
119
113
  serialize?: Serialize;
120
114
  data: Record<number, unknown>;
121
115
  onError?: ProducerOnError;
116
+ formatError?: (opts: {
117
+ error: unknown;
118
+ path: (string | number)[];
119
+ }) => unknown;
122
120
  maxDepth?: number;
123
121
  }
124
122
 
@@ -161,9 +159,13 @@ function createBatchStreamProducer(opts: ProducerOptions) {
161
159
  .then((it) => {
162
160
  enqueue([idx, PROMISE_STATUS_FULFILLED, hydrate(it, path)]);
163
161
  })
164
- .catch((err) => {
165
- opts.onError?.({ error: err, path });
166
- enqueue([idx, PROMISE_STATUS_REJECTED]);
162
+ .catch((error) => {
163
+ opts.onError?.({ error, path });
164
+ enqueue([
165
+ idx,
166
+ PROMISE_STATUS_REJECTED,
167
+ opts.formatError?.({ error, path }),
168
+ ]);
167
169
  })
168
170
  .finally(() => {
169
171
  pending.delete(idx);
@@ -197,7 +199,11 @@ function createBatchStreamProducer(opts: ProducerOptions) {
197
199
  controller.enqueue([idx, ASYNC_ITERABLE_STATUS_DONE]);
198
200
  } catch (error) {
199
201
  opts.onError?.({ error, path });
200
- controller.enqueue([idx, ASYNC_ITERABLE_STATUS_ERROR]);
202
+ controller.enqueue([
203
+ idx,
204
+ ASYNC_ITERABLE_STATUS_ERROR,
205
+ opts.formatError?.({ error, path }),
206
+ ]);
201
207
  } finally {
202
208
  pending.delete(idx);
203
209
  maybeClose();
@@ -403,6 +409,7 @@ export async function jsonlStreamConsumer<THead>(opts: {
403
409
  from: NodeJSReadableStreamEsque | WebReadableStreamEsque;
404
410
  deserialize?: Deserialize;
405
411
  onError?: ConsumerOnError;
412
+ formatError?: (opts: { error: unknown }) => Error;
406
413
  }) {
407
414
  const { deserialize = (v) => v } = opts;
408
415
 
@@ -459,7 +466,9 @@ export async function jsonlStreamConsumer<THead>(opts: {
459
466
  resolve(dehydrate(data));
460
467
  break;
461
468
  case PROMISE_STATUS_REJECTED:
462
- reject(new AsyncError(data));
469
+ reject(
470
+ opts.formatError?.({ error: data }) ?? new AsyncError(data),
471
+ );
463
472
  break;
464
473
  }
465
474
  })
@@ -494,7 +503,9 @@ export async function jsonlStreamConsumer<THead>(opts: {
494
503
  return;
495
504
  case ASYNC_ITERABLE_STATUS_ERROR:
496
505
  controllers.delete(chunkId);
497
- throw new AsyncError(data);
506
+ throw (
507
+ opts.formatError?.({ error: data }) ?? new AsyncError(data)
508
+ );
498
509
  }
499
510
  }
500
511
  },
@@ -541,7 +552,7 @@ export async function jsonlStreamConsumer<THead>(opts: {
541
552
  const head = chunkOrHead as Record<number | string, unknown>;
542
553
 
543
554
  for (const [key, value] of Object.entries(chunkOrHead)) {
544
- const parsed = dehydrate(value);
555
+ const parsed = dehydrate(value as any);
545
556
  head[key] = parsed;
546
557
  }
547
558
  headDeferred.resolve(head as THead);