@trpc/server 11.0.0-rc.730 → 11.0.0-rc.741

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 (33) hide show
  1. package/dist/adapters/fastify/fastifyRequestHandler.d.ts.map +1 -1
  2. package/dist/adapters/node-http/incomingMessageToRequest.d.ts +3 -16
  3. package/dist/adapters/node-http/incomingMessageToRequest.d.ts.map +1 -1
  4. package/dist/adapters/node-http/incomingMessageToRequest.js +5 -3
  5. package/dist/adapters/node-http/incomingMessageToRequest.mjs +5 -3
  6. package/dist/adapters/node-http/types.d.ts +21 -6
  7. package/dist/adapters/node-http/types.d.ts.map +1 -1
  8. package/dist/adapters/standalone.d.ts +18 -2
  9. package/dist/adapters/standalone.d.ts.map +1 -1
  10. package/dist/adapters/standalone.js +14 -6
  11. package/dist/adapters/standalone.mjs +14 -7
  12. package/dist/adapters/ws.d.ts.map +1 -1
  13. package/dist/adapters/ws.js +2 -1
  14. package/dist/adapters/ws.mjs +2 -1
  15. package/dist/bundle-analysis.json +56 -55
  16. package/dist/unstable-core-do-not-import/http/contentType.d.ts +1 -0
  17. package/dist/unstable-core-do-not-import/http/contentType.d.ts.map +1 -1
  18. package/dist/unstable-core-do-not-import/http/contentType.js +6 -3
  19. package/dist/unstable-core-do-not-import/http/contentType.mjs +6 -3
  20. package/dist/unstable-core-do-not-import/http/resolveResponse.d.ts.map +1 -1
  21. package/dist/unstable-core-do-not-import/http/resolveResponse.js +2 -1
  22. package/dist/unstable-core-do-not-import/http/resolveResponse.mjs +2 -1
  23. package/dist/unstable-core-do-not-import/http/types.d.ts +4 -0
  24. package/dist/unstable-core-do-not-import/http/types.d.ts.map +1 -1
  25. package/package.json +4 -4
  26. package/src/adapters/fastify/fastifyRequestHandler.ts +2 -2
  27. package/src/adapters/node-http/incomingMessageToRequest.ts +11 -22
  28. package/src/adapters/node-http/types.ts +34 -7
  29. package/src/adapters/standalone.ts +61 -10
  30. package/src/adapters/ws.ts +1 -0
  31. package/src/unstable-core-do-not-import/http/contentType.ts +4 -0
  32. package/src/unstable-core-do-not-import/http/resolveResponse.ts +1 -0
  33. package/src/unstable-core-do-not-import/http/types.ts +4 -0
@@ -1 +1 @@
1
- {"version":3,"file":"fastifyRequestHandler.d.ts","sourceRoot":"","sources":["../../../src/adapters/fastify/fastifyRequestHandler.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EAEL,KAAK,sBAAsB,EAE5B,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAEL,KAAK,2BAA2B,EAEjC,MAAM,cAAc,CAAC;AAEtB,MAAM,MAAM,qBAAqB,CAC/B,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,cAAc,EAC/B,SAAS,SAAS,YAAY,IAC5B,sBAAsB,CAAC,OAAO,EAAE,QAAQ,CAAC,GAC3C,2BAA2B,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;AAE5D,KAAK,4BAA4B,CAC/B,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,cAAc,EAC/B,SAAS,SAAS,YAAY,IAC5B,qBAAqB,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,GAAG;IACxD,GAAG,EAAE,QAAQ,CAAC;IACd,GAAG,EAAE,SAAS,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,wBAAsB,qBAAqB,CACzC,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,cAAc,EAC/B,SAAS,SAAS,YAAY,EAC9B,IAAI,EAAE,4BAA4B,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,iBAkCjE"}
1
+ {"version":3,"file":"fastifyRequestHandler.d.ts","sourceRoot":"","sources":["../../../src/adapters/fastify/fastifyRequestHandler.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EAEL,KAAK,sBAAsB,EAE5B,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EAEL,KAAK,2BAA2B,EACjC,MAAM,cAAc,CAAC;AAEtB,MAAM,MAAM,qBAAqB,CAC/B,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,cAAc,EAC/B,SAAS,SAAS,YAAY,IAC5B,sBAAsB,CAAC,OAAO,EAAE,QAAQ,CAAC,GAC3C,2BAA2B,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;AAE5D,KAAK,4BAA4B,CAC/B,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,cAAc,EAC/B,SAAS,SAAS,YAAY,IAC5B,qBAAqB,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,GAAG;IACxD,GAAG,EAAE,QAAQ,CAAC;IACd,GAAG,EAAE,SAAS,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,wBAAsB,qBAAqB,CACzC,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,cAAc,EAC/B,SAAS,SAAS,YAAY,EAC9B,IAAI,EAAE,4BAA4B,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,iBAkCjE"}
@@ -1,22 +1,9 @@
1
- import type * as http from 'http';
2
- export interface UniversalIncomingMessage extends Omit<http.IncomingMessage, 'socket'> {
3
- /**
4
- * Many adapters will add a `body` property to the incoming message and pre-parse the body
5
- */
6
- body?: unknown;
7
- /**
8
- * Socket is not always available in all deployments, so we need to make it optional
9
- * @see https://github.com/trpc/trpc/issues/6341
10
- * The socket object provided in the request does not fully implement the expected Node.js Socket interface.
11
- * @see https://github.com/trpc/trpc/pull/6358
12
- */
13
- socket?: Partial<http.IncomingMessage['socket']>;
14
- }
15
- export declare function createURL(req: UniversalIncomingMessage): URL;
1
+ import type { NodeHTTPRequest, NodeHTTPResponse } from './types';
2
+ export declare function createURL(req: NodeHTTPRequest): URL;
16
3
  /**
17
4
  * Convert an [`IncomingMessage`](https://nodejs.org/api/http.html#class-httpincomingmessage) to a [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request)
18
5
  */
19
- export declare function incomingMessageToRequest(req: UniversalIncomingMessage, res: http.ServerResponse, opts: {
6
+ export declare function incomingMessageToRequest(req: NodeHTTPRequest, res: NodeHTTPResponse, opts: {
20
7
  /**
21
8
  * Max body size in bytes. If the body is larger than this, the request will be aborted
22
9
  */
@@ -1 +1 @@
1
- {"version":3,"file":"incomingMessageToRequest.d.ts","sourceRoot":"","sources":["../../../src/adapters/node-http/incomingMessageToRequest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,IAAI,MAAM,MAAM,CAAC;AAGlC,MAAM,WAAW,wBACf,SAAQ,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,QAAQ,CAAC;IAC5C;;OAEG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IACf;;;;;OAKG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC,CAAC;CAClD;AAiED,wBAAgB,SAAS,CAAC,GAAG,EAAE,wBAAwB,GAAG,GAAG,CAkB5D;AAwBD;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,wBAAwB,EAC7B,GAAG,EAAE,IAAI,CAAC,cAAc,EACxB,IAAI,EAAE;IACJ;;OAEG;IACH,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B,GACA,OAAO,CAqCT"}
1
+ {"version":3,"file":"incomingMessageToRequest.d.ts","sourceRoot":"","sources":["../../../src/adapters/node-http/incomingMessageToRequest.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAiEjE,wBAAgB,SAAS,CAAC,GAAG,EAAE,eAAe,GAAG,GAAG,CAqBnD;AAwBD;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,gBAAgB,EACrB,IAAI,EAAE;IACJ;;OAEG;IACH,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B,GACA,OAAO,CAqCT"}
@@ -55,8 +55,10 @@ function createBody(req, opts) {
55
55
  }
56
56
  function createURL(req) {
57
57
  try {
58
- const protocol = req.socket && 'encrypted' in req.socket && req.socket.encrypted ? 'https:' : 'http:';
59
- const host = req.headers.host ?? 'localhost';
58
+ const protocol = // http2
59
+ req.headers[':scheme'] && req.headers[':scheme'] === 'https' || // http1
60
+ req.socket && 'encrypted' in req.socket && req.socket.encrypted ? 'https:' : 'http:';
61
+ const host = req.headers.host ?? req.headers[':authority'] ?? 'localhost';
60
62
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
61
63
  return new URL(req.url, `${protocol}//${host}`);
62
64
  } catch (cause) {
@@ -95,7 +97,7 @@ function createHeaders(incoming) {
95
97
  ac.abort();
96
98
  };
97
99
  res.once('close', onAbort);
98
- req.socket?.once?.('end', onAbort);
100
+ req.socket?.once?.('close', onAbort);
99
101
  // Get host from either regular header or HTTP/2 pseudo-header
100
102
  const url = createURL(req);
101
103
  const init = {
@@ -53,8 +53,10 @@ function createBody(req, opts) {
53
53
  }
54
54
  function createURL(req) {
55
55
  try {
56
- const protocol = req.socket && 'encrypted' in req.socket && req.socket.encrypted ? 'https:' : 'http:';
57
- const host = req.headers.host ?? 'localhost';
56
+ const protocol = // http2
57
+ req.headers[':scheme'] && req.headers[':scheme'] === 'https' || // http1
58
+ req.socket && 'encrypted' in req.socket && req.socket.encrypted ? 'https:' : 'http:';
59
+ const host = req.headers.host ?? req.headers[':authority'] ?? 'localhost';
58
60
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
59
61
  return new URL(req.url, `${protocol}//${host}`);
60
62
  } catch (cause) {
@@ -93,7 +95,7 @@ function createHeaders(incoming) {
93
95
  ac.abort();
94
96
  };
95
97
  res.once('close', onAbort);
96
- req.socket?.once?.('end', onAbort);
98
+ req.socket?.once?.('close', onAbort);
97
99
  // Get host from either regular header or HTTP/2 pseudo-header
98
100
  const url = createURL(req);
99
101
  const init = {
@@ -8,14 +8,24 @@
8
8
  * ```
9
9
  */
10
10
  import type * as http from 'http';
11
+ import type * as http2 from 'http2';
11
12
  import type { AnyRouter, CreateContextCallback, inferRouterContext } from '../../@trpc/server';
12
13
  import type { HTTPBaseHandlerOptions, TRPCRequestInfo } from '../../@trpc/server/http';
13
- import type { MaybePromise } from '../../unstable-core-do-not-import';
14
- export type NodeHTTPRequest = http.IncomingMessage & {
14
+ import type { DistributiveOmit, MaybePromise } from '../../unstable-core-do-not-import';
15
+ export type NodeHTTPRequest = DistributiveOmit<http.IncomingMessage | http2.Http2ServerRequest, 'socket'> & {
16
+ /**
17
+ * Many adapters will add a `body` property to the incoming message and pre-parse the body
18
+ */
15
19
  body?: unknown;
16
- query?: unknown;
20
+ /**
21
+ * Socket is not always available in all deployments, so we need to make it optional
22
+ * @see https://github.com/trpc/trpc/issues/6341
23
+ * The socket object provided in the request does not fully implement the expected Node.js Socket interface.
24
+ * @see https://github.com/trpc/trpc/pull/6358
25
+ */
26
+ socket?: Partial<http.IncomingMessage['socket']> | Partial<http2.Http2ServerRequest['socket']>;
17
27
  };
18
- export type NodeHTTPResponse = http.ServerResponse & {
28
+ export type NodeHTTPResponse = DistributiveOmit<http.ServerResponse | http2.Http2ServerResponse, 'write'> & {
19
29
  /**
20
30
  * Force the partially-compressed response to be flushed to the client.
21
31
  *
@@ -25,6 +35,7 @@ export type NodeHTTPResponse = http.ServerResponse & {
25
35
  * e.g. Express w/ `compression()`)
26
36
  */
27
37
  flush?: () => void;
38
+ write: (chunk: string | Uint8Array) => boolean;
28
39
  };
29
40
  export type NodeHTTPCreateContextOption<TRouter extends AnyRouter, TRequest, TResponse> = CreateContextCallback<inferRouterContext<TRouter>, NodeHTTPCreateContextFn<TRouter, TRequest, TResponse>>;
30
41
  /**
@@ -51,11 +62,15 @@ export type NodeHTTPHandlerOptions<TRouter extends AnyRouter, TRequest extends N
51
62
  middleware?: ConnectMiddleware<TRequest, TResponse>;
52
63
  maxBodySize?: number;
53
64
  };
54
- export type NodeHTTPRequestHandlerOptions<TRouter extends AnyRouter, TRequest extends NodeHTTPRequest, TResponse extends NodeHTTPResponse> = {
65
+ export type NodeHTTPRequestHandlerOptions<TRouter extends AnyRouter, TRequest extends NodeHTTPRequest, TResponse extends NodeHTTPResponse> = NodeHTTPHandlerOptions<TRouter, TRequest, TResponse> & {
55
66
  req: TRequest;
56
67
  res: TResponse;
68
+ /**
69
+ * The tRPC path to handle requests for
70
+ * @example 'post.all'
71
+ */
57
72
  path: string;
58
- } & NodeHTTPHandlerOptions<TRouter, TRequest, TResponse>;
73
+ };
59
74
  export type NodeHTTPCreateContextFnOptions<TRequest, TResponse> = {
60
75
  req: TRequest;
61
76
  res: TResponse;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/adapters/node-http/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,KAAK,IAAI,MAAM,MAAM,CAAC;AAElC,OAAO,KAAK,EACV,SAAS,EACT,qBAAqB,EACrB,kBAAkB,EACnB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EACV,sBAAsB,EACtB,eAAe,EAChB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAEtE,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,eAAe,GAAG;IACnD,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AACF,MAA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,EAAE,QAAQ,CAAC;IACd,GAAG,EAAE,SAAS,CAAC;IACf,IAAI,EAAE,eAAe,CAAC;CACvB,CAAC;AACF,MAAM,MAAM,uBAAuB,CACjC,OAAO,SAAS,SAAS,EACzB,QAAQ,EACR,SAAS,IACP,CACF,IAAI,EAAE,8BAA8B,CAAC,QAAQ,EAAE,SAAS,CAAC,KACtD,YAAY,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC"}
@@ -8,13 +8,29 @@
8
8
  * ```
9
9
  */
10
10
  import http from 'http';
11
+ import type * as http2 from 'http2';
11
12
  import { type AnyRouter } from '../@trpc/server';
12
- import type { NodeHTTPCreateContextFnOptions, NodeHTTPHandlerOptions } from './node-http';
13
- export type CreateHTTPHandlerOptions<TRouter extends AnyRouter> = NodeHTTPHandlerOptions<TRouter, http.IncomingMessage, http.ServerResponse>;
13
+ import type { NodeHTTPCreateContextFnOptions, NodeHTTPHandlerOptions, NodeHTTPRequest, NodeHTTPResponse } from './node-http';
14
+ type StandaloneHandlerOptions<TRouter extends AnyRouter, TRequest extends NodeHTTPRequest, TResponse extends NodeHTTPResponse> = NodeHTTPHandlerOptions<TRouter, TRequest, TResponse> & {
15
+ /**
16
+ * The base path to handle requests for.
17
+ * This will be sliced from the beginning of the request path
18
+ * (Do not miss including the trailing slash)
19
+ * @default '/'
20
+ * @example '/trpc/'
21
+ * @example '/trpc/api/'
22
+ */
23
+ basePath?: string;
24
+ };
25
+ export type CreateHTTPHandlerOptions<TRouter extends AnyRouter> = StandaloneHandlerOptions<TRouter, http.IncomingMessage, http.ServerResponse>;
14
26
  export type CreateHTTPContextOptions = NodeHTTPCreateContextFnOptions<http.IncomingMessage, http.ServerResponse>;
15
27
  /**
16
28
  * @internal
17
29
  */
18
30
  export declare function createHTTPHandler<TRouter extends AnyRouter>(opts: CreateHTTPHandlerOptions<TRouter>): http.RequestListener;
19
31
  export declare function createHTTPServer<TRouter extends AnyRouter>(opts: CreateHTTPHandlerOptions<TRouter>): http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
32
+ export type CreateHTTP2HandlerOptions<TRouter extends AnyRouter> = StandaloneHandlerOptions<TRouter, http2.Http2ServerRequest, http2.Http2ServerResponse>;
33
+ export type CreateHTTP2ContextOptions = NodeHTTPCreateContextFnOptions<http2.Http2ServerRequest, http2.Http2ServerResponse>;
34
+ export declare function createHTTP2Handler(opts: CreateHTTP2HandlerOptions<AnyRouter>): (req: http2.Http2ServerRequest, res: http2.Http2ServerResponse<http2.Http2ServerRequest>) => void;
35
+ export {};
20
36
  //# sourceMappingURL=standalone.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"standalone.d.ts","sourceRoot":"","sources":["../../src/adapters/standalone.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAGjD,OAAO,KAAK,EACV,8BAA8B,EAC9B,sBAAsB,EACvB,MAAM,aAAa,CAAC;AAOrB,MAAM,MAAM,wBAAwB,CAAC,OAAO,SAAS,SAAS,IAC5D,sBAAsB,CAAC,OAAO,EAAE,IAAI,CAAC,eAAe,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;AAE7E,MAAM,MAAM,wBAAwB,GAAG,8BAA8B,CACnE,IAAI,CAAC,eAAe,EACpB,IAAI,CAAC,cAAc,CACpB,CAAC;AAEF;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,SAAS,SAAS,EACzD,IAAI,EAAE,wBAAwB,CAAC,OAAO,CAAC,GACtC,IAAI,CAAC,eAAe,CAyBtB;AAED,wBAAgB,gBAAgB,CAAC,OAAO,SAAS,SAAS,EACxD,IAAI,EAAE,wBAAwB,CAAC,OAAO,CAAC,wEAGxC"}
1
+ {"version":3,"file":"standalone.d.ts","sourceRoot":"","sources":["../../src/adapters/standalone.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO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B,CAAC,SAAS,CAAC,gGA1DvC,IAAI,CA4DzC"}
@@ -8,16 +8,15 @@ require('../unstable-core-do-not-import/rootConfig.js');
8
8
  var nodeHTTPRequestHandler = require('./node-http/nodeHTTPRequestHandler.js');
9
9
  var incomingMessageToRequest = require('./node-http/incomingMessageToRequest.js');
10
10
 
11
- /**
12
- * @internal
13
- */ function createHTTPHandler(opts) {
11
+ function createHandler(opts) {
12
+ const basePath = opts.basePath ?? '/';
13
+ const sliceLength = basePath.length;
14
14
  return (req, res)=>{
15
15
  let path = '';
16
16
  utils.run(async ()=>{
17
17
  const url = incomingMessageToRequest.createURL(req);
18
- // get procedure path and remove the leading slash
19
- // /procedure -> procedure
20
- path = url.pathname.slice(1);
18
+ // get procedure(s) path and remove the leading slash
19
+ path = url.pathname.slice(sliceLength);
21
20
  await nodeHTTPRequestHandler.nodeHTTPRequestHandler({
22
21
  ...opts,
23
22
  req,
@@ -32,9 +31,18 @@ var incomingMessageToRequest = require('./node-http/incomingMessageToRequest.js'
32
31
  }));
33
32
  };
34
33
  }
34
+ /**
35
+ * @internal
36
+ */ function createHTTPHandler(opts) {
37
+ return createHandler(opts);
38
+ }
35
39
  function createHTTPServer(opts) {
36
40
  return http.createServer(createHTTPHandler(opts));
37
41
  }
42
+ function createHTTP2Handler(opts) {
43
+ return createHandler(opts);
44
+ }
38
45
 
46
+ exports.createHTTP2Handler = createHTTP2Handler;
39
47
  exports.createHTTPHandler = createHTTPHandler;
40
48
  exports.createHTTPServer = createHTTPServer;
@@ -6,16 +6,15 @@ import '../unstable-core-do-not-import/rootConfig.mjs';
6
6
  import { nodeHTTPRequestHandler, internal_exceptionHandler } from './node-http/nodeHTTPRequestHandler.mjs';
7
7
  import { createURL } from './node-http/incomingMessageToRequest.mjs';
8
8
 
9
- /**
10
- * @internal
11
- */ function createHTTPHandler(opts) {
9
+ function createHandler(opts) {
10
+ const basePath = opts.basePath ?? '/';
11
+ const sliceLength = basePath.length;
12
12
  return (req, res)=>{
13
13
  let path = '';
14
14
  run(async ()=>{
15
15
  const url = createURL(req);
16
- // get procedure path and remove the leading slash
17
- // /procedure -> procedure
18
- path = url.pathname.slice(1);
16
+ // get procedure(s) path and remove the leading slash
17
+ path = url.pathname.slice(sliceLength);
19
18
  await nodeHTTPRequestHandler({
20
19
  ...opts,
21
20
  req,
@@ -30,8 +29,16 @@ import { createURL } from './node-http/incomingMessageToRequest.mjs';
30
29
  }));
31
30
  };
32
31
  }
32
+ /**
33
+ * @internal
34
+ */ function createHTTPHandler(opts) {
35
+ return createHandler(opts);
36
+ }
33
37
  function createHTTPServer(opts) {
34
38
  return http.createServer(createHTTPHandler(opts));
35
39
  }
40
+ function createHTTP2Handler(opts) {
41
+ return createHandler(opts);
42
+ }
36
43
 
37
- export { createHTTPHandler, createHTTPServer };
44
+ export { createHTTP2Handler, createHTTPHandler, createHTTPServer };
@@ -1 +1 @@
1
- {"version":3,"file":"ws.d.ts","sourceRoot":"","sources":["../../src/adapters/ws.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAC5C,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,EACV,SAAS,EACT,qBAAqB,EACrB,kBAAkB,EACnB,MAAM,iBAAiB,CAAC;AASzB,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAa/D,OAAO,EAKL,KAAK,YAAY,EAClB,MAAM,gCAAgC,CAAC;AAIxC,OAAO,EAAa,KAAK,8BAA8B,EAAE,MAAM,aAAa,CAAC;AAQ7E;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG,8BAA8B,CACpE,eAAe,EACf,EAAE,CAAC,SAAS,CACb,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,kBAAkB,CAAC,OAAO,SAAS,SAAS,IAAI,CAC1D,IAAI,EAAE,yBAAyB,KAC5B,YAAY,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC;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AAS,EACpB,MAAM,SAAS,EACf,UAAU,SAAQ,QAiCnB;AAED,wBAAgB,eAAe,CAAC,OAAO,SAAS,SAAS,EACvD,IAAI,EAAE,iBAAiB,CAAC,OAAO,CAAC;;EAwCjC"}
@@ -109,7 +109,8 @@ function getWSConnectionHandler(opts) {
109
109
  isBatchCall: false,
110
110
  accept: null,
111
111
  type: 'unknown',
112
- signal: abortController.signal
112
+ signal: abortController.signal,
113
+ url: null
113
114
  }
114
115
  });
115
116
  return ctx;
@@ -107,7 +107,8 @@ function getWSConnectionHandler(opts) {
107
107
  isBatchCall: false,
108
108
  accept: null,
109
109
  type: 'unknown',
110
- signal: abortController.signal
110
+ signal: abortController.signal,
111
+ url: null
111
112
  }
112
113
  });
113
114
  return ctx;
@@ -1,12 +1,12 @@
1
1
  {
2
- "bundleSize": 194424,
3
- "bundleOrigSize": 224713,
4
- "bundleReduction": 13.48,
2
+ "bundleSize": 194887,
3
+ "bundleOrigSize": 225774,
4
+ "bundleReduction": 13.68,
5
5
  "modules": [
6
6
  {
7
7
  "id": "/src/unstable-core-do-not-import/http/resolveResponse.ts",
8
- "size": 21013,
9
- "origSize": 19389,
8
+ "size": 21038,
9
+ "origSize": 19404,
10
10
  "renderedExports": [
11
11
  "resolveResponse"
12
12
  ],
@@ -14,13 +14,13 @@
14
14
  "dependents": [
15
15
  "/src/unstable-core-do-not-import.ts"
16
16
  ],
17
- "percent": 10.81,
17
+ "percent": 10.79,
18
18
  "reduction": 0
19
19
  },
20
20
  {
21
21
  "id": "/src/adapters/ws.ts",
22
- "size": 20133,
23
- "origSize": 15932,
22
+ "size": 20168,
23
+ "origSize": 15955,
24
24
  "renderedExports": [
25
25
  "getWSConnectionHandler",
26
26
  "handleKeepAlive",
@@ -30,7 +30,7 @@
30
30
  "dependents": [
31
31
  "/src/adapters/fastify/fastifyTRPCPlugin.ts"
32
32
  ],
33
- "percent": 10.36,
33
+ "percent": 10.35,
34
34
  "reduction": 0
35
35
  },
36
36
  {
@@ -47,7 +47,7 @@
47
47
  "/src/unstable-core-do-not-import.ts",
48
48
  "/src/unstable-core-do-not-import/http/resolveResponse.ts"
49
49
  ],
50
- "percent": 10.3,
50
+ "percent": 10.27,
51
51
  "reduction": 0
52
52
  },
53
53
  {
@@ -64,7 +64,7 @@
64
64
  "/src/unstable-core-do-not-import.ts",
65
65
  "/src/unstable-core-do-not-import/http/resolveResponse.ts"
66
66
  ],
67
- "percent": 6.49,
67
+ "percent": 6.48,
68
68
  "reduction": 0
69
69
  },
70
70
  {
@@ -77,7 +77,7 @@
77
77
  ],
78
78
  "removedExports": [],
79
79
  "dependents": [],
80
- "percent": 6.25,
80
+ "percent": 6.24,
81
81
  "reduction": 11.62
82
82
  },
83
83
  {
@@ -91,13 +91,13 @@
91
91
  "dependents": [
92
92
  "/src/unstable-core-do-not-import/stream/jsonl.ts"
93
93
  ],
94
- "percent": 4.18,
94
+ "percent": 4.17,
95
95
  "reduction": 0
96
96
  },
97
97
  {
98
98
  "id": "/src/unstable-core-do-not-import/http/contentType.ts",
99
- "size": 7685,
100
- "origSize": 7608,
99
+ "size": 7766,
100
+ "origSize": 7690,
101
101
  "renderedExports": [
102
102
  "getRequestInfo"
103
103
  ],
@@ -106,7 +106,7 @@
106
106
  "/src/unstable-core-do-not-import.ts",
107
107
  "/src/unstable-core-do-not-import/http/resolveResponse.ts"
108
108
  ],
109
- "percent": 3.95,
109
+ "percent": 3.98,
110
110
  "reduction": 0
111
111
  },
112
112
  {
@@ -124,7 +124,7 @@
124
124
  "/src/unstable-core-do-not-import.ts",
125
125
  "/src/unstable-core-do-not-import/initTRPC.ts"
126
126
  ],
127
- "percent": 3.32,
127
+ "percent": 3.31,
128
128
  "reduction": 39.41
129
129
  },
130
130
  {
@@ -143,7 +143,7 @@
143
143
  "/src/unstable-core-do-not-import/stream/sse.ts",
144
144
  "/src/unstable-core-do-not-import/stream/utils/withPing.ts"
145
145
  ],
146
- "percent": 3,
146
+ "percent": 2.99,
147
147
  "reduction": 0
148
148
  },
149
149
  {
@@ -158,7 +158,7 @@
158
158
  "/src/unstable-core-do-not-import.ts",
159
159
  "/src/unstable-core-do-not-import/initTRPC.ts"
160
160
  ],
161
- "percent": 2.98,
161
+ "percent": 2.97,
162
162
  "reduction": 65.01
163
163
  },
164
164
  {
@@ -192,7 +192,7 @@
192
192
  "/src/observable/operators.ts",
193
193
  "/src/observable/behaviorSubject.ts"
194
194
  ],
195
- "percent": 2.49,
195
+ "percent": 2.48,
196
196
  "reduction": 0
197
197
  },
198
198
  {
@@ -212,8 +212,8 @@
212
212
  },
213
213
  {
214
214
  "id": "/src/adapters/node-http/incomingMessageToRequest.ts",
215
- "size": 3918,
216
- "origSize": 4751,
215
+ "size": 4047,
216
+ "origSize": 4343,
217
217
  "renderedExports": [
218
218
  "createURL",
219
219
  "incomingMessageToRequest"
@@ -223,8 +223,8 @@
223
223
  "/src/adapters/node-http/index.ts",
224
224
  "/src/adapters/node-http/nodeHTTPRequestHandler.ts"
225
225
  ],
226
- "percent": 2.02,
227
- "reduction": 17.53
226
+ "percent": 2.08,
227
+ "reduction": 6.82
228
228
  },
229
229
  {
230
230
  "id": "/src/observable/operators.ts",
@@ -255,7 +255,7 @@
255
255
  "dependents": [
256
256
  "/src/adapters/next-app-dir.ts"
257
257
  ],
258
- "percent": 1.67,
258
+ "percent": 1.66,
259
259
  "reduction": 22.52
260
260
  },
261
261
  {
@@ -351,18 +351,18 @@
351
351
  "/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts",
352
352
  "/src/unstable-core-do-not-import/http/parseConnectionParams.ts",
353
353
  "/src/unstable-core-do-not-import/http/resolveResponse.ts",
354
- "/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts",
355
354
  "/src/unstable-core-do-not-import/error/TRPCError.ts",
356
355
  "/src/unstable-core-do-not-import/transformer.ts",
357
356
  "/src/unstable-core-do-not-import/middleware.ts",
358
357
  "/src/unstable-core-do-not-import/router.ts",
358
+ "/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts",
359
359
  "/src/unstable-core-do-not-import/http/contentType.ts",
360
360
  "/src/unstable-core-do-not-import/http/isAbortError.ts",
361
361
  "/src/unstable-core-do-not-import/procedureBuilder.ts",
362
362
  "/src/unstable-core-do-not-import/stream/jsonl.ts",
363
363
  "/src/unstable-core-do-not-import/stream/sse.ts"
364
364
  ],
365
- "percent": 1.27,
365
+ "percent": 1.26,
366
366
  "reduction": 17.51
367
367
  },
368
368
  {
@@ -574,7 +574,7 @@
574
574
  {
575
575
  "id": "/src/adapters/fastify/fastifyRequestHandler.ts",
576
576
  "size": 1146,
577
- "origSize": 2174,
577
+ "origSize": 2185,
578
578
  "renderedExports": [
579
579
  "fastifyRequestHandler"
580
580
  ],
@@ -584,7 +584,7 @@
584
584
  "/src/adapters/fastify/fastifyTRPCPlugin.ts"
585
585
  ],
586
586
  "percent": 0.59,
587
- "reduction": 47.29
587
+ "reduction": 47.55
588
588
  },
589
589
  {
590
590
  "id": "/src/unstable-core-do-not-import/http/parseConnectionParams.ts",
@@ -613,7 +613,7 @@
613
613
  "dependents": [
614
614
  "/src/unstable-core-do-not-import.ts"
615
615
  ],
616
- "percent": 0.55,
616
+ "percent": 0.54,
617
617
  "reduction": 0
618
618
  },
619
619
  {
@@ -630,6 +630,20 @@
630
630
  "percent": 0.5,
631
631
  "reduction": 32.89
632
632
  },
633
+ {
634
+ "id": "/src/adapters/standalone.ts",
635
+ "size": 958,
636
+ "origSize": 3103,
637
+ "renderedExports": [
638
+ "createHTTPHandler",
639
+ "createHTTPServer",
640
+ "createHTTP2Handler"
641
+ ],
642
+ "removedExports": [],
643
+ "dependents": [],
644
+ "percent": 0.49,
645
+ "reduction": 69.13
646
+ },
633
647
  {
634
648
  "id": "/src/adapters/express.ts",
635
649
  "size": 887,
@@ -659,19 +673,6 @@
659
673
  "percent": 0.4,
660
674
  "reduction": 44.13
661
675
  },
662
- {
663
- "id": "/src/adapters/standalone.ts",
664
- "size": 765,
665
- "origSize": 1765,
666
- "renderedExports": [
667
- "createHTTPHandler",
668
- "createHTTPServer"
669
- ],
670
- "removedExports": [],
671
- "dependents": [],
672
- "percent": 0.39,
673
- "reduction": 56.66
674
- },
675
676
  {
676
677
  "id": "/src/adapters/aws-lambda/index.ts",
677
678
  "size": 759,
@@ -864,9 +865,9 @@
864
865
  "reduction": 100
865
866
  },
866
867
  {
867
- "id": "/src/rpc.ts",
868
+ "id": "/src/index.ts",
868
869
  "size": 0,
869
- "origSize": 36,
870
+ "origSize": 32,
870
871
  "renderedExports": [],
871
872
  "removedExports": [],
872
873
  "dependents": [],
@@ -874,9 +875,9 @@
874
875
  "reduction": 100
875
876
  },
876
877
  {
877
- "id": "/src/index.ts",
878
+ "id": "/src/shared.ts",
878
879
  "size": 0,
879
- "origSize": 32,
880
+ "origSize": 653,
880
881
  "renderedExports": [],
881
882
  "removedExports": [],
882
883
  "dependents": [],
@@ -884,9 +885,9 @@
884
885
  "reduction": 100
885
886
  },
886
887
  {
887
- "id": "/src/shared.ts",
888
+ "id": "/src/rpc.ts",
888
889
  "size": 0,
889
- "origSize": 653,
890
+ "origSize": 36,
890
891
  "renderedExports": [],
891
892
  "removedExports": [],
892
893
  "dependents": [],
@@ -902,8 +903,8 @@
902
903
  "dependents": [
903
904
  "/src/adapters/express.ts",
904
905
  "/src/adapters/ws.ts",
905
- "/src/adapters/next.ts",
906
906
  "/src/adapters/standalone.ts",
907
+ "/src/adapters/next.ts",
907
908
  "/src/adapters/node-http/nodeHTTPRequestHandler.ts",
908
909
  "/src/adapters/next-app-dir/nextAppDirCaller.ts",
909
910
  "/src/adapters/node-http/writeResponse.ts"
@@ -934,9 +935,9 @@
934
935
  "reduction": 100
935
936
  },
936
937
  {
937
- "id": "/src/adapters/fastify/index.ts",
938
+ "id": "/src/adapters/fetch/index.ts",
938
939
  "size": 0,
939
- "origSize": 78,
940
+ "origSize": 64,
940
941
  "renderedExports": [],
941
942
  "removedExports": [],
942
943
  "dependents": [],
@@ -944,9 +945,9 @@
944
945
  "reduction": 100
945
946
  },
946
947
  {
947
- "id": "/src/adapters/fetch/index.ts",
948
+ "id": "/src/adapters/fastify/index.ts",
948
949
  "size": 0,
949
- "origSize": 64,
950
+ "origSize": 78,
950
951
  "renderedExports": [],
951
952
  "removedExports": [],
952
953
  "dependents": [],
@@ -962,8 +963,8 @@
962
963
  "dependents": [
963
964
  "/src/adapters/express.ts",
964
965
  "/src/adapters/ws.ts",
965
- "/src/adapters/next.ts",
966
966
  "/src/adapters/standalone.ts",
967
+ "/src/adapters/next.ts",
967
968
  "/src/adapters/fastify/fastifyRequestHandler.ts"
968
969
  ],
969
970
  "percent": 0,
@@ -3,6 +3,7 @@ import type { TRPCRequestInfo } from './types';
3
3
  type GetRequestInfoOptions = {
4
4
  path: string;
5
5
  req: Request;
6
+ url: URL | null;
6
7
  searchParams: URLSearchParams;
7
8
  headers: Headers;
8
9
  router: AnyRouter;
@@ -1 +1 @@
1
- {"version":3,"file":"contentType.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/http/contentType.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAG3C,OAAO,KAAK,EAAoB,eAAe,EAAE,MAAM,SAAS,CAAC;AAEjE,KAAK,qBAAqB,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,OAAO,CAAC;IACb,YAAY,EAAE,eAAe,CAAC;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,SAAS,CAAC;CACnB,CAAC;AAwQF,wBAAgB,cAAc,CAAC,IAAI,EAAE,qBAAqB,GAAG,eAAe,CAG3E"}
1
+ {"version":3,"file":"contentType.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/http/contentType.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAG3C,OAAO,KAAK,EAAoB,eAAe,EAAE,MAAM,SAAS,CAAC;AAEjE,KAAK,qBAAqB,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,OAAO,CAAC;IACb,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC;IAChB,YAAY,EAAE,eAAe,CAAC;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,SAAS,CAAC;CACnB,CAAC;AA2QF,wBAAgB,cAAc,CAAC,IAAI,EAAE,qBAAqB,GAAG,eAAe,CAG3E"}
@@ -129,7 +129,8 @@ const jsonContentTypeHandler = {
129
129
  calls,
130
130
  type,
131
131
  connectionParams: connectionParamsStr === null ? null : parseConnectionParams.parseConnectionParamsFromString(connectionParamsStr),
132
- signal: req.signal
132
+ signal: req.signal,
133
+ url: opts.url
133
134
  };
134
135
  return info;
135
136
  }
@@ -163,7 +164,8 @@ const formDataContentTypeHandler = {
163
164
  isBatchCall: false,
164
165
  type: 'mutation',
165
166
  connectionParams: null,
166
- signal: req.signal
167
+ signal: req.signal,
168
+ url: opts.url
167
169
  };
168
170
  }
169
171
  };
@@ -195,7 +197,8 @@ const octetStreamContentTypeHandler = {
195
197
  accept: null,
196
198
  type: 'mutation',
197
199
  connectionParams: null,
198
- signal: req.signal
200
+ signal: req.signal,
201
+ url: opts.url
199
202
  };
200
203
  }
201
204
  };
@@ -127,7 +127,8 @@ const jsonContentTypeHandler = {
127
127
  calls,
128
128
  type,
129
129
  connectionParams: connectionParamsStr === null ? null : parseConnectionParamsFromString(connectionParamsStr),
130
- signal: req.signal
130
+ signal: req.signal,
131
+ url: opts.url
131
132
  };
132
133
  return info;
133
134
  }
@@ -161,7 +162,8 @@ const formDataContentTypeHandler = {
161
162
  isBatchCall: false,
162
163
  type: 'mutation',
163
164
  connectionParams: null,
164
- signal: req.signal
165
+ signal: req.signal,
166
+ url: opts.url
165
167
  };
166
168
  }
167
169
  };
@@ -193,7 +195,8 @@ const octetStreamContentTypeHandler = {
193
195
  accept: null,
194
196
  type: 'mutation',
195
197
  connectionParams: null,
196
- signal: req.signal
198
+ signal: req.signal,
199
+ url: opts.url
197
200
  };
198
201
  }
199
202
  };
@@ -1 +1 @@
1
- {"version":3,"file":"resolveResponse.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/http/resolveResponse.ts"],"names":[],"mappings":"AAMA,OAAO,EAA2B,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAExE,OAAO,EACL,KAAK,SAAS,EAGf,MAAM,WAAW,CAAC;AAQnB,OAAO,KAAK,EACV,sBAAsB,EACtB,kCAAkC,EAEnC,MAAM,SAAS,CAAC;AA+BjB,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;AA2ID,wBAAsB,eAAe,CAAC,OAAO,SAAS,SAAS,EAC7D,IAAI,EAAE,yBAAyB,CAAC,OAAO,CAAC,GACvC,OAAO,CAAC,QAAQ,CAAC,CAmfnB"}
1
+ {"version":3,"file":"resolveResponse.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/http/resolveResponse.ts"],"names":[],"mappings":"AAMA,OAAO,EAA2B,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAExE,OAAO,EACL,KAAK,SAAS,EAGf,MAAM,WAAW,CAAC;AAQnB,OAAO,KAAK,EACV,sBAAsB,EACtB,kCAAkC,EAEnC,MAAM,SAAS,CAAC;AA+BjB,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;AA2ID,wBAAsB,eAAe,CAAC,OAAO,SAAS,SAAS,EAC7D,IAAI,EAAE,yBAAyB,CAAC,OAAO,CAAC,GACvC,OAAO,CAAC,QAAQ,CAAC,CAofnB"}
@@ -151,7 +151,8 @@ async function resolveResponse(opts) {
151
151
  path: decodeURIComponent(opts.path),
152
152
  router,
153
153
  searchParams: url.searchParams,
154
- headers: opts.req.headers
154
+ headers: opts.req.headers,
155
+ url
155
156
  })
156
157
  ];
157
158
  } catch (cause) {
@@ -149,7 +149,8 @@ async function resolveResponse(opts) {
149
149
  path: decodeURIComponent(opts.path),
150
150
  router,
151
151
  searchParams: url.searchParams,
152
- headers: opts.req.headers
152
+ headers: opts.req.headers,
153
+ url
153
154
  })
154
155
  ];
155
156
  } catch (cause) {
@@ -88,6 +88,10 @@ export interface TRPCRequestInfo {
88
88
  * Can be used to abort async operations during the request, e.g. `fetch()`-requests
89
89
  */
90
90
  signal: AbortSignal;
91
+ /**
92
+ * The URL of the request if available
93
+ */
94
+ url: URL | null;
91
95
  }
92
96
  /**
93
97
  * Inner createContext function for `resolveResponse` used to forward `TRPCRequestInfo` to `createContext`
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/http/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EACV,YAAY,EACZ,mBAAmB,EACnB,aAAa,EACd,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EACV,SAAS,EACT,kBAAkB,EAClB,gBAAgB,EACjB,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAErC;;GAEG;AACH,KAAK,WAAW,GAAG,IAAI,CAAC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EAAE,gBAAgB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAC9C;;OAEG;IACH,QAAQ,CAAC,EAAE;QACT;;WAEG;QACH,OAAO,EAAE,OAAO,CAAC;KAClB,CAAC;IACF,MAAM,EAAE,OAAO,CAAC;IAChB;;;OAGG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/server",
3
- "version": "11.0.0-rc.730+776d07336",
3
+ "version": "11.0.0-rc.741+caed91ee7",
4
4
  "description": "The tRPC server library",
5
5
  "author": "KATT",
6
6
  "license": "MIT",
@@ -120,7 +120,7 @@
120
120
  "@fastify/websocket": "^10.0.1",
121
121
  "@tanstack/react-query": "^5.62.8",
122
122
  "@types/aws-lambda": "^8.10.137",
123
- "@types/express": "^4.17.17",
123
+ "@types/express": "^5.0.0",
124
124
  "@types/hash-sum": "^1.0.0",
125
125
  "@types/node": "^22.9.0",
126
126
  "@types/react": "^19.0.0",
@@ -141,7 +141,7 @@
141
141
  "superstruct": "^2.0.0",
142
142
  "tsx": "^4.0.0",
143
143
  "typescript": "^5.7.2",
144
- "valibot": "1.0.0-beta.14",
144
+ "valibot": "1.0.0-beta.15",
145
145
  "ws": "^8.0.0",
146
146
  "yup": "^1.0.0",
147
147
  "zod": "^3.0.0"
@@ -152,5 +152,5 @@
152
152
  "peerDependencies": {
153
153
  "typescript": ">=5.7.2"
154
154
  },
155
- "gitHead": "776d07336bddd01ac2ad02da0360fb71aa734471"
155
+ "gitHead": "caed91ee782f78ada6c8c0c82e2d9d2ff474f555"
156
156
  }
@@ -17,10 +17,10 @@ import {
17
17
  type ResolveHTTPRequestOptionsContextFn,
18
18
  } from '../../@trpc/server/http';
19
19
  // @trpc/server/node-http
20
+ import type { NodeHTTPRequest } from '../node-http';
20
21
  import {
21
22
  incomingMessageToRequest,
22
23
  type NodeHTTPCreateContextOption,
23
- type UniversalIncomingMessage,
24
24
  } from '../node-http';
25
25
 
26
26
  export type FastifyHandlerOptions<
@@ -54,7 +54,7 @@ export async function fastifyRequestHandler<
54
54
  });
55
55
  };
56
56
 
57
- const incomingMessage: UniversalIncomingMessage = opts.req.raw;
57
+ const incomingMessage: NodeHTTPRequest = opts.req.raw;
58
58
 
59
59
  // monkey-path body to the IncomingMessage
60
60
  if ('body' in opts.req) {
@@ -1,23 +1,9 @@
1
1
  import type * as http from 'http';
2
2
  import { TRPCError } from '../../@trpc/server';
3
-
4
- export interface UniversalIncomingMessage
5
- extends Omit<http.IncomingMessage, 'socket'> {
6
- /**
7
- * Many adapters will add a `body` property to the incoming message and pre-parse the body
8
- */
9
- body?: unknown;
10
- /**
11
- * Socket is not always available in all deployments, so we need to make it optional
12
- * @see https://github.com/trpc/trpc/issues/6341
13
- * The socket object provided in the request does not fully implement the expected Node.js Socket interface.
14
- * @see https://github.com/trpc/trpc/pull/6358
15
- */
16
- socket?: Partial<http.IncomingMessage['socket']>;
17
- }
3
+ import type { NodeHTTPRequest, NodeHTTPResponse } from './types';
18
4
 
19
5
  function createBody(
20
- req: UniversalIncomingMessage,
6
+ req: NodeHTTPRequest,
21
7
  opts: {
22
8
  /**
23
9
  * Max body size in bytes. If the body is larger than this, the request will be aborted
@@ -79,14 +65,17 @@ function createBody(
79
65
  },
80
66
  });
81
67
  }
82
- export function createURL(req: UniversalIncomingMessage): URL {
68
+ export function createURL(req: NodeHTTPRequest): URL {
83
69
  try {
84
70
  const protocol =
85
- req.socket && 'encrypted' in req.socket && req.socket.encrypted
71
+ // http2
72
+ (req.headers[':scheme'] && req.headers[':scheme'] === 'https') ||
73
+ // http1
74
+ (req.socket && 'encrypted' in req.socket && req.socket.encrypted)
86
75
  ? 'https:'
87
76
  : 'http:';
88
77
 
89
- const host = req.headers.host ?? 'localhost';
78
+ const host = req.headers.host ?? req.headers[':authority'] ?? 'localhost';
90
79
 
91
80
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
92
81
  return new URL(req.url!, `${protocol}//${host}`);
@@ -125,8 +114,8 @@ function createHeaders(incoming: http.IncomingHttpHeaders): Headers {
125
114
  * Convert an [`IncomingMessage`](https://nodejs.org/api/http.html#class-httpincomingmessage) to a [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request)
126
115
  */
127
116
  export function incomingMessageToRequest(
128
- req: UniversalIncomingMessage,
129
- res: http.ServerResponse,
117
+ req: NodeHTTPRequest,
118
+ res: NodeHTTPResponse,
130
119
  opts: {
131
120
  /**
132
121
  * Max body size in bytes. If the body is larger than this, the request will be aborted
@@ -145,7 +134,7 @@ export function incomingMessageToRequest(
145
134
  };
146
135
 
147
136
  res.once('close', onAbort);
148
- req.socket?.once?.('end', onAbort);
137
+ req.socket?.once?.('close', onAbort);
149
138
 
150
139
  // Get host from either regular header or HTTP/2 pseudo-header
151
140
  const url = createURL(req);
@@ -8,6 +8,7 @@
8
8
  * ```
9
9
  */
10
10
  import type * as http from 'http';
11
+ import type * as http2 from 'http2';
11
12
  // @trpc/server
12
13
  import type {
13
14
  AnyRouter,
@@ -20,13 +21,34 @@ import type {
20
21
  TRPCRequestInfo,
21
22
  } from '../../@trpc/server/http';
22
23
  // eslint-disable-next-line no-restricted-imports
23
- import type { MaybePromise } from '../../unstable-core-do-not-import';
24
+ import type {
25
+ DistributiveOmit,
26
+ MaybePromise,
27
+ } from '../../unstable-core-do-not-import';
24
28
 
25
- export type NodeHTTPRequest = http.IncomingMessage & {
29
+ export type NodeHTTPRequest = DistributiveOmit<
30
+ http.IncomingMessage | http2.Http2ServerRequest,
31
+ 'socket'
32
+ > & {
33
+ /**
34
+ * Many adapters will add a `body` property to the incoming message and pre-parse the body
35
+ */
26
36
  body?: unknown;
27
- query?: unknown;
37
+ /**
38
+ * Socket is not always available in all deployments, so we need to make it optional
39
+ * @see https://github.com/trpc/trpc/issues/6341
40
+ * The socket object provided in the request does not fully implement the expected Node.js Socket interface.
41
+ * @see https://github.com/trpc/trpc/pull/6358
42
+ */
43
+ socket?:
44
+ | Partial<http.IncomingMessage['socket']>
45
+ | Partial<http2.Http2ServerRequest['socket']>;
28
46
  };
29
- export type NodeHTTPResponse = http.ServerResponse & {
47
+
48
+ export type NodeHTTPResponse = DistributiveOmit<
49
+ http.ServerResponse | http2.Http2ServerResponse,
50
+ 'write'
51
+ > & {
30
52
  /**
31
53
  * Force the partially-compressed response to be flushed to the client.
32
54
  *
@@ -36,8 +58,9 @@ export type NodeHTTPResponse = http.ServerResponse & {
36
58
  * e.g. Express w/ `compression()`)
37
59
  */
38
60
  flush?: () => void;
39
- };
40
61
 
62
+ write: (chunk: string | Uint8Array) => boolean;
63
+ };
41
64
  export type NodeHTTPCreateContextOption<
42
65
  TRouter extends AnyRouter,
43
66
  TRequest,
@@ -85,11 +108,15 @@ export type NodeHTTPRequestHandlerOptions<
85
108
  TRouter extends AnyRouter,
86
109
  TRequest extends NodeHTTPRequest,
87
110
  TResponse extends NodeHTTPResponse,
88
- > = {
111
+ > = NodeHTTPHandlerOptions<TRouter, TRequest, TResponse> & {
89
112
  req: TRequest;
90
113
  res: TResponse;
114
+ /**
115
+ * The tRPC path to handle requests for
116
+ * @example 'post.all'
117
+ */
91
118
  path: string;
92
- } & NodeHTTPHandlerOptions<TRouter, TRequest, TResponse>;
119
+ };
93
120
 
94
121
  export type NodeHTTPCreateContextFnOptions<TRequest, TResponse> = {
95
122
  req: TRequest;
@@ -9,6 +9,8 @@
9
9
  */
10
10
 
11
11
  import http from 'http';
12
+ // --- http2 ---
13
+ import type * as http2 from 'http2';
12
14
  // @trpc/server
13
15
  import { type AnyRouter } from '../@trpc/server';
14
16
  // eslint-disable-next-line no-restricted-imports
@@ -16,6 +18,8 @@ import { run } from '../unstable-core-do-not-import';
16
18
  import type {
17
19
  NodeHTTPCreateContextFnOptions,
18
20
  NodeHTTPHandlerOptions,
21
+ NodeHTTPRequest,
22
+ NodeHTTPResponse,
19
23
  } from './node-http';
20
24
  import {
21
25
  createURL,
@@ -23,28 +27,49 @@ import {
23
27
  nodeHTTPRequestHandler,
24
28
  } from './node-http';
25
29
 
30
+ type StandaloneHandlerOptions<
31
+ TRouter extends AnyRouter,
32
+ TRequest extends NodeHTTPRequest,
33
+ TResponse extends NodeHTTPResponse,
34
+ > = NodeHTTPHandlerOptions<TRouter, TRequest, TResponse> & {
35
+ /**
36
+ * The base path to handle requests for.
37
+ * This will be sliced from the beginning of the request path
38
+ * (Do not miss including the trailing slash)
39
+ * @default '/'
40
+ * @example '/trpc/'
41
+ * @example '/trpc/api/'
42
+ */
43
+ basePath?: string;
44
+ };
45
+
46
+ // --- http1 ---
26
47
  export type CreateHTTPHandlerOptions<TRouter extends AnyRouter> =
27
- NodeHTTPHandlerOptions<TRouter, http.IncomingMessage, http.ServerResponse>;
48
+ StandaloneHandlerOptions<TRouter, http.IncomingMessage, http.ServerResponse>;
28
49
 
29
50
  export type CreateHTTPContextOptions = NodeHTTPCreateContextFnOptions<
30
51
  http.IncomingMessage,
31
52
  http.ServerResponse
32
53
  >;
33
54
 
34
- /**
35
- * @internal
36
- */
37
- export function createHTTPHandler<TRouter extends AnyRouter>(
38
- opts: CreateHTTPHandlerOptions<TRouter>,
39
- ): http.RequestListener {
55
+ function createHandler<
56
+ TRouter extends AnyRouter,
57
+ TRequest extends NodeHTTPRequest,
58
+ TResponse extends NodeHTTPResponse,
59
+ >(
60
+ opts: StandaloneHandlerOptions<TRouter, TRequest, TResponse>,
61
+ ): (req: TRequest, res: TResponse) => void {
62
+ const basePath = opts.basePath ?? '/';
63
+ const sliceLength = basePath.length;
64
+
40
65
  return (req, res) => {
41
66
  let path = '';
67
+
42
68
  run(async () => {
43
69
  const url = createURL(req);
44
70
 
45
- // get procedure path and remove the leading slash
46
- // /procedure -> procedure
47
- path = url.pathname.slice(1);
71
+ // get procedure(s) path and remove the leading slash
72
+ path = url.pathname.slice(sliceLength);
48
73
 
49
74
  await nodeHTTPRequestHandler({
50
75
  ...(opts as any),
@@ -63,8 +88,34 @@ export function createHTTPHandler<TRouter extends AnyRouter>(
63
88
  };
64
89
  }
65
90
 
91
+ /**
92
+ * @internal
93
+ */
94
+ export function createHTTPHandler<TRouter extends AnyRouter>(
95
+ opts: CreateHTTPHandlerOptions<TRouter>,
96
+ ): http.RequestListener {
97
+ return createHandler(opts);
98
+ }
99
+
66
100
  export function createHTTPServer<TRouter extends AnyRouter>(
67
101
  opts: CreateHTTPHandlerOptions<TRouter>,
68
102
  ) {
69
103
  return http.createServer(createHTTPHandler(opts));
70
104
  }
105
+
106
+ // --- http2 ---
107
+ export type CreateHTTP2HandlerOptions<TRouter extends AnyRouter> =
108
+ StandaloneHandlerOptions<
109
+ TRouter,
110
+ http2.Http2ServerRequest,
111
+ http2.Http2ServerResponse
112
+ >;
113
+
114
+ export type CreateHTTP2ContextOptions = NodeHTTPCreateContextFnOptions<
115
+ http2.Http2ServerRequest,
116
+ http2.Http2ServerResponse
117
+ >;
118
+
119
+ export function createHTTP2Handler(opts: CreateHTTP2HandlerOptions<AnyRouter>) {
120
+ return createHandler(opts);
121
+ }
@@ -136,6 +136,7 @@ export function getWSConnectionHandler<TRouter extends AnyRouter>(
136
136
  accept: null,
137
137
  type: 'unknown',
138
138
  signal: abortController.signal,
139
+ url: null,
139
140
  },
140
141
  });
141
142
 
@@ -8,6 +8,7 @@ import type { TRPCAcceptHeader, TRPCRequestInfo } from './types';
8
8
  type GetRequestInfoOptions = {
9
9
  path: string;
10
10
  req: Request;
11
+ url: URL | null;
11
12
  searchParams: URLSearchParams;
12
13
  headers: Headers;
13
14
  router: AnyRouter;
@@ -174,6 +175,7 @@ const jsonContentTypeHandler: ContentTypeHandler = {
174
175
  ? null
175
176
  : parseConnectionParamsFromString(connectionParamsStr),
176
177
  signal: req.signal,
178
+ url: opts.url,
177
179
  };
178
180
  return info;
179
181
  },
@@ -210,6 +212,7 @@ const formDataContentTypeHandler: ContentTypeHandler = {
210
212
  type: 'mutation',
211
213
  connectionParams: null,
212
214
  signal: req.signal,
215
+ url: opts.url,
213
216
  };
214
217
  },
215
218
  };
@@ -246,6 +249,7 @@ const octetStreamContentTypeHandler: ContentTypeHandler = {
246
249
  type: 'mutation',
247
250
  connectionParams: null,
248
251
  signal: req.signal,
252
+ url: opts.url,
249
253
  };
250
254
  },
251
255
  };
@@ -233,6 +233,7 @@ export async function resolveResponse<TRouter extends AnyRouter>(
233
233
  router,
234
234
  searchParams: url.searchParams,
235
235
  headers: opts.req.headers,
236
+ url,
236
237
  }),
237
238
  ];
238
239
  } catch (cause) {
@@ -104,6 +104,10 @@ export interface TRPCRequestInfo {
104
104
  * Can be used to abort async operations during the request, e.g. `fetch()`-requests
105
105
  */
106
106
  signal: AbortSignal;
107
+ /**
108
+ * The URL of the request if available
109
+ */
110
+ url: URL | null;
107
111
  }
108
112
 
109
113
  /**