@trpc/server 11.0.0-rc.740 → 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.
@@ -62,11 +62,15 @@ export type NodeHTTPHandlerOptions<TRouter extends AnyRouter, TRequest extends N
62
62
  middleware?: ConnectMiddleware<TRequest, TResponse>;
63
63
  maxBodySize?: number;
64
64
  };
65
- 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> & {
66
66
  req: TRequest;
67
67
  res: TResponse;
68
+ /**
69
+ * The tRPC path to handle requests for
70
+ * @example 'post.all'
71
+ */
68
72
  path: string;
69
- } & NodeHTTPHandlerOptions<TRouter, TRequest, TResponse>;
73
+ };
70
74
  export type NodeHTTPCreateContextFnOptions<TRequest, TResponse> = {
71
75
  req: TRequest;
72
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;AAClC,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,CAAC;AAEpC,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,EACV,gBAAgB,EAChB,YAAY,EACb,MAAM,mCAAmC,CAAC;AAE3C,MAAM,MAAM,eAAe,GAAG,gBAAgB,CAC5C,IAAI,CAAC,eAAe,GAAG,KAAK,CAAC,kBAAkB,EAC/C,QAAQ,CACT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M,CAAC;CACtB,CAAC;AAEJ,MAAM,MAAM,6BAA6B,CACvC,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,eAAe,EAChC,SAAS,SAAS,gBAAgB,IAChC,sBAAsB,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,GAAG;IACzD,GAAG,EAAE,QAAQ,CAAC;IACd,GAAG,EAAE,SAAS,CAAC;IACf;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,8BAA8B,CAAC,QAAQ,EAAE,SAAS,IAAI;IAChE,GAAG,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"}
@@ -10,15 +10,27 @@
10
10
  import http from 'http';
11
11
  import type * as http2 from 'http2';
12
12
  import { type AnyRouter } from '../@trpc/server';
13
- import type { NodeHTTPCreateContextFnOptions, NodeHTTPHandlerOptions } from './node-http';
14
- 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>;
15
26
  export type CreateHTTPContextOptions = NodeHTTPCreateContextFnOptions<http.IncomingMessage, http.ServerResponse>;
16
27
  /**
17
28
  * @internal
18
29
  */
19
30
  export declare function createHTTPHandler<TRouter extends AnyRouter>(opts: CreateHTTPHandlerOptions<TRouter>): http.RequestListener;
20
31
  export declare function createHTTPServer<TRouter extends AnyRouter>(opts: CreateHTTPHandlerOptions<TRouter>): http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
21
- export type CreateHTTP2HandlerOptions<TRouter extends AnyRouter> = NodeHTTPHandlerOptions<TRouter, http2.Http2ServerRequest, http2.Http2ServerResponse>;
32
+ export type CreateHTTP2HandlerOptions<TRouter extends AnyRouter> = StandaloneHandlerOptions<TRouter, http2.Http2ServerRequest, http2.Http2ServerResponse>;
22
33
  export type CreateHTTP2ContextOptions = NodeHTTPCreateContextFnOptions<http2.Http2ServerRequest, http2.Http2ServerResponse>;
23
34
  export declare function createHTTP2Handler(opts: CreateHTTP2HandlerOptions<AnyRouter>): (req: http2.Http2ServerRequest, res: http2.Http2ServerResponse<http2.Http2ServerRequest>) => void;
35
+ export {};
24
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,KAAK,KAAK,KAAK,MAAM,OAAO,CAAC;AAEpC,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAGjD,OAAO,KAAK,EACV,8BAA8B,EAC9B,sBAAsB,EAGvB,MAAM,aAAa,CAAC;AAQrB,MAAM,MAAM,wBAAwB,CAAC,OAAO,SAAS,SAAS,IAC5D,sBAAsB,CAAC,OAAO,EA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GAAG;IACzD;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAGF,MAAM,MAAM,wBAAwB,CAAC,OAAO,SAAS,SAAS,IAC5D,wBAAwB,CAAC,OAAO,EAAE,IAAI,CAAC,eAAe,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;AAE/E,MAAM,MAAM,wBAAwB,GAAG,8BAA8B,CACnE,IAAI,CAAC,eAAe,EACpB,IAAI,CAAC,cAAc,CACpB,CAAC;AAsCF;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,SAAS,SAAS,EACzD,IAAI,EAAE,wBAAwB,CAAC,OAAO,CAAC,GACtC,IAAI,CAAC,eAAe,CAEtB;AAED,wBAAgB,gBAAgB,CAAC,OAAO,SAAS,SAAS,EACxD,IAAI,EAAE,wBAAwB,CAAC,OAAO,CAAC,wEAGxC;AAGD,MAAM,MAAM,yBAAyB,CAAC,OAAO,SAAS,SAAS,IAC7D,wBAAwB,CACtB,OAAO,EACP,KAAK,CAAC,kBAAkB,EACxB,KAAK,CAAC,mBAAmB,CAC1B,CAAC;AAEJ,MAAM,MAAM,yBAAyB,GAAG,8BAA8B,CACpE,KAAK,CAAC,kBAAkB,EACxB,KAAK,CAAC,mBAAmB,CAC1B,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,yBAAyB,CAAC,SAAS,CAAC,gGA1DvC,IAAI,CA4DzC"}
@@ -9,13 +9,14 @@ var nodeHTTPRequestHandler = require('./node-http/nodeHTTPRequestHandler.js');
9
9
  var incomingMessageToRequest = require('./node-http/incomingMessageToRequest.js');
10
10
 
11
11
  function createHandler(opts) {
12
+ const basePath = opts.basePath ?? '/';
13
+ const sliceLength = basePath.length;
12
14
  return (req, res)=>{
13
15
  let path = '';
14
16
  utils.run(async ()=>{
15
17
  const url = incomingMessageToRequest.createURL(req);
16
- // get procedure path and remove the leading slash
17
- // /procedure -> procedure
18
- path = url.pathname.slice(1);
18
+ // get procedure(s) path and remove the leading slash
19
+ path = url.pathname.slice(sliceLength);
19
20
  await nodeHTTPRequestHandler.nodeHTTPRequestHandler({
20
21
  ...opts,
21
22
  req,
@@ -7,13 +7,14 @@ import { nodeHTTPRequestHandler, internal_exceptionHandler } from './node-http/n
7
7
  import { createURL } from './node-http/incomingMessageToRequest.mjs';
8
8
 
9
9
  function createHandler(opts) {
10
+ const basePath = opts.basePath ?? '/';
11
+ const sliceLength = basePath.length;
10
12
  return (req, res)=>{
11
13
  let path = '';
12
14
  run(async ()=>{
13
15
  const url = createURL(req);
14
- // get procedure path and remove the leading slash
15
- // /procedure -> procedure
16
- path = url.pathname.slice(1);
16
+ // get procedure(s) path and remove the leading slash
17
+ path = url.pathname.slice(sliceLength);
17
18
  await nodeHTTPRequestHandler({
18
19
  ...opts,
19
20
  req,
@@ -1,7 +1,7 @@
1
1
  {
2
- "bundleSize": 194829,
3
- "bundleOrigSize": 225251,
4
- "bundleReduction": 13.51,
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",
@@ -14,7 +14,7 @@
14
14
  "dependents": [
15
15
  "/src/unstable-core-do-not-import.ts"
16
16
  ],
17
- "percent": 10.8,
17
+ "percent": 10.79,
18
18
  "reduction": 0
19
19
  },
20
20
  {
@@ -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.99,
109
+ "percent": 3.98,
110
110
  "reduction": 0
111
111
  },
112
112
  {
@@ -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,11 +351,11 @@
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",
@@ -632,8 +632,8 @@
632
632
  },
633
633
  {
634
634
  "id": "/src/adapters/standalone.ts",
635
- "size": 900,
636
- "origSize": 2580,
635
+ "size": 958,
636
+ "origSize": 3103,
637
637
  "renderedExports": [
638
638
  "createHTTPHandler",
639
639
  "createHTTPServer",
@@ -641,8 +641,8 @@
641
641
  ],
642
642
  "removedExports": [],
643
643
  "dependents": [],
644
- "percent": 0.46,
645
- "reduction": 65.12
644
+ "percent": 0.49,
645
+ "reduction": 69.13
646
646
  },
647
647
  {
648
648
  "id": "/src/adapters/express.ts",
@@ -865,9 +865,9 @@
865
865
  "reduction": 100
866
866
  },
867
867
  {
868
- "id": "/src/rpc.ts",
868
+ "id": "/src/index.ts",
869
869
  "size": 0,
870
- "origSize": 36,
870
+ "origSize": 32,
871
871
  "renderedExports": [],
872
872
  "removedExports": [],
873
873
  "dependents": [],
@@ -875,9 +875,9 @@
875
875
  "reduction": 100
876
876
  },
877
877
  {
878
- "id": "/src/index.ts",
878
+ "id": "/src/shared.ts",
879
879
  "size": 0,
880
- "origSize": 32,
880
+ "origSize": 653,
881
881
  "renderedExports": [],
882
882
  "removedExports": [],
883
883
  "dependents": [],
@@ -885,9 +885,9 @@
885
885
  "reduction": 100
886
886
  },
887
887
  {
888
- "id": "/src/shared.ts",
888
+ "id": "/src/rpc.ts",
889
889
  "size": 0,
890
- "origSize": 653,
890
+ "origSize": 36,
891
891
  "renderedExports": [],
892
892
  "removedExports": [],
893
893
  "dependents": [],
@@ -902,9 +902,9 @@
902
902
  "removedExports": [],
903
903
  "dependents": [
904
904
  "/src/adapters/express.ts",
905
+ "/src/adapters/ws.ts",
905
906
  "/src/adapters/standalone.ts",
906
907
  "/src/adapters/next.ts",
907
- "/src/adapters/ws.ts",
908
908
  "/src/adapters/node-http/nodeHTTPRequestHandler.ts",
909
909
  "/src/adapters/next-app-dir/nextAppDirCaller.ts",
910
910
  "/src/adapters/node-http/writeResponse.ts"
@@ -935,9 +935,9 @@
935
935
  "reduction": 100
936
936
  },
937
937
  {
938
- "id": "/src/adapters/fastify/index.ts",
938
+ "id": "/src/adapters/fetch/index.ts",
939
939
  "size": 0,
940
- "origSize": 78,
940
+ "origSize": 64,
941
941
  "renderedExports": [],
942
942
  "removedExports": [],
943
943
  "dependents": [],
@@ -945,9 +945,9 @@
945
945
  "reduction": 100
946
946
  },
947
947
  {
948
- "id": "/src/adapters/fetch/index.ts",
948
+ "id": "/src/adapters/fastify/index.ts",
949
949
  "size": 0,
950
- "origSize": 64,
950
+ "origSize": 78,
951
951
  "renderedExports": [],
952
952
  "removedExports": [],
953
953
  "dependents": [],
@@ -962,9 +962,9 @@
962
962
  "removedExports": [],
963
963
  "dependents": [
964
964
  "/src/adapters/express.ts",
965
+ "/src/adapters/ws.ts",
965
966
  "/src/adapters/standalone.ts",
966
967
  "/src/adapters/next.ts",
967
- "/src/adapters/ws.ts",
968
968
  "/src/adapters/fastify/fastifyRequestHandler.ts"
969
969
  ],
970
970
  "percent": 0,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/server",
3
- "version": "11.0.0-rc.740+df313f4ad",
3
+ "version": "11.0.0-rc.741+caed91ee7",
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": "df313f4ade37202545103974aeeb4975e9c032cb"
155
+ "gitHead": "caed91ee782f78ada6c8c0c82e2d9d2ff474f555"
156
156
  }
@@ -108,11 +108,15 @@ export type NodeHTTPRequestHandlerOptions<
108
108
  TRouter extends AnyRouter,
109
109
  TRequest extends NodeHTTPRequest,
110
110
  TResponse extends NodeHTTPResponse,
111
- > = {
111
+ > = NodeHTTPHandlerOptions<TRouter, TRequest, TResponse> & {
112
112
  req: TRequest;
113
113
  res: TResponse;
114
+ /**
115
+ * The tRPC path to handle requests for
116
+ * @example 'post.all'
117
+ */
114
118
  path: string;
115
- } & NodeHTTPHandlerOptions<TRouter, TRequest, TResponse>;
119
+ };
116
120
 
117
121
  export type NodeHTTPCreateContextFnOptions<TRequest, TResponse> = {
118
122
  req: TRequest;
@@ -27,9 +27,25 @@ import {
27
27
  nodeHTTPRequestHandler,
28
28
  } from './node-http';
29
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
+
30
46
  // --- http1 ---
31
47
  export type CreateHTTPHandlerOptions<TRouter extends AnyRouter> =
32
- NodeHTTPHandlerOptions<TRouter, http.IncomingMessage, http.ServerResponse>;
48
+ StandaloneHandlerOptions<TRouter, http.IncomingMessage, http.ServerResponse>;
33
49
 
34
50
  export type CreateHTTPContextOptions = NodeHTTPCreateContextFnOptions<
35
51
  http.IncomingMessage,
@@ -41,16 +57,19 @@ function createHandler<
41
57
  TRequest extends NodeHTTPRequest,
42
58
  TResponse extends NodeHTTPResponse,
43
59
  >(
44
- opts: NodeHTTPHandlerOptions<TRouter, TRequest, TResponse>,
60
+ opts: StandaloneHandlerOptions<TRouter, TRequest, TResponse>,
45
61
  ): (req: TRequest, res: TResponse) => void {
62
+ const basePath = opts.basePath ?? '/';
63
+ const sliceLength = basePath.length;
64
+
46
65
  return (req, res) => {
47
66
  let path = '';
67
+
48
68
  run(async () => {
49
69
  const url = createURL(req);
50
70
 
51
- // get procedure path and remove the leading slash
52
- // /procedure -> procedure
53
- path = url.pathname.slice(1);
71
+ // get procedure(s) path and remove the leading slash
72
+ path = url.pathname.slice(sliceLength);
54
73
 
55
74
  await nodeHTTPRequestHandler({
56
75
  ...(opts as any),
@@ -86,7 +105,7 @@ export function createHTTPServer<TRouter extends AnyRouter>(
86
105
 
87
106
  // --- http2 ---
88
107
  export type CreateHTTP2HandlerOptions<TRouter extends AnyRouter> =
89
- NodeHTTPHandlerOptions<
108
+ StandaloneHandlerOptions<
90
109
  TRouter,
91
110
  http2.Http2ServerRequest,
92
111
  http2.Http2ServerResponse