@trpc/server 11.0.0-rc.746 → 11.0.0-rc.748

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 (35) hide show
  1. package/dist/@trpc/server/index.d.ts +1 -1
  2. package/dist/@trpc/server/index.d.ts.map +1 -1
  3. package/dist/adapters/node-http/nodeHTTPRequestHandler.js +1 -1
  4. package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +1 -1
  5. package/dist/adapters/ws.js +2 -2
  6. package/dist/adapters/ws.mjs +2 -2
  7. package/dist/bundle-analysis.json +122 -119
  8. package/dist/index.js +4 -3
  9. package/dist/index.mjs +1 -1
  10. package/dist/unstable-core-do-not-import/http/contentType.d.ts +2 -2
  11. package/dist/unstable-core-do-not-import/http/contentType.d.ts.map +1 -1
  12. package/dist/unstable-core-do-not-import/http/contentType.js +12 -10
  13. package/dist/unstable-core-do-not-import/http/contentType.mjs +12 -10
  14. package/dist/unstable-core-do-not-import/http/resolveResponse.js +2 -2
  15. package/dist/unstable-core-do-not-import/http/resolveResponse.mjs +2 -2
  16. package/dist/unstable-core-do-not-import/procedureBuilder.js +1 -0
  17. package/dist/unstable-core-do-not-import/procedureBuilder.mjs +1 -0
  18. package/dist/unstable-core-do-not-import/router.d.ts +20 -3
  19. package/dist/unstable-core-do-not-import/router.d.ts.map +1 -1
  20. package/dist/unstable-core-do-not-import/router.js +102 -6
  21. package/dist/unstable-core-do-not-import/router.mjs +102 -8
  22. package/dist/unstable-core-do-not-import/stream/jsonl.d.ts +3 -9
  23. package/dist/unstable-core-do-not-import/stream/jsonl.d.ts.map +1 -1
  24. package/dist/unstable-core-do-not-import/stream/jsonl.js +24 -33
  25. package/dist/unstable-core-do-not-import/stream/jsonl.mjs +24 -33
  26. package/dist/unstable-core-do-not-import.js +2 -0
  27. package/dist/unstable-core-do-not-import.mjs +1 -1
  28. package/package.json +2 -2
  29. package/src/@trpc/server/index.ts +1 -0
  30. package/src/adapters/ws.ts +1 -1
  31. package/src/unstable-core-do-not-import/http/contentType.ts +48 -42
  32. package/src/unstable-core-do-not-import/http/resolveResponse.ts +2 -2
  33. package/src/unstable-core-do-not-import/procedureBuilder.ts +1 -0
  34. package/src/unstable-core-do-not-import/router.ts +156 -14
  35. package/src/unstable-core-do-not-import/stream/jsonl.ts +28 -40
@@ -1 +1 @@
1
- {"version":3,"file":"jsonl.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/stream/jsonl.ts"],"names":[],"mappings":"AASA;;;GAGG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,SAAS,EAAE,MAAM,2BAA2B,CAAC,UAAU,CAAC,CAAC;CAC1D,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,EAAE,CACA,SAAS,EAAE,MAAM,GAAG,MAAM,EAC1B,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GACjC,yBAAyB,CAAC;CAC9B,CAAC;AAOF,QAAA,MAAM,wBAAwB,IAAI,CAAC;AACnC,KAAK,wBAAwB,GAAG,OAAO,wBAAwB,CAAC;AAChE,QAAA,MAAM,+BAA+B,IAAI,CAAC;AAC1C,KAAK,+BAA+B,GAAG,OAAO,+BAA+B,CAAC;AAE9E,QAAA,MAAM,wBAAwB,IAAI,CAAC;AACnC,KAAK,wBAAwB,GAAG,OAAO,wBAAwB,CAAC;AAChE,QAAA,MAAM,uBAAuB,IAAI,CAAC;AAClC,KAAK,uBAAuB,GAAG,OAAO,uBAAuB,CAAC;AAE9D,QAAA,MAAM,4BAA4B,IAAI,CAAC;AACvC,KAAK,4BAA4B,GAAG,OAAO,4BAA4B,CAAC;AACxE,QAAA,MAAM,2BAA2B,IAAI,CAAC;AACtC,KAAK,2BAA2B,GAAG,OAAO,2BAA2B,CAAC;AACtE,QAAA,MAAM,2BAA2B,IAAI,CAAC;AACtC,KAAK,2BAA2B,GAAG,OAAO,2BAA2B,CAAC;AAEtE,KAAK,kBAAkB,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O,CAAC,EAAE,eAAe,CAAC;IAC1B,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,IAAI,EAAE,SAAS,CAAA;KAAE,KAAK,OAAO,CAAC;IACrE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAsJD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,oBAAoB,+CA+B7D;AAOD,MAAM,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE;IAAE,KAAK,EAAE,OAAO,CAAA;CAAE,KAAK,IAAI,CAAC;AAsLjE;;;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;IAClD;;OAEG;IACH,eAAe,EAAE,eAAe,CAAC;CAClC;2BAtC+B,UAAU;qBA9CvB,SAAS;;;;wBAmBN,OAAO;;;wBAuCA,OAAO;IAgJnC"}
@@ -322,15 +322,6 @@ async function* createBatchStreamProducer(opts) {
322
322
  }
323
323
  })).pipeThrough(new TextEncoderStream());
324
324
  }
325
- class StreamInterruptedError extends Error {
326
- constructor(cause){
327
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
328
- // @ts-ignore https://github.com/tc39/proposal-error-cause
329
- super('Invalid response or stream interrupted', {
330
- cause
331
- });
332
- }
333
- }
334
325
  class AsyncError extends Error {
335
326
  constructor(data){
336
327
  super('Received error from server'), _define_property(this, "data", void 0), this.data = data;
@@ -420,17 +411,7 @@ function createConsumerStream(from) {
420
411
  enqueue: (v)=>originalController.enqueue(v),
421
412
  close: ()=>{
422
413
  originalController.close();
423
- // mark as closed and remove methods
424
- Object.assign(streamController, {
425
- closed: true,
426
- close: ()=>{
427
- // noop
428
- },
429
- enqueue: ()=>{
430
- // noop
431
- },
432
- getReaderResource: null
433
- });
414
+ clear();
434
415
  if (isEmpty()) {
435
416
  abortController.abort();
436
417
  }
@@ -442,8 +423,27 @@ function createConsumerStream(from) {
442
423
  reader.releaseLock();
443
424
  streamController.close();
444
425
  });
426
+ },
427
+ error: (reason)=>{
428
+ originalController.error(reason);
429
+ clear();
445
430
  }
446
431
  };
432
+ function clear() {
433
+ Object.assign(streamController, {
434
+ closed: true,
435
+ close: ()=>{
436
+ // noop
437
+ },
438
+ enqueue: ()=>{
439
+ // noop
440
+ },
441
+ getReaderResource: null,
442
+ error: ()=>{
443
+ // noop
444
+ }
445
+ });
446
+ }
447
447
  return streamController;
448
448
  }
449
449
  /**
@@ -459,10 +459,8 @@ function createConsumerStream(from) {
459
459
  /**
460
460
  * Cancels all pending controllers and rejects deferred promises
461
461
  */ function cancelAll(reason) {
462
- const error = new StreamInterruptedError(reason);
463
462
  for (const controller of controllerMap.values()){
464
- controller.enqueue(error);
465
- controller.close();
463
+ controller.error(reason);
466
464
  }
467
465
  }
468
466
  return {
@@ -502,9 +500,6 @@ function createConsumerStream(from) {
502
500
  const reader = _ts_add_disposable_resource(env, controller.getReaderResource(), false);
503
501
  ;
504
502
  const { value } = await reader.read();
505
- if (value instanceof StreamInterruptedError) {
506
- throw value;
507
- }
508
503
  const [_chunkId, status, data] = value;
509
504
  switch(status){
510
505
  case PROMISE_STATUS_FULFILLED:
@@ -535,9 +530,6 @@ function createConsumerStream(from) {
535
530
  ;
536
531
  while(true){
537
532
  const { value } = await reader.read();
538
- if (value instanceof StreamInterruptedError) {
539
- throw value;
540
- }
541
533
  const [_chunkId, status, data] = value;
542
534
  switch(status){
543
535
  case ASYNC_ITERABLE_STATUS_YIELD:
@@ -574,9 +566,8 @@ function createConsumerStream(from) {
574
566
  return data;
575
567
  }
576
568
  const closeOrAbort = (reason)=>{
577
- const error = new StreamInterruptedError(reason);
578
- headDeferred?.reject(error);
579
- streamManager.cancelAll(error);
569
+ headDeferred?.reject(reason);
570
+ streamManager.cancelAll(reason);
580
571
  };
581
572
  source.pipeTo(new WritableStream({
582
573
  write (chunkOrHead) {
@@ -595,7 +586,7 @@ function createConsumerStream(from) {
595
586
  const controller = streamManager.getOrCreate(idx);
596
587
  controller.enqueue(chunk);
597
588
  },
598
- close: closeOrAbort,
589
+ close: ()=>closeOrAbort(new Error('Stream closed')),
599
590
  abort: closeOrAbort
600
591
  }), {
601
592
  signal: opts.abortController.signal
@@ -320,15 +320,6 @@ async function* createBatchStreamProducer(opts) {
320
320
  }
321
321
  })).pipeThrough(new TextEncoderStream());
322
322
  }
323
- class StreamInterruptedError extends Error {
324
- constructor(cause){
325
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
326
- // @ts-ignore https://github.com/tc39/proposal-error-cause
327
- super('Invalid response or stream interrupted', {
328
- cause
329
- });
330
- }
331
- }
332
323
  class AsyncError extends Error {
333
324
  constructor(data){
334
325
  super('Received error from server'), _define_property(this, "data", void 0), this.data = data;
@@ -418,17 +409,7 @@ function createConsumerStream(from) {
418
409
  enqueue: (v)=>originalController.enqueue(v),
419
410
  close: ()=>{
420
411
  originalController.close();
421
- // mark as closed and remove methods
422
- Object.assign(streamController, {
423
- closed: true,
424
- close: ()=>{
425
- // noop
426
- },
427
- enqueue: ()=>{
428
- // noop
429
- },
430
- getReaderResource: null
431
- });
412
+ clear();
432
413
  if (isEmpty()) {
433
414
  abortController.abort();
434
415
  }
@@ -440,8 +421,27 @@ function createConsumerStream(from) {
440
421
  reader.releaseLock();
441
422
  streamController.close();
442
423
  });
424
+ },
425
+ error: (reason)=>{
426
+ originalController.error(reason);
427
+ clear();
443
428
  }
444
429
  };
430
+ function clear() {
431
+ Object.assign(streamController, {
432
+ closed: true,
433
+ close: ()=>{
434
+ // noop
435
+ },
436
+ enqueue: ()=>{
437
+ // noop
438
+ },
439
+ getReaderResource: null,
440
+ error: ()=>{
441
+ // noop
442
+ }
443
+ });
444
+ }
445
445
  return streamController;
446
446
  }
447
447
  /**
@@ -457,10 +457,8 @@ function createConsumerStream(from) {
457
457
  /**
458
458
  * Cancels all pending controllers and rejects deferred promises
459
459
  */ function cancelAll(reason) {
460
- const error = new StreamInterruptedError(reason);
461
460
  for (const controller of controllerMap.values()){
462
- controller.enqueue(error);
463
- controller.close();
461
+ controller.error(reason);
464
462
  }
465
463
  }
466
464
  return {
@@ -500,9 +498,6 @@ function createConsumerStream(from) {
500
498
  const reader = _ts_add_disposable_resource(env, controller.getReaderResource(), false);
501
499
  ;
502
500
  const { value } = await reader.read();
503
- if (value instanceof StreamInterruptedError) {
504
- throw value;
505
- }
506
501
  const [_chunkId, status, data] = value;
507
502
  switch(status){
508
503
  case PROMISE_STATUS_FULFILLED:
@@ -533,9 +528,6 @@ function createConsumerStream(from) {
533
528
  ;
534
529
  while(true){
535
530
  const { value } = await reader.read();
536
- if (value instanceof StreamInterruptedError) {
537
- throw value;
538
- }
539
531
  const [_chunkId, status, data] = value;
540
532
  switch(status){
541
533
  case ASYNC_ITERABLE_STATUS_YIELD:
@@ -572,9 +564,8 @@ function createConsumerStream(from) {
572
564
  return data;
573
565
  }
574
566
  const closeOrAbort = (reason)=>{
575
- const error = new StreamInterruptedError(reason);
576
- headDeferred?.reject(error);
577
- streamManager.cancelAll(error);
567
+ headDeferred?.reject(reason);
568
+ streamManager.cancelAll(reason);
578
569
  };
579
570
  source.pipeTo(new WritableStream({
580
571
  write (chunkOrHead) {
@@ -593,7 +584,7 @@ function createConsumerStream(from) {
593
584
  const controller = streamManager.getOrCreate(idx);
594
585
  controller.enqueue(chunk);
595
586
  },
596
- close: closeOrAbort,
587
+ close: ()=>closeOrAbort(new Error('Stream closed')),
597
588
  abort: closeOrAbort
598
589
  }), {
599
590
  signal: opts.abortController.signal
@@ -66,6 +66,8 @@ exports.isServerDefault = rootConfig.isServerDefault;
66
66
  exports.callProcedure = router.callProcedure;
67
67
  exports.createCallerFactory = router.createCallerFactory;
68
68
  exports.createRouterFactory = router.createRouterFactory;
69
+ exports.getProcedureAtPath = router.getProcedureAtPath;
70
+ exports.lazy = router.lazy;
69
71
  exports.mergeRouters = router.mergeRouters;
70
72
  exports.TRPC_ERROR_CODES_BY_KEY = codes.TRPC_ERROR_CODES_BY_KEY;
71
73
  exports.TRPC_ERROR_CODES_BY_NUMBER = codes.TRPC_ERROR_CODES_BY_NUMBER;
@@ -15,7 +15,7 @@ export { getParseFn } from './unstable-core-do-not-import/parser.mjs';
15
15
  export { procedureTypes } from './unstable-core-do-not-import/procedure.mjs';
16
16
  export { createBuilder } from './unstable-core-do-not-import/procedureBuilder.mjs';
17
17
  export { isServerDefault } from './unstable-core-do-not-import/rootConfig.mjs';
18
- export { callProcedure, createCallerFactory, createRouterFactory, mergeRouters } from './unstable-core-do-not-import/router.mjs';
18
+ export { callProcedure, createCallerFactory, createRouterFactory, getProcedureAtPath, lazy, mergeRouters } from './unstable-core-do-not-import/router.mjs';
19
19
  export { TRPC_ERROR_CODES_BY_KEY, TRPC_ERROR_CODES_BY_NUMBER } from './unstable-core-do-not-import/rpc/codes.mjs';
20
20
  export { parseTRPCMessage } from './unstable-core-do-not-import/rpc/parseTRPCMessage.mjs';
21
21
  export { isPromise, jsonlStreamConsumer, jsonlStreamProducer } from './unstable-core-do-not-import/stream/jsonl.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/server",
3
- "version": "11.0.0-rc.746+6c15b0575",
3
+ "version": "11.0.0-rc.748+b19e7e9a6",
4
4
  "description": "The tRPC server library",
5
5
  "author": "KATT",
6
6
  "license": "MIT",
@@ -152,5 +152,5 @@
152
152
  "peerDependencies": {
153
153
  "typescript": ">=5.7.2"
154
154
  },
155
- "gitHead": "6c15b0575d18179ddf964d89d8295aabad39f2cc"
155
+ "gitHead": "b19e7e9a640511f49de05bcd4436dc0a514f5e0f"
156
156
  }
@@ -44,6 +44,7 @@ export {
44
44
  tracked,
45
45
  type TrackedEnvelope,
46
46
  isTrackedEnvelope,
47
+ lazy as experimental_lazy,
47
48
  } from '../../unstable-core-do-not-import';
48
49
 
49
50
  export type {
@@ -219,7 +219,7 @@ export function getWSConnectionHandler<TRouter extends AnyRouter>(
219
219
 
220
220
  const abortController = new AbortController();
221
221
  const result = await callProcedure({
222
- procedures: router._def.procedures,
222
+ _def: router._def,
223
223
  path,
224
224
  getRawInput: async () => input,
225
225
  ctx,
@@ -1,6 +1,6 @@
1
1
  import { TRPCError } from '../error/TRPCError';
2
- import type { AnyProcedure, ProcedureType } from '../procedure';
3
- import type { AnyRouter } from '../router';
2
+ import type { ProcedureType } from '../procedure';
3
+ import { getProcedureAtPath, type AnyRouter } from '../router';
4
4
  import { isObject, unsetMarker } from '../utils';
5
5
  import { parseConnectionParamsFromString } from './parseConnectionParams';
6
6
  import type { TRPCAcceptHeader, TRPCRequestInfo } from './types';
@@ -16,7 +16,7 @@ type GetRequestInfoOptions = {
16
16
 
17
17
  type ContentTypeHandler = {
18
18
  isMatch: (opts: Request) => boolean;
19
- parse: (opts: GetRequestInfoOptions) => TRPCRequestInfo;
19
+ parse: (opts: GetRequestInfoOptions) => Promise<TRPCRequestInfo>;
20
20
  };
21
21
 
22
22
  /**
@@ -66,7 +66,7 @@ const jsonContentTypeHandler: ContentTypeHandler = {
66
66
  isMatch(req) {
67
67
  return !!req.headers.get('content-type')?.startsWith('application/json');
68
68
  },
69
- parse(opts) {
69
+ async parse(opts) {
70
70
  const { req } = opts;
71
71
  const isBatchCall = opts.searchParams.get('batch') === '1';
72
72
  const paths = isBatchCall ? opts.path.split(',') : [opts.path];
@@ -110,42 +110,45 @@ const jsonContentTypeHandler: ContentTypeHandler = {
110
110
  return acc;
111
111
  });
112
112
 
113
- const calls = paths.map((path, index): TRPCRequestInfo['calls'][number] => {
114
- const procedure: AnyProcedure | null =
115
- opts.router._def.procedures[path] ?? null;
116
- return {
117
- path,
118
- procedure,
119
- getRawInput: async () => {
120
- const inputs = await getInputs.read();
121
- let input = inputs[index];
113
+ const calls = await Promise.all(
114
+ paths.map(
115
+ async (path, index): Promise<TRPCRequestInfo['calls'][number]> => {
116
+ const procedure = await getProcedureAtPath(opts.router._def, path);
117
+ return {
118
+ path,
119
+ procedure,
120
+ getRawInput: async () => {
121
+ const inputs = await getInputs.read();
122
+ let input = inputs[index];
122
123
 
123
- if (procedure?._def.type === 'subscription') {
124
- const lastEventId =
125
- opts.headers.get('last-event-id') ??
126
- opts.searchParams.get('lastEventId') ??
127
- opts.searchParams.get('Last-Event-Id');
124
+ if (procedure?._def.type === 'subscription') {
125
+ const lastEventId =
126
+ opts.headers.get('last-event-id') ??
127
+ opts.searchParams.get('lastEventId') ??
128
+ opts.searchParams.get('Last-Event-Id');
128
129
 
129
- if (lastEventId) {
130
- if (isObject(input)) {
131
- input = {
132
- ...input,
133
- lastEventId: lastEventId,
134
- };
135
- } else {
136
- input ??= {
137
- lastEventId: lastEventId,
138
- };
130
+ if (lastEventId) {
131
+ if (isObject(input)) {
132
+ input = {
133
+ ...input,
134
+ lastEventId: lastEventId,
135
+ };
136
+ } else {
137
+ input ??= {
138
+ lastEventId: lastEventId,
139
+ };
140
+ }
141
+ }
139
142
  }
140
- }
141
- }
142
- return input;
143
- },
144
- result: () => {
145
- return getInputs.result()?.[index];
143
+ return input;
144
+ },
145
+ result: () => {
146
+ return getInputs.result()?.[index];
147
+ },
148
+ };
146
149
  },
147
- };
148
- });
150
+ ),
151
+ );
149
152
 
150
153
  const types = new Set(
151
154
  calls.map((call) => call.procedure?._def.type).filter(Boolean),
@@ -185,7 +188,7 @@ const formDataContentTypeHandler: ContentTypeHandler = {
185
188
  isMatch(req) {
186
189
  return !!req.headers.get('content-type')?.startsWith('multipart/form-data');
187
190
  },
188
- parse(opts) {
191
+ async parse(opts) {
189
192
  const { req } = opts;
190
193
  if (req.method !== 'POST') {
191
194
  throw new TRPCError({
@@ -198,6 +201,7 @@ const formDataContentTypeHandler: ContentTypeHandler = {
198
201
  const fd = await req.formData();
199
202
  return fd;
200
203
  });
204
+ const procedure = await getProcedureAtPath(opts.router._def, opts.path);
201
205
  return {
202
206
  accept: null,
203
207
  calls: [
@@ -205,7 +209,7 @@ const formDataContentTypeHandler: ContentTypeHandler = {
205
209
  path: opts.path,
206
210
  getRawInput: getInputs.read,
207
211
  result: getInputs.result,
208
- procedure: opts.router._def.procedures[opts.path] ?? null,
212
+ procedure,
209
213
  },
210
214
  ],
211
215
  isBatchCall: false,
@@ -223,7 +227,7 @@ const octetStreamContentTypeHandler: ContentTypeHandler = {
223
227
  .get('content-type')
224
228
  ?.startsWith('application/octet-stream');
225
229
  },
226
- parse(opts) {
230
+ async parse(opts) {
227
231
  const { req } = opts;
228
232
  if (req.method !== 'POST') {
229
233
  throw new TRPCError({
@@ -241,7 +245,7 @@ const octetStreamContentTypeHandler: ContentTypeHandler = {
241
245
  path: opts.path,
242
246
  getRawInput: getInputs.read,
243
247
  result: getInputs.result,
244
- procedure: opts.router._def.procedures[opts.path] ?? null,
248
+ procedure: await getProcedureAtPath(opts.router._def, opts.path),
245
249
  },
246
250
  ],
247
251
  isBatchCall: false,
@@ -279,7 +283,9 @@ function getContentTypeHandler(req: Request): ContentTypeHandler {
279
283
  });
280
284
  }
281
285
 
282
- export function getRequestInfo(opts: GetRequestInfoOptions): TRPCRequestInfo {
286
+ export async function getRequestInfo(
287
+ opts: GetRequestInfoOptions,
288
+ ): Promise<TRPCRequestInfo> {
283
289
  const handler = getContentTypeHandler(opts.req);
284
- return handler.parse(opts);
290
+ return await handler.parse(opts);
285
291
  }
@@ -223,11 +223,11 @@ export async function resolveResponse<TRouter extends AnyRouter>(
223
223
 
224
224
  type $Context = inferRouterContext<TRouter>;
225
225
 
226
- const infoTuple: ResultTuple<TRPCRequestInfo> = run(() => {
226
+ const infoTuple: ResultTuple<TRPCRequestInfo> = await run(async () => {
227
227
  try {
228
228
  return [
229
229
  undefined,
230
- getRequestInfo({
230
+ await getRequestInfo({
231
231
  req,
232
232
  path: decodeURIComponent(opts.path),
233
233
  router,
@@ -637,6 +637,7 @@ function createProcedureCaller(_def: AnyProcedureBuilderDef): AnyProcedure {
637
637
  }
638
638
 
639
639
  procedure._def = _def;
640
+ procedure.procedure = true;
640
641
 
641
642
  // FIXME typecast shouldn't be needed - fixittt
642
643
  return procedure as unknown as AnyProcedure;