@trpc/server 10.21.1 → 10.21.3-alpha.1

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 (32) hide show
  1. package/dist/adapters/aws-lambda/index.js +1 -1
  2. package/dist/adapters/aws-lambda/index.mjs +1 -1
  3. package/dist/adapters/express.js +2 -2
  4. package/dist/adapters/express.mjs +2 -2
  5. package/dist/adapters/fastify/index.js +1 -1
  6. package/dist/adapters/fastify/index.mjs +1 -1
  7. package/dist/adapters/fetch/index.js +1 -1
  8. package/dist/adapters/fetch/index.mjs +1 -1
  9. package/dist/adapters/next.js +2 -2
  10. package/dist/adapters/next.mjs +2 -2
  11. package/dist/adapters/node-http/index.js +2 -2
  12. package/dist/adapters/node-http/index.mjs +2 -2
  13. package/dist/adapters/node-http/internals/getPostBody.d.ts +1 -0
  14. package/dist/adapters/node-http/internals/getPostBody.d.ts.map +1 -1
  15. package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
  16. package/dist/adapters/standalone.js +2 -2
  17. package/dist/adapters/standalone.mjs +2 -2
  18. package/dist/http/index.js +1 -1
  19. package/dist/http/index.mjs +1 -1
  20. package/dist/http/resolveHTTPResponse.d.ts +1 -0
  21. package/dist/http/resolveHTTPResponse.d.ts.map +1 -1
  22. package/dist/{nodeHTTPRequestHandler-2718f9d8.mjs → nodeHTTPRequestHandler-4f6f12f6.mjs} +6 -3
  23. package/dist/{nodeHTTPRequestHandler-b7fa74a0.js → nodeHTTPRequestHandler-8bbfaa5c.js} +6 -3
  24. package/dist/{nodeHTTPRequestHandler-64a40c7d.js → nodeHTTPRequestHandler-9d8156da.js} +4 -2
  25. package/dist/{resolveHTTPResponse-6c8965e4.mjs → resolveHTTPResponse-24febe05.mjs} +11 -7
  26. package/dist/{resolveHTTPResponse-1fb1d8c3.js → resolveHTTPResponse-a2e412ec.js} +11 -7
  27. package/dist/{resolveHTTPResponse-2a931446.js → resolveHTTPResponse-b413b925.js} +11 -7
  28. package/package.json +2 -2
  29. package/src/adapters/node-http/internals/getPostBody.test.ts +7 -5
  30. package/src/adapters/node-http/internals/getPostBody.ts +4 -2
  31. package/src/adapters/node-http/nodeHTTPRequestHandler.ts +1 -0
  32. package/src/http/resolveHTTPResponse.ts +15 -7
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var TRPCError = require('../../TRPCError-16b2e52d.js');
6
6
  require('../../config-e6e74385.js');
7
7
  require('../../codes-0a561c20.js');
8
- var resolveHTTPResponse = require('../../resolveHTTPResponse-1fb1d8c3.js');
8
+ var resolveHTTPResponse = require('../../resolveHTTPResponse-a2e412ec.js');
9
9
  require('../../index-4d2d31b6.js');
10
10
  require('../../transformTRPCResponse-8afb9a5c.js');
11
11
 
@@ -1,7 +1,7 @@
1
1
  import { T as TRPCError } from '../../TRPCError-2b10c8d2.mjs';
2
2
  import '../../config-f0387de5.mjs';
3
3
  import '../../codes-e5d244b6.mjs';
4
- import { r as resolveHTTPResponse } from '../../resolveHTTPResponse-6c8965e4.mjs';
4
+ import { r as resolveHTTPResponse } from '../../resolveHTTPResponse-24febe05.mjs';
5
5
  import '../../index-972002da.mjs';
6
6
  import '../../transformTRPCResponse-0ea8c0ca.mjs';
7
7
 
@@ -2,8 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var nodeHTTPRequestHandler = require('../nodeHTTPRequestHandler-b7fa74a0.js');
6
- require('../resolveHTTPResponse-1fb1d8c3.js');
5
+ var nodeHTTPRequestHandler = require('../nodeHTTPRequestHandler-8bbfaa5c.js');
6
+ require('../resolveHTTPResponse-a2e412ec.js');
7
7
  require('../config-e6e74385.js');
8
8
  require('../TRPCError-16b2e52d.js');
9
9
  require('../codes-0a561c20.js');
@@ -1,5 +1,5 @@
1
- import { n as nodeHTTPRequestHandler } from '../nodeHTTPRequestHandler-2718f9d8.mjs';
2
- import '../resolveHTTPResponse-6c8965e4.mjs';
1
+ import { n as nodeHTTPRequestHandler } from '../nodeHTTPRequestHandler-4f6f12f6.mjs';
2
+ import '../resolveHTTPResponse-24febe05.mjs';
3
3
  import '../config-f0387de5.mjs';
4
4
  import '../TRPCError-2b10c8d2.mjs';
5
5
  import '../codes-e5d244b6.mjs';
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var resolveHTTPResponse = require('../../resolveHTTPResponse-1fb1d8c3.js');
5
+ var resolveHTTPResponse = require('../../resolveHTTPResponse-a2e412ec.js');
6
6
  var adapters_ws = require('../ws.js');
7
7
  require('../../config-e6e74385.js');
8
8
  require('../../TRPCError-16b2e52d.js');
@@ -1,4 +1,4 @@
1
- import { r as resolveHTTPResponse } from '../../resolveHTTPResponse-6c8965e4.mjs';
1
+ import { r as resolveHTTPResponse } from '../../resolveHTTPResponse-24febe05.mjs';
2
2
  import { applyWSSHandler } from '../ws.mjs';
3
3
  import '../../config-f0387de5.mjs';
4
4
  import '../../TRPCError-2b10c8d2.mjs';
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var resolveHTTPResponse = require('../../resolveHTTPResponse-1fb1d8c3.js');
5
+ var resolveHTTPResponse = require('../../resolveHTTPResponse-a2e412ec.js');
6
6
  require('../../config-e6e74385.js');
7
7
  require('../../TRPCError-16b2e52d.js');
8
8
  require('../../codes-0a561c20.js');
@@ -1,4 +1,4 @@
1
- import { r as resolveHTTPResponse } from '../../resolveHTTPResponse-6c8965e4.mjs';
1
+ import { r as resolveHTTPResponse } from '../../resolveHTTPResponse-24febe05.mjs';
2
2
  import '../../config-f0387de5.mjs';
3
3
  import '../../TRPCError-2b10c8d2.mjs';
4
4
  import '../../codes-e5d244b6.mjs';
@@ -3,8 +3,8 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var TRPCError = require('../TRPCError-16b2e52d.js');
6
- var nodeHTTPRequestHandler = require('../nodeHTTPRequestHandler-b7fa74a0.js');
7
- require('../resolveHTTPResponse-1fb1d8c3.js');
6
+ var nodeHTTPRequestHandler = require('../nodeHTTPRequestHandler-8bbfaa5c.js');
7
+ require('../resolveHTTPResponse-a2e412ec.js');
8
8
  require('../config-e6e74385.js');
9
9
  require('../codes-0a561c20.js');
10
10
  require('../index-4d2d31b6.js');
@@ -1,6 +1,6 @@
1
1
  import { T as TRPCError } from '../TRPCError-2b10c8d2.mjs';
2
- import { n as nodeHTTPRequestHandler } from '../nodeHTTPRequestHandler-2718f9d8.mjs';
3
- import '../resolveHTTPResponse-6c8965e4.mjs';
2
+ import { n as nodeHTTPRequestHandler } from '../nodeHTTPRequestHandler-4f6f12f6.mjs';
3
+ import '../resolveHTTPResponse-24febe05.mjs';
4
4
  import '../config-f0387de5.mjs';
5
5
  import '../codes-e5d244b6.mjs';
6
6
  import '../index-972002da.mjs';
@@ -2,8 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var nodeHTTPRequestHandler = require('../../nodeHTTPRequestHandler-b7fa74a0.js');
6
- require('../../resolveHTTPResponse-1fb1d8c3.js');
5
+ var nodeHTTPRequestHandler = require('../../nodeHTTPRequestHandler-8bbfaa5c.js');
6
+ require('../../resolveHTTPResponse-a2e412ec.js');
7
7
  require('../../config-e6e74385.js');
8
8
  require('../../TRPCError-16b2e52d.js');
9
9
  require('../../codes-0a561c20.js');
@@ -1,5 +1,5 @@
1
- export { n as nodeHTTPRequestHandler } from '../../nodeHTTPRequestHandler-2718f9d8.mjs';
2
- import '../../resolveHTTPResponse-6c8965e4.mjs';
1
+ export { n as nodeHTTPRequestHandler } from '../../nodeHTTPRequestHandler-4f6f12f6.mjs';
2
+ import '../../resolveHTTPResponse-24febe05.mjs';
3
3
  import '../../config-f0387de5.mjs';
4
4
  import '../../TRPCError-2b10c8d2.mjs';
5
5
  import '../../codes-e5d244b6.mjs';
@@ -6,6 +6,7 @@ export declare function getPostBody(opts: {
6
6
  }): Promise<{
7
7
  ok: true;
8
8
  data: unknown;
9
+ preprocessed: boolean;
9
10
  } | {
10
11
  ok: false;
11
12
  error: TRPCError;
@@ -1 +1 @@
1
- {"version":3,"file":"getPostBody.d.ts","sourceRoot":"","sources":["../../../../src/adapters/node-http/internals/getPostBody.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE3C,wBAAsB,WAAW,CAAC,IAAI,EAAE;IACtC,GAAG,EAAE,eAAe,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;QAGS,IAAI;UAAQ,OAAO;;QAAW,KAAK;WAAS,SAAS;GA0B9D"}
1
+ {"version":3,"file":"getPostBody.d.ts","sourceRoot":"","sources":["../../../../src/adapters/node-http/internals/getPostBody.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE3C,wBAAsB,WAAW,CAAC,IAAI,EAAE;IACtC,GAAG,EAAE,eAAe,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;QAGW,IAAI;UAAQ,OAAO;kBAAgB,OAAO;;QAC1C,KAAK;WAAS,SAAS;GA2BlC"}
@@ -1 +1 @@
1
- {"version":3,"file":"nodeHTTPRequestHandler.d.ts","sourceRoot":"","sources":["../../../src/adapters/node-http/nodeHTTPRequestHandler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAKvC,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAEjB,aAAK,6BAA6B,CAChC,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,eAAe,EAChC,SAAS,SAAS,gBAAgB,IAChC;IACF,GAAG,EAAE,QAAQ,CAAC;IACd,GAAG,EAAE,SAAS,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd,GAAG,sBAAsB,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;AAEzD,wBAAsB,sBAAsB,CAC1C,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,eAAe,EAChC,SAAS,SAAS,gBAAgB,EAClC,IAAI,EAAE,6BAA6B,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,iBAqElE"}
1
+ {"version":3,"file":"nodeHTTPRequestHandler.d.ts","sourceRoot":"","sources":["../../../src/adapters/node-http/nodeHTTPRequestHandler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAKvC,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAEjB,aAAK,6BAA6B,CAChC,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,eAAe,EAChC,SAAS,SAAS,gBAAgB,IAChC;IACF,GAAG,EAAE,QAAQ,CAAC;IACd,GAAG,EAAE,SAAS,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd,GAAG,sBAAsB,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;AAEzD,wBAAsB,sBAAsB,CAC1C,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,eAAe,EAChC,SAAS,SAAS,gBAAgB,EAClC,IAAI,EAAE,6BAA6B,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,iBAsElE"}
@@ -3,8 +3,8 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var http = require('node:http');
6
- var nodeHTTPRequestHandler = require('../nodeHTTPRequestHandler-b7fa74a0.js');
7
- require('../resolveHTTPResponse-1fb1d8c3.js');
6
+ var nodeHTTPRequestHandler = require('../nodeHTTPRequestHandler-8bbfaa5c.js');
7
+ require('../resolveHTTPResponse-a2e412ec.js');
8
8
  require('../config-e6e74385.js');
9
9
  require('../TRPCError-16b2e52d.js');
10
10
  require('../codes-0a561c20.js');
@@ -1,6 +1,6 @@
1
1
  import http from 'node:http';
2
- import { n as nodeHTTPRequestHandler } from '../nodeHTTPRequestHandler-2718f9d8.mjs';
3
- import '../resolveHTTPResponse-6c8965e4.mjs';
2
+ import { n as nodeHTTPRequestHandler } from '../nodeHTTPRequestHandler-4f6f12f6.mjs';
3
+ import '../resolveHTTPResponse-24febe05.mjs';
4
4
  import '../config-f0387de5.mjs';
5
5
  import '../TRPCError-2b10c8d2.mjs';
6
6
  import '../codes-e5d244b6.mjs';
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var config = require('../config-e6e74385.js');
6
- var resolveHTTPResponse = require('../resolveHTTPResponse-1fb1d8c3.js');
6
+ var resolveHTTPResponse = require('../resolveHTTPResponse-a2e412ec.js');
7
7
  require('../TRPCError-16b2e52d.js');
8
8
  require('../codes-0a561c20.js');
9
9
  require('../index-4d2d31b6.js');
@@ -1,5 +1,5 @@
1
1
  export { T as TRPC_ERROR_CODES_BY_NUMBER, f as getHTTPStatusCode, g as getHTTPStatusCodeFromError } from '../config-f0387de5.mjs';
2
- export { r as resolveHTTPResponse } from '../resolveHTTPResponse-6c8965e4.mjs';
2
+ export { r as resolveHTTPResponse } from '../resolveHTTPResponse-24febe05.mjs';
3
3
  import '../TRPCError-2b10c8d2.mjs';
4
4
  import '../codes-e5d244b6.mjs';
5
5
  import '../index-972002da.mjs';
@@ -8,6 +8,7 @@ interface ResolveHTTPRequestOptions<TRouter extends AnyRouter, TRequest extends
8
8
  req: TRequest;
9
9
  path: string;
10
10
  error?: Maybe<TRPCError>;
11
+ preprocessedBody?: boolean;
11
12
  }
12
13
  export declare function resolveHTTPResponse<TRouter extends AnyRouter, TRequest extends HTTPRequest>(opts: ResolveHTTPRequestOptions<TRouter, TRequest>): Promise<HTTPResponse>;
13
14
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"resolveHTTPResponse.d.ts","sourceRoot":"","sources":["../../src/http/resolveHTTPResponse.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,EAGT,kBAAkB,EAEnB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,SAAS,EAA2B,MAAM,oBAAoB,CAAC;AAIxE,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjC,OAAO,EAAe,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AA+B9D,UAAU,yBAAyB,CACjC,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,WAAW,CAC5B,SAAQ,sBAAsB,CAAC,OAAO,EAAE,QAAQ,CAAC;IACjD,aAAa,EAAE,MAAM,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC;IAC1D,GAAG,EAAE,QAAQ,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;CAC1B;AAED,wBAAsB,mBAAmB,CACvC,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,WAAW,EAC5B,IAAI,EAAE,yBAAyB,CAAC,OAAO,EAAE,QAAQ,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,CAyM3E"}
1
+ {"version":3,"file":"resolveHTTPResponse.d.ts","sourceRoot":"","sources":["../../src/http/resolveHTTPResponse.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,EAGT,kBAAkB,EAEnB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,SAAS,EAA2B,MAAM,oBAAoB,CAAC;AAIxE,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjC,OAAO,EAAe,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAmC9D,UAAU,yBAAyB,CACjC,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,WAAW,CAC5B,SAAQ,sBAAsB,CAAC,OAAO,EAAE,QAAQ,CAAC;IACjD,aAAa,EAAE,MAAM,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC;IAC1D,GAAG,EAAE,QAAQ,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;IACzB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,wBAAsB,mBAAmB,CACvC,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,WAAW,EAC5B,IAAI,EAAE,yBAAyB,CAAC,OAAO,EAAE,QAAQ,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,CA4M3E"}
@@ -1,4 +1,4 @@
1
- import { r as resolveHTTPResponse } from './resolveHTTPResponse-6c8965e4.mjs';
1
+ import { r as resolveHTTPResponse } from './resolveHTTPResponse-24febe05.mjs';
2
2
  import { T as TRPCError } from './TRPCError-2b10c8d2.mjs';
3
3
 
4
4
  async function getPostBody(opts) {
@@ -7,7 +7,8 @@ async function getPostBody(opts) {
7
7
  if ('body' in req) {
8
8
  resolve({
9
9
  ok: true,
10
- data: req.body
10
+ data: req.body,
11
+ preprocessed: true
11
12
  });
12
13
  return;
13
14
  }
@@ -29,7 +30,8 @@ async function getPostBody(opts) {
29
30
  req.on('end', ()=>{
30
31
  resolve({
31
32
  ok: true,
32
- data: hasBody ? body : undefined
33
+ data: hasBody ? body : undefined,
34
+ preprocessed: false
33
35
  });
34
36
  });
35
37
  });
@@ -66,6 +68,7 @@ async function nodeHTTPRequestHandler(opts) {
66
68
  router: opts.router,
67
69
  req,
68
70
  error: bodyResult.ok ? null : bodyResult.error,
71
+ preprocessedBody: bodyResult.ok ? bodyResult.preprocessed : false,
69
72
  onError (o) {
70
73
  opts?.onError?.({
71
74
  ...o,
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var resolveHTTPResponse = require('./resolveHTTPResponse-1fb1d8c3.js');
3
+ var resolveHTTPResponse = require('./resolveHTTPResponse-a2e412ec.js');
4
4
  var TRPCError = require('./TRPCError-16b2e52d.js');
5
5
 
6
6
  async function getPostBody(opts) {
@@ -9,7 +9,8 @@ async function getPostBody(opts) {
9
9
  if ('body' in req) {
10
10
  resolve({
11
11
  ok: true,
12
- data: req.body
12
+ data: req.body,
13
+ preprocessed: true
13
14
  });
14
15
  return;
15
16
  }
@@ -31,7 +32,8 @@ async function getPostBody(opts) {
31
32
  req.on('end', ()=>{
32
33
  resolve({
33
34
  ok: true,
34
- data: hasBody ? body : undefined
35
+ data: hasBody ? body : undefined,
36
+ preprocessed: false
35
37
  });
36
38
  });
37
39
  });
@@ -68,6 +70,7 @@ async function nodeHTTPRequestHandler(opts) {
68
70
  router: opts.router,
69
71
  req,
70
72
  error: bodyResult.ok ? null : bodyResult.error,
73
+ preprocessedBody: bodyResult.ok ? bodyResult.preprocessed : false,
71
74
  onError (o) {
72
75
  opts?.onError?.({
73
76
  ...o,
@@ -1,11 +1,11 @@
1
- import { r as resolveHTTPResponse } from './resolveHTTPResponse-2a931446.js';
1
+ import { r as resolveHTTPResponse } from './resolveHTTPResponse-b413b925.js';
2
2
  import { T as TRPCError } from './TRPCError-61026c9a.js';
3
3
 
4
4
  async function getPostBody(opts) {
5
5
  const { req, maxBodySize = Infinity } = opts;
6
6
  return new Promise((resolve) => {
7
7
  if ('body' in req) {
8
- resolve({ ok: true, data: req.body });
8
+ resolve({ ok: true, data: req.body, preprocessed: true });
9
9
  return;
10
10
  }
11
11
  let body = '';
@@ -25,6 +25,7 @@ async function getPostBody(opts) {
25
25
  resolve({
26
26
  ok: true,
27
27
  data: hasBody ? body : undefined,
28
+ preprocessed: false,
28
29
  });
29
30
  });
30
31
  });
@@ -64,6 +65,7 @@ async function nodeHTTPRequestHandler(opts) {
64
65
  router: opts.router,
65
66
  req,
66
67
  error: bodyResult.ok ? null : bodyResult.error,
68
+ preprocessedBody: bodyResult.ok ? bodyResult.preprocessed : false,
67
69
  onError(o) {
68
70
  opts?.onError?.({
69
71
  ...o,
@@ -6,7 +6,8 @@ const HTTP_METHOD_PROCEDURE_TYPE_MAP = {
6
6
  GET: 'query',
7
7
  POST: 'mutation'
8
8
  };
9
- function getRawProcedureInputOrThrow(req) {
9
+ function getRawProcedureInputOrThrow(opts) {
10
+ const { req } = opts;
10
11
  try {
11
12
  if (req.method === 'GET') {
12
13
  if (!req.query.has('input')) {
@@ -15,7 +16,7 @@ function getRawProcedureInputOrThrow(req) {
15
16
  const raw = req.query.get('input');
16
17
  return JSON.parse(raw);
17
18
  }
18
- if (typeof req.body === 'string') {
19
+ if (!opts.preprocessed && typeof req.body === 'string') {
19
20
  // A mutation with no inputs will have req.body === ''
20
21
  return req.body.length === 0 ? undefined : JSON.parse(req.body);
21
22
  }
@@ -28,7 +29,7 @@ function getRawProcedureInputOrThrow(req) {
28
29
  }
29
30
  }
30
31
  async function resolveHTTPResponse(opts) {
31
- const { createContext , onError , router , req } = opts;
32
+ const { router , req } = opts;
32
33
  const batchingEnabled = opts.batching?.enabled ?? true;
33
34
  if (req.method === 'HEAD') {
34
35
  // can be used for lambda warmup
@@ -87,11 +88,14 @@ async function resolveHTTPResponse(opts) {
87
88
  code: 'METHOD_NOT_SUPPORTED'
88
89
  });
89
90
  }
90
- const rawInput = getRawProcedureInputOrThrow(req);
91
+ const rawInput = getRawProcedureInputOrThrow({
92
+ req,
93
+ preprocessed: opts.preprocessedBody
94
+ });
91
95
  paths = isBatchCall ? opts.path.split(',') : [
92
96
  opts.path
93
97
  ];
94
- ctx = await createContext();
98
+ ctx = await opts.createContext();
95
99
  const deserializeInputValue = (rawValue)=>{
96
100
  return typeof rawValue !== 'undefined' ? router._def._config.transformer.input.deserialize(rawValue) : rawValue;
97
101
  };
@@ -134,7 +138,7 @@ async function resolveHTTPResponse(opts) {
134
138
  };
135
139
  } catch (cause) {
136
140
  const error = getTRPCErrorFromUnknown(cause);
137
- onError?.({
141
+ opts.onError?.({
138
142
  error,
139
143
  path,
140
144
  input,
@@ -182,7 +186,7 @@ async function resolveHTTPResponse(opts) {
182
186
  // - input deserialization fails
183
187
  // - `errorFormatter` return value is malformed
184
188
  const error = getTRPCErrorFromUnknown(cause);
185
- onError?.({
189
+ opts.onError?.({
186
190
  error,
187
191
  path: undefined,
188
192
  input: undefined,
@@ -8,7 +8,8 @@ const HTTP_METHOD_PROCEDURE_TYPE_MAP = {
8
8
  GET: 'query',
9
9
  POST: 'mutation'
10
10
  };
11
- function getRawProcedureInputOrThrow(req) {
11
+ function getRawProcedureInputOrThrow(opts) {
12
+ const { req } = opts;
12
13
  try {
13
14
  if (req.method === 'GET') {
14
15
  if (!req.query.has('input')) {
@@ -17,7 +18,7 @@ function getRawProcedureInputOrThrow(req) {
17
18
  const raw = req.query.get('input');
18
19
  return JSON.parse(raw);
19
20
  }
20
- if (typeof req.body === 'string') {
21
+ if (!opts.preprocessed && typeof req.body === 'string') {
21
22
  // A mutation with no inputs will have req.body === ''
22
23
  return req.body.length === 0 ? undefined : JSON.parse(req.body);
23
24
  }
@@ -30,7 +31,7 @@ function getRawProcedureInputOrThrow(req) {
30
31
  }
31
32
  }
32
33
  async function resolveHTTPResponse(opts) {
33
- const { createContext , onError , router , req } = opts;
34
+ const { router , req } = opts;
34
35
  const batchingEnabled = opts.batching?.enabled ?? true;
35
36
  if (req.method === 'HEAD') {
36
37
  // can be used for lambda warmup
@@ -89,11 +90,14 @@ async function resolveHTTPResponse(opts) {
89
90
  code: 'METHOD_NOT_SUPPORTED'
90
91
  });
91
92
  }
92
- const rawInput = getRawProcedureInputOrThrow(req);
93
+ const rawInput = getRawProcedureInputOrThrow({
94
+ req,
95
+ preprocessed: opts.preprocessedBody
96
+ });
93
97
  paths = isBatchCall ? opts.path.split(',') : [
94
98
  opts.path
95
99
  ];
96
- ctx = await createContext();
100
+ ctx = await opts.createContext();
97
101
  const deserializeInputValue = (rawValue)=>{
98
102
  return typeof rawValue !== 'undefined' ? router._def._config.transformer.input.deserialize(rawValue) : rawValue;
99
103
  };
@@ -136,7 +140,7 @@ async function resolveHTTPResponse(opts) {
136
140
  };
137
141
  } catch (cause) {
138
142
  const error = TRPCError.getTRPCErrorFromUnknown(cause);
139
- onError?.({
143
+ opts.onError?.({
140
144
  error,
141
145
  path,
142
146
  input,
@@ -184,7 +188,7 @@ async function resolveHTTPResponse(opts) {
184
188
  // - input deserialization fails
185
189
  // - `errorFormatter` return value is malformed
186
190
  const error = TRPCError.getTRPCErrorFromUnknown(cause);
187
- onError?.({
191
+ opts.onError?.({
188
192
  error,
189
193
  path: undefined,
190
194
  input: undefined,
@@ -7,7 +7,8 @@ const HTTP_METHOD_PROCEDURE_TYPE_MAP = {
7
7
  GET: 'query',
8
8
  POST: 'mutation',
9
9
  };
10
- function getRawProcedureInputOrThrow(req) {
10
+ function getRawProcedureInputOrThrow(opts) {
11
+ const { req } = opts;
11
12
  try {
12
13
  if (req.method === 'GET') {
13
14
  if (!req.query.has('input')) {
@@ -16,7 +17,7 @@ function getRawProcedureInputOrThrow(req) {
16
17
  const raw = req.query.get('input');
17
18
  return JSON.parse(raw);
18
19
  }
19
- if (typeof req.body === 'string') {
20
+ if (!opts.preprocessed && typeof req.body === 'string') {
20
21
  // A mutation with no inputs will have req.body === ''
21
22
  return req.body.length === 0 ? undefined : JSON.parse(req.body);
22
23
  }
@@ -30,7 +31,7 @@ function getRawProcedureInputOrThrow(req) {
30
31
  }
31
32
  }
32
33
  async function resolveHTTPResponse(opts) {
33
- const { createContext, onError, router, req } = opts;
34
+ const { router, req } = opts;
34
35
  const batchingEnabled = opts.batching?.enabled ?? true;
35
36
  if (req.method === 'HEAD') {
36
37
  // can be used for lambda warmup
@@ -90,9 +91,12 @@ async function resolveHTTPResponse(opts) {
90
91
  code: 'METHOD_NOT_SUPPORTED',
91
92
  });
92
93
  }
93
- const rawInput = getRawProcedureInputOrThrow(req);
94
+ const rawInput = getRawProcedureInputOrThrow({
95
+ req,
96
+ preprocessed: opts.preprocessedBody,
97
+ });
94
98
  paths = isBatchCall ? opts.path.split(',') : [opts.path];
95
- ctx = await createContext();
99
+ ctx = await opts.createContext();
96
100
  const deserializeInputValue = (rawValue) => {
97
101
  return typeof rawValue !== 'undefined'
98
102
  ? router._def._config.transformer.input.deserialize(rawValue)
@@ -141,7 +145,7 @@ async function resolveHTTPResponse(opts) {
141
145
  }
142
146
  catch (cause) {
143
147
  const error = getTRPCErrorFromUnknown(cause);
144
- onError?.({ error, path, input, ctx, type: type, req });
148
+ opts.onError?.({ error, path, input, ctx, type: type, req });
145
149
  return {
146
150
  input,
147
151
  path,
@@ -182,7 +186,7 @@ async function resolveHTTPResponse(opts) {
182
186
  // - input deserialization fails
183
187
  // - `errorFormatter` return value is malformed
184
188
  const error = getTRPCErrorFromUnknown(cause);
185
- onError?.({
189
+ opts.onError?.({
186
190
  error,
187
191
  path: undefined,
188
192
  input: undefined,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/server",
3
- "version": "10.21.1",
3
+ "version": "10.21.3-alpha.1",
4
4
  "description": "tRPC Server",
5
5
  "author": "KATT",
6
6
  "license": "MIT",
@@ -157,5 +157,5 @@
157
157
  "yup": "^1.0.0",
158
158
  "zod": "^3.0.0"
159
159
  },
160
- "gitHead": "04fa9d04420e677f3a8e46d3868169321eb5dcc8"
160
+ "gitHead": "aa9b7d05d388ccfc046ed9985234cdf5b35124ef"
161
161
  }
@@ -8,6 +8,7 @@ test('has body', async () => {
8
8
  Object {
9
9
  "data": Object {},
10
10
  "ok": true,
11
+ "preprocessed": true,
11
12
  }
12
13
  `);
13
14
  });
@@ -28,9 +29,10 @@ test('req as eventemitter', async () => {
28
29
  expect(result.ok).toBeTruthy();
29
30
  expect((result as any).data).toBeTruthy();
30
31
  expect(result).toMatchInlineSnapshot(`
31
- Object {
32
- "data": "{\\"hello\\":\\"there\\"}",
33
- "ok": true,
34
- }
35
- `);
32
+ Object {
33
+ "data": "{\\"hello\\":\\"there\\"}",
34
+ "ok": true,
35
+ "preprocessed": false,
36
+ }
37
+ `);
36
38
  });
@@ -7,10 +7,11 @@ export async function getPostBody(opts: {
7
7
  }) {
8
8
  const { req, maxBodySize = Infinity } = opts;
9
9
  return new Promise<
10
- { ok: true; data: unknown } | { ok: false; error: TRPCError }
10
+ | { ok: true; data: unknown; preprocessed: boolean }
11
+ | { ok: false; error: TRPCError }
11
12
  >((resolve) => {
12
13
  if ('body' in req) {
13
- resolve({ ok: true, data: req.body });
14
+ resolve({ ok: true, data: req.body, preprocessed: true });
14
15
  return;
15
16
  }
16
17
  let body = '';
@@ -30,6 +31,7 @@ export async function getPostBody(opts: {
30
31
  resolve({
31
32
  ok: true,
32
33
  data: hasBody ? body : undefined,
34
+ preprocessed: false,
33
35
  });
34
36
  });
35
37
  });
@@ -67,6 +67,7 @@ export async function nodeHTTPRequestHandler<
67
67
  router: opts.router,
68
68
  req,
69
69
  error: bodyResult.ok ? null : bodyResult.error,
70
+ preprocessedBody: bodyResult.ok ? bodyResult.preprocessed : false,
70
71
  onError(o) {
71
72
  opts?.onError?.({
72
73
  ...o,
@@ -22,7 +22,11 @@ const HTTP_METHOD_PROCEDURE_TYPE_MAP: Record<
22
22
  GET: 'query',
23
23
  POST: 'mutation',
24
24
  };
25
- function getRawProcedureInputOrThrow(req: HTTPRequest) {
25
+ function getRawProcedureInputOrThrow(opts: {
26
+ req: HTTPRequest;
27
+ preprocessed?: boolean;
28
+ }) {
29
+ const { req } = opts;
26
30
  try {
27
31
  if (req.method === 'GET') {
28
32
  if (!req.query.has('input')) {
@@ -31,7 +35,7 @@ function getRawProcedureInputOrThrow(req: HTTPRequest) {
31
35
  const raw = req.query.get('input');
32
36
  return JSON.parse(raw!);
33
37
  }
34
- if (typeof req.body === 'string') {
38
+ if (!opts.preprocessed && typeof req.body === 'string') {
35
39
  // A mutation with no inputs will have req.body === ''
36
40
  return req.body.length === 0 ? undefined : JSON.parse(req.body);
37
41
  }
@@ -52,13 +56,14 @@ interface ResolveHTTPRequestOptions<
52
56
  req: TRequest;
53
57
  path: string;
54
58
  error?: Maybe<TRPCError>;
59
+ preprocessedBody?: boolean;
55
60
  }
56
61
 
57
62
  export async function resolveHTTPResponse<
58
63
  TRouter extends AnyRouter,
59
64
  TRequest extends HTTPRequest,
60
65
  >(opts: ResolveHTTPRequestOptions<TRouter, TRequest>): Promise<HTTPResponse> {
61
- const { createContext, onError, router, req } = opts;
66
+ const { router, req } = opts;
62
67
  const batchingEnabled = opts.batching?.enabled ?? true;
63
68
  if (req.method === 'HEAD') {
64
69
  // can be used for lambda warmup
@@ -133,10 +138,13 @@ export async function resolveHTTPResponse<
133
138
  code: 'METHOD_NOT_SUPPORTED',
134
139
  });
135
140
  }
136
- const rawInput = getRawProcedureInputOrThrow(req);
141
+ const rawInput = getRawProcedureInputOrThrow({
142
+ req,
143
+ preprocessed: opts.preprocessedBody,
144
+ });
137
145
 
138
146
  paths = isBatchCall ? opts.path.split(',') : [opts.path];
139
- ctx = await createContext();
147
+ ctx = await opts.createContext();
140
148
 
141
149
  const deserializeInputValue = (rawValue: unknown) => {
142
150
  return typeof rawValue !== 'undefined'
@@ -194,7 +202,7 @@ export async function resolveHTTPResponse<
194
202
  } catch (cause) {
195
203
  const error = getTRPCErrorFromUnknown(cause);
196
204
 
197
- onError?.({ error, path, input, ctx, type: type, req });
205
+ opts.onError?.({ error, path, input, ctx, type: type, req });
198
206
  return {
199
207
  input,
200
208
  path,
@@ -237,7 +245,7 @@ export async function resolveHTTPResponse<
237
245
  // - `errorFormatter` return value is malformed
238
246
  const error = getTRPCErrorFromUnknown(cause);
239
247
 
240
- onError?.({
248
+ opts.onError?.({
241
249
  error,
242
250
  path: undefined,
243
251
  input: undefined,