@trpc/server 11.0.0-rc.361 → 11.0.0-rc.363

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 (178) hide show
  1. package/dist/@trpc/server/http.d.ts +7 -5
  2. package/dist/@trpc/server/http.d.ts.map +1 -1
  3. package/dist/@trpc/server/index.d.ts +1 -2
  4. package/dist/@trpc/server/index.d.ts.map +1 -1
  5. package/dist/adapters/aws-lambda/getPlanner.d.ts +13 -0
  6. package/dist/adapters/aws-lambda/getPlanner.d.ts.map +1 -0
  7. package/dist/adapters/aws-lambda/getPlanner.js +143 -0
  8. package/dist/adapters/aws-lambda/getPlanner.mjs +141 -0
  9. package/dist/adapters/aws-lambda/index.d.ts +12 -9
  10. package/dist/adapters/aws-lambda/index.d.ts.map +1 -1
  11. package/dist/adapters/aws-lambda/index.js +8 -77
  12. package/dist/adapters/aws-lambda/index.mjs +9 -72
  13. package/dist/adapters/express.js +1 -0
  14. package/dist/adapters/express.mjs +1 -0
  15. package/dist/adapters/fastify/fastifyRequestHandler.d.ts +19 -2
  16. package/dist/adapters/fastify/fastifyRequestHandler.d.ts.map +1 -1
  17. package/dist/adapters/fastify/fastifyRequestHandler.js +22 -64
  18. package/dist/adapters/fastify/fastifyRequestHandler.mjs +22 -64
  19. package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts +1 -1
  20. package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts.map +1 -1
  21. package/dist/adapters/fastify/fastifyTRPCPlugin.js +1 -0
  22. package/dist/adapters/fastify/fastifyTRPCPlugin.mjs +1 -0
  23. package/dist/adapters/fetch/fetchRequestHandler.d.ts +2 -2
  24. package/dist/adapters/fetch/fetchRequestHandler.d.ts.map +1 -1
  25. package/dist/adapters/fetch/fetchRequestHandler.js +29 -86
  26. package/dist/adapters/fetch/fetchRequestHandler.mjs +29 -86
  27. package/dist/adapters/fetch/types.d.ts +2 -2
  28. package/dist/adapters/fetch/types.d.ts.map +1 -1
  29. package/dist/adapters/next.js +1 -1
  30. package/dist/adapters/next.mjs +1 -1
  31. package/dist/adapters/node-http/incomingMessageToRequest.d.ts +18 -0
  32. package/dist/adapters/node-http/incomingMessageToRequest.d.ts.map +1 -0
  33. package/dist/adapters/node-http/incomingMessageToRequest.js +71 -0
  34. package/dist/adapters/node-http/incomingMessageToRequest.mjs +69 -0
  35. package/dist/adapters/node-http/index.d.ts +1 -0
  36. package/dist/adapters/node-http/index.d.ts.map +1 -1
  37. package/dist/adapters/node-http/index.js +2 -0
  38. package/dist/adapters/node-http/index.mjs +1 -0
  39. package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts +1 -1
  40. package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
  41. package/dist/adapters/node-http/nodeHTTPRequestHandler.js +28 -71
  42. package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +28 -71
  43. package/dist/adapters/node-http/types.d.ts +7 -8
  44. package/dist/adapters/node-http/types.d.ts.map +1 -1
  45. package/dist/adapters/ws.js +1 -1
  46. package/dist/adapters/ws.mjs +1 -1
  47. package/dist/bundle-analysis.json +174 -271
  48. package/dist/http.js +4 -2
  49. package/dist/http.mjs +2 -1
  50. package/dist/index.js +2 -4
  51. package/dist/index.mjs +1 -2
  52. package/dist/unstable-core-do-not-import/http/contentType.d.ts +8 -20
  53. package/dist/unstable-core-do-not-import/http/contentType.d.ts.map +1 -1
  54. package/dist/unstable-core-do-not-import/http/contentType.js +180 -0
  55. package/dist/unstable-core-do-not-import/http/contentType.mjs +178 -0
  56. package/dist/unstable-core-do-not-import/http/contentTypeParsers.d.ts +14 -0
  57. package/dist/unstable-core-do-not-import/http/contentTypeParsers.d.ts.map +1 -0
  58. package/dist/unstable-core-do-not-import/http/contentTypeParsers.js +14 -0
  59. package/dist/unstable-core-do-not-import/http/contentTypeParsers.mjs +12 -0
  60. package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts +1 -1
  61. package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts.map +1 -1
  62. package/dist/unstable-core-do-not-import/http/resolveResponse.d.ts +15 -0
  63. package/dist/unstable-core-do-not-import/http/resolveResponse.d.ts.map +1 -0
  64. package/dist/unstable-core-do-not-import/http/{resolveHTTPResponse.js → resolveResponse.js} +119 -134
  65. package/dist/unstable-core-do-not-import/http/{resolveHTTPResponse.mjs → resolveResponse.mjs} +119 -134
  66. package/dist/unstable-core-do-not-import/http/types.d.ts +25 -27
  67. package/dist/unstable-core-do-not-import/http/types.d.ts.map +1 -1
  68. package/dist/unstable-core-do-not-import/initTRPC.d.ts +1 -1
  69. package/dist/unstable-core-do-not-import/procedureBuilder.d.ts +1 -3
  70. package/dist/unstable-core-do-not-import/procedureBuilder.d.ts.map +1 -1
  71. package/dist/unstable-core-do-not-import/procedureBuilder.js +0 -2
  72. package/dist/unstable-core-do-not-import/procedureBuilder.mjs +1 -2
  73. package/dist/unstable-core-do-not-import/rootConfig.d.ts +0 -9
  74. package/dist/unstable-core-do-not-import/rootConfig.d.ts.map +1 -1
  75. package/dist/unstable-core-do-not-import/utils.d.ts +3 -0
  76. package/dist/unstable-core-do-not-import/utils.d.ts.map +1 -1
  77. package/dist/unstable-core-do-not-import/utils.js +2 -0
  78. package/dist/unstable-core-do-not-import/utils.mjs +2 -1
  79. package/dist/unstable-core-do-not-import.d.ts +9 -3
  80. package/dist/unstable-core-do-not-import.d.ts.map +1 -1
  81. package/dist/unstable-core-do-not-import.js +12 -8
  82. package/dist/unstable-core-do-not-import.mjs +7 -5
  83. package/package.json +3 -13
  84. package/src/@trpc/server/http.ts +7 -12
  85. package/src/@trpc/server/index.ts +0 -3
  86. package/src/adapters/aws-lambda/getPlanner.ts +191 -0
  87. package/src/adapters/aws-lambda/index.ts +43 -107
  88. package/src/adapters/express.ts +1 -1
  89. package/src/adapters/fastify/fastifyRequestHandler.ts +43 -90
  90. package/src/adapters/fastify/fastifyTRPCPlugin.ts +4 -3
  91. package/src/adapters/fetch/fetchRequestHandler.ts +35 -111
  92. package/src/adapters/fetch/types.ts +4 -2
  93. package/src/adapters/next.ts +1 -1
  94. package/src/adapters/node-http/incomingMessageToRequest.ts +94 -0
  95. package/src/adapters/node-http/index.ts +1 -0
  96. package/src/adapters/node-http/nodeHTTPRequestHandler.ts +31 -97
  97. package/src/adapters/node-http/types.ts +27 -37
  98. package/src/adapters/standalone.ts +1 -1
  99. package/src/unstable-core-do-not-import/http/contentType.ts +214 -22
  100. package/src/unstable-core-do-not-import/http/contentTypeParsers.ts +29 -0
  101. package/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts +2 -2
  102. package/src/unstable-core-do-not-import/http/resolveResponse.ts +386 -0
  103. package/src/unstable-core-do-not-import/http/types.ts +25 -30
  104. package/src/unstable-core-do-not-import/procedureBuilder.ts +2 -4
  105. package/src/unstable-core-do-not-import/rootConfig.ts +0 -10
  106. package/src/unstable-core-do-not-import/utils.ts +4 -0
  107. package/src/unstable-core-do-not-import.ts +9 -3
  108. package/adapters/node-http/content-type/form-data/index.d.ts +0 -1
  109. package/adapters/node-http/content-type/form-data/index.js +0 -1
  110. package/adapters/node-http/content-type/json/index.d.ts +0 -1
  111. package/adapters/node-http/content-type/json/index.js +0 -1
  112. package/dist/adapters/aws-lambda/content-type/json/index.d.ts +0 -10
  113. package/dist/adapters/aws-lambda/content-type/json/index.d.ts.map +0 -1
  114. package/dist/adapters/aws-lambda/content-type/json/index.js +0 -62
  115. package/dist/adapters/aws-lambda/content-type/json/index.mjs +0 -60
  116. package/dist/adapters/aws-lambda/utils.d.ts +0 -31
  117. package/dist/adapters/aws-lambda/utils.d.ts.map +0 -1
  118. package/dist/adapters/aws-lambda/utils.js +0 -111
  119. package/dist/adapters/aws-lambda/utils.mjs +0 -103
  120. package/dist/adapters/content-handlers/concurrentCache.d.ts +0 -7
  121. package/dist/adapters/content-handlers/concurrentCache.d.ts.map +0 -1
  122. package/dist/adapters/content-handlers/concurrentCache.js +0 -17
  123. package/dist/adapters/content-handlers/concurrentCache.mjs +0 -15
  124. package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.d.ts +0 -10
  125. package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.d.ts.map +0 -1
  126. package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.js +0 -33
  127. package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.mjs +0 -31
  128. package/dist/adapters/fastify/content-type/json/index.d.ts +0 -8
  129. package/dist/adapters/fastify/content-type/json/index.d.ts.map +0 -1
  130. package/dist/adapters/fastify/content-type/json/index.js +0 -62
  131. package/dist/adapters/fastify/content-type/json/index.mjs +0 -60
  132. package/dist/adapters/fastify/types.d.ts +0 -11
  133. package/dist/adapters/fastify/types.d.ts.map +0 -1
  134. package/dist/adapters/fetch/content-type/json/index.d.ts +0 -9
  135. package/dist/adapters/fetch/content-type/json/index.d.ts.map +0 -1
  136. package/dist/adapters/fetch/content-type/json/index.js +0 -55
  137. package/dist/adapters/fetch/content-type/json/index.mjs +0 -53
  138. package/dist/adapters/node-http/content-type/form-data/index.d.ts +0 -5
  139. package/dist/adapters/node-http/content-type/form-data/index.d.ts.map +0 -1
  140. package/dist/adapters/node-http/content-type/form-data/index.js +0 -32
  141. package/dist/adapters/node-http/content-type/form-data/index.mjs +0 -30
  142. package/dist/adapters/node-http/content-type/json/getPostBody.d.ts +0 -7
  143. package/dist/adapters/node-http/content-type/json/getPostBody.d.ts.map +0 -1
  144. package/dist/adapters/node-http/content-type/json/getPostBody.js +0 -45
  145. package/dist/adapters/node-http/content-type/json/getPostBody.mjs +0 -43
  146. package/dist/adapters/node-http/content-type/json/index.d.ts +0 -5
  147. package/dist/adapters/node-http/content-type/json/index.d.ts.map +0 -1
  148. package/dist/adapters/node-http/content-type/json/index.js +0 -68
  149. package/dist/adapters/node-http/content-type/json/index.mjs +0 -66
  150. package/dist/adapters/node-http/content-type/octet/index.d.ts +0 -5
  151. package/dist/adapters/node-http/content-type/octet/index.d.ts.map +0 -1
  152. package/dist/adapters/node-http/content-type/octet/index.js +0 -19
  153. package/dist/adapters/node-http/content-type/octet/index.mjs +0 -17
  154. package/dist/adapters/node-http/content-type/types.d.ts +0 -8
  155. package/dist/adapters/node-http/content-type/types.d.ts.map +0 -1
  156. package/dist/unstable-core-do-not-import/contentTypeParsers.d.ts +0 -16
  157. package/dist/unstable-core-do-not-import/contentTypeParsers.d.ts.map +0 -1
  158. package/dist/unstable-core-do-not-import/contentTypeParsers.js +0 -23
  159. package/dist/unstable-core-do-not-import/contentTypeParsers.mjs +0 -21
  160. package/dist/unstable-core-do-not-import/http/index.d.ts +0 -11
  161. package/dist/unstable-core-do-not-import/http/index.d.ts.map +0 -1
  162. package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts +0 -51
  163. package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts.map +0 -1
  164. package/src/adapters/aws-lambda/content-type/json/index.ts +0 -108
  165. package/src/adapters/aws-lambda/utils.ts +0 -170
  166. package/src/adapters/content-handlers/concurrentCache.ts +0 -16
  167. package/src/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.ts +0 -45
  168. package/src/adapters/fastify/content-type/json/index.ts +0 -106
  169. package/src/adapters/fastify/types.ts +0 -22
  170. package/src/adapters/fetch/content-type/json/index.ts +0 -90
  171. package/src/adapters/node-http/content-type/form-data/index.ts +0 -37
  172. package/src/adapters/node-http/content-type/json/getPostBody.ts +0 -49
  173. package/src/adapters/node-http/content-type/json/index.ts +0 -100
  174. package/src/adapters/node-http/content-type/octet/index.ts +0 -27
  175. package/src/adapters/node-http/content-type/types.ts +0 -19
  176. package/src/unstable-core-do-not-import/contentTypeParsers.ts +0 -37
  177. package/src/unstable-core-do-not-import/http/index.ts +0 -28
  178. package/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts +0 -461
package/dist/http.js CHANGED
@@ -1,8 +1,9 @@
1
1
  'use strict';
2
2
 
3
3
  var getHTTPStatusCode = require('./unstable-core-do-not-import/http/getHTTPStatusCode.js');
4
- var resolveHTTPResponse = require('./unstable-core-do-not-import/http/resolveHTTPResponse.js');
5
4
  var batchStreamFormatter = require('./unstable-core-do-not-import/http/batchStreamFormatter.js');
5
+ var contentTypeParsers = require('./unstable-core-do-not-import/http/contentTypeParsers.js');
6
+ var resolveResponse = require('./unstable-core-do-not-import/http/resolveResponse.js');
6
7
  var toURL = require('./unstable-core-do-not-import/http/toURL.js');
7
8
  require('./unstable-core-do-not-import/rootConfig.js');
8
9
 
@@ -10,6 +11,7 @@ require('./unstable-core-do-not-import/rootConfig.js');
10
11
 
11
12
  exports.getHTTPStatusCode = getHTTPStatusCode.getHTTPStatusCode;
12
13
  exports.getHTTPStatusCodeFromError = getHTTPStatusCode.getHTTPStatusCodeFromError;
13
- exports.resolveHTTPResponse = resolveHTTPResponse.resolveHTTPResponse;
14
14
  exports.getBatchStreamFormatter = batchStreamFormatter.getBatchStreamFormatter;
15
+ exports.octetInputParser = contentTypeParsers.octetInputParser;
16
+ exports.resolveResponse = resolveResponse.resolveResponse;
15
17
  exports.toURL = toURL.toURL;
package/dist/http.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  export { getHTTPStatusCode, getHTTPStatusCodeFromError } from './unstable-core-do-not-import/http/getHTTPStatusCode.mjs';
2
- export { resolveHTTPResponse } from './unstable-core-do-not-import/http/resolveHTTPResponse.mjs';
3
2
  export { getBatchStreamFormatter } from './unstable-core-do-not-import/http/batchStreamFormatter.mjs';
3
+ export { octetInputParser } from './unstable-core-do-not-import/http/contentTypeParsers.mjs';
4
+ export { resolveResponse } from './unstable-core-do-not-import/http/resolveResponse.mjs';
4
5
  export { toURL } from './unstable-core-do-not-import/http/toURL.mjs';
5
6
  import './unstable-core-do-not-import/rootConfig.mjs';
package/dist/index.js CHANGED
@@ -1,25 +1,23 @@
1
1
  'use strict';
2
2
 
3
3
  var createProxy = require('./unstable-core-do-not-import/createProxy.js');
4
- var getErrorShape = require('./unstable-core-do-not-import/error/getErrorShape.js');
5
4
  var TRPCError = require('./unstable-core-do-not-import/error/TRPCError.js');
5
+ var getErrorShape = require('./unstable-core-do-not-import/error/getErrorShape.js');
6
6
  var router = require('./unstable-core-do-not-import/router.js');
7
7
  var transformer = require('./unstable-core-do-not-import/transformer.js');
8
8
  var initTRPC = require('./unstable-core-do-not-import/initTRPC.js');
9
9
  var middleware = require('./unstable-core-do-not-import/middleware.js');
10
10
  require('./unstable-core-do-not-import/rootConfig.js');
11
- var contentTypeParsers = require('./unstable-core-do-not-import/contentTypeParsers.js');
12
11
 
13
12
 
14
13
 
15
14
  exports.createTRPCFlatProxy = createProxy.createFlatProxy;
16
- exports.getErrorShape = getErrorShape.getErrorShape;
17
15
  exports.TRPCError = TRPCError.TRPCError;
18
16
  exports.getTRPCErrorFromUnknown = TRPCError.getTRPCErrorFromUnknown;
17
+ exports.getErrorShape = getErrorShape.getErrorShape;
19
18
  exports.callProcedure = router.callProcedure;
20
19
  exports.callTRPCProcedure = router.callProcedure;
21
20
  exports.transformTRPCResponse = transformer.transformTRPCResponse;
22
21
  exports.initTRPC = initTRPC.initTRPC;
23
22
  exports.experimental_standaloneMiddleware = middleware.experimental_standaloneMiddleware;
24
23
  exports.experimental_trpcMiddleware = middleware.experimental_standaloneMiddleware;
25
- exports.parseOctetInput = contentTypeParsers.parseOctetInput;
package/dist/index.mjs CHANGED
@@ -1,9 +1,8 @@
1
1
  export { createFlatProxy as createTRPCFlatProxy } from './unstable-core-do-not-import/createProxy.mjs';
2
- export { getErrorShape } from './unstable-core-do-not-import/error/getErrorShape.mjs';
3
2
  export { TRPCError, getTRPCErrorFromUnknown } from './unstable-core-do-not-import/error/TRPCError.mjs';
3
+ export { getErrorShape } from './unstable-core-do-not-import/error/getErrorShape.mjs';
4
4
  export { callProcedure, callProcedure as callTRPCProcedure } from './unstable-core-do-not-import/router.mjs';
5
5
  export { transformTRPCResponse } from './unstable-core-do-not-import/transformer.mjs';
6
6
  export { initTRPC } from './unstable-core-do-not-import/initTRPC.mjs';
7
7
  export { experimental_standaloneMiddleware, experimental_standaloneMiddleware as experimental_trpcMiddleware } from './unstable-core-do-not-import/middleware.mjs';
8
8
  import './unstable-core-do-not-import/rootConfig.mjs';
9
- export { parseOctetInput } from './unstable-core-do-not-import/contentTypeParsers.mjs';
@@ -1,21 +1,9 @@
1
- import type { TRPCError } from '../error/TRPCError';
2
- export type BodyResult = {
3
- ok: true;
4
- data: unknown;
5
- /**
6
- * If the HTTP handler has already parsed the body
7
- */
8
- preprocessed: boolean;
9
- } | {
10
- ok: false;
11
- error: TRPCError;
12
- };
13
- export type BaseContentTypeHandler<TOptions> = {
14
- name: string;
15
- isMatch(headers: Headers): boolean;
16
- getInputs: (opts: TOptions, info: {
17
- isBatchCall: boolean;
18
- batch: number;
19
- }) => Promise<unknown>;
20
- };
1
+ import type { RootConfig } from '../rootConfig';
2
+ import type { TRPCRequestInfo } from './types';
3
+ export declare function getRequestInfo(opts: {
4
+ path: string;
5
+ req: Request;
6
+ searchParams: URLSearchParams;
7
+ config: RootConfig<any>;
8
+ }): TRPCRequestInfo;
21
9
  //# sourceMappingURL=contentType.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"contentType.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/http/contentType.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEpD,MAAM,MAAM,UAAU,GAClB;IACE,EAAE,EAAE,IAAI,CAAC;IACT,IAAI,EAAE,OAAO,CAAC;IACd;;OAEG;IACH,YAAY,EAAE,OAAO,CAAC;CACvB,GACD;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,SAAS,CAAA;CAAE,CAAC;AAEpC,MAAM,MAAM,sBAAsB,CAAC,QAAQ,IAAI;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC;IACnC,SAAS,EAAE,CACT,IAAI,EAAE,QAAQ,EACd,IAAI,EAAE;QACJ,WAAW,EAAE,OAAO,CAAC;QACrB,KAAK,EAAE,MAAM,CAAC;KACf,KACE,OAAO,CAAC,OAAO,CAAC,CAAC;CACvB,CAAC"}
1
+ {"version":3,"file":"contentType.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/http/contentType.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AA4M/C,wBAAgB,cAAc,CAAC,IAAI,EAAE;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,OAAO,CAAC;IACb,YAAY,EAAE,eAAe,CAAC;IAC9B,MAAM,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC;CACzB,GAAG,eAAe,CAGlB"}
@@ -0,0 +1,180 @@
1
+ 'use strict';
2
+
3
+ var TRPCError = require('../error/TRPCError.js');
4
+ var utils = require('../utils.js');
5
+
6
+ /**
7
+ * Memoize a function that takes no arguments
8
+ * @internal
9
+ */ function memo(fn) {
10
+ let promise = null;
11
+ let value = utils.unsetMarker;
12
+ return {
13
+ /**
14
+ * Lazily read the value
15
+ */ read: async ()=>{
16
+ if (value !== utils.unsetMarker) {
17
+ return value;
18
+ }
19
+ if (promise === null) {
20
+ // dedupes promises and catches errors
21
+ promise = fn().catch((cause)=>{
22
+ if (cause instanceof TRPCError.TRPCError) {
23
+ throw cause;
24
+ }
25
+ throw new TRPCError.TRPCError({
26
+ code: 'BAD_REQUEST',
27
+ message: cause instanceof Error ? cause.message : 'Invalid input',
28
+ cause
29
+ });
30
+ });
31
+ }
32
+ value = await promise;
33
+ promise = null;
34
+ return value;
35
+ },
36
+ /**
37
+ * Get an already stored result
38
+ */ result: ()=>{
39
+ return value !== utils.unsetMarker ? value : undefined;
40
+ }
41
+ };
42
+ }
43
+ const jsonContentTypeHandler = {
44
+ isMatch (req) {
45
+ return !!req.headers.get('content-type')?.startsWith('application/json');
46
+ },
47
+ parse (opts) {
48
+ const { req } = opts;
49
+ const isBatchCall = opts.searchParams.get('batch') === '1';
50
+ const paths = isBatchCall ? opts.path.split(',') : [
51
+ opts.path
52
+ ];
53
+ const getInputs = memo(async ()=>{
54
+ let inputs = undefined;
55
+ if (req.method === 'GET') {
56
+ const queryInput = opts.searchParams.get('input');
57
+ if (queryInput) {
58
+ inputs = JSON.parse(queryInput);
59
+ }
60
+ } else {
61
+ inputs = await req.json();
62
+ }
63
+ if (inputs === undefined) {
64
+ return {};
65
+ }
66
+ if (!isBatchCall) {
67
+ return {
68
+ 0: opts.config.transformer.input.deserialize(inputs)
69
+ };
70
+ }
71
+ if (!utils.isObject(inputs)) {
72
+ throw new TRPCError.TRPCError({
73
+ code: 'BAD_REQUEST',
74
+ message: '"input" needs to be an object when doing a batch call'
75
+ });
76
+ }
77
+ const acc = {};
78
+ for (const index of paths.keys()){
79
+ const input = inputs[index];
80
+ if (input !== undefined) {
81
+ acc[index] = opts.config.transformer.input.deserialize(input);
82
+ }
83
+ }
84
+ return acc;
85
+ });
86
+ return {
87
+ isBatchCall,
88
+ calls: paths.map((path, index)=>({
89
+ path,
90
+ getRawInput: async ()=>{
91
+ const inputs = await getInputs.read();
92
+ return inputs[index];
93
+ },
94
+ result: ()=>{
95
+ return getInputs.result()?.[index];
96
+ }
97
+ }))
98
+ };
99
+ }
100
+ };
101
+ const formDataContentTypeHandler = {
102
+ isMatch (req) {
103
+ return !!req.headers.get('content-type')?.startsWith('multipart/form-data');
104
+ },
105
+ parse (opts) {
106
+ const { req } = opts;
107
+ if (req.method !== 'POST') {
108
+ throw new TRPCError.TRPCError({
109
+ code: 'METHOD_NOT_SUPPORTED',
110
+ message: 'Only POST requests are supported for multipart/form-data requests'
111
+ });
112
+ }
113
+ const getInputs = memo(async ()=>{
114
+ const fd = await req.formData();
115
+ return fd;
116
+ });
117
+ return {
118
+ calls: [
119
+ {
120
+ path: opts.path,
121
+ getRawInput: getInputs.read,
122
+ result: getInputs.result
123
+ }
124
+ ],
125
+ isBatchCall: false
126
+ };
127
+ }
128
+ };
129
+ const octetStreamContentTypeHandler = {
130
+ isMatch (req) {
131
+ return !!req.headers.get('content-type')?.startsWith('application/octet-stream');
132
+ },
133
+ parse (opts) {
134
+ const { req } = opts;
135
+ if (req.method !== 'POST') {
136
+ throw new TRPCError.TRPCError({
137
+ code: 'METHOD_NOT_SUPPORTED',
138
+ message: 'Only POST requests are supported for application/octet-stream requests'
139
+ });
140
+ }
141
+ const getInputs = memo(async ()=>{
142
+ return req.body;
143
+ });
144
+ return {
145
+ calls: [
146
+ {
147
+ path: opts.path,
148
+ getRawInput: getInputs.read,
149
+ result: getInputs.result
150
+ }
151
+ ],
152
+ isBatchCall: false
153
+ };
154
+ }
155
+ };
156
+ const handlers = [
157
+ jsonContentTypeHandler,
158
+ formDataContentTypeHandler,
159
+ octetStreamContentTypeHandler
160
+ ];
161
+ function getContentTypeHandler(req) {
162
+ const handler = handlers.find((handler)=>handler.isMatch(req));
163
+ if (handler) {
164
+ return handler;
165
+ }
166
+ if (!handler && req.method === 'GET') {
167
+ // fallback to JSON for get requests so GET-requests can be opened in browser easily
168
+ return jsonContentTypeHandler;
169
+ }
170
+ throw new TRPCError.TRPCError({
171
+ code: 'UNSUPPORTED_MEDIA_TYPE',
172
+ message: req.headers.has('content-type') ? `Unsupported content-type "${req.headers.get('content-type')}` : 'Missing content-type header'
173
+ });
174
+ }
175
+ function getRequestInfo(opts) {
176
+ const handler = getContentTypeHandler(opts.req);
177
+ return handler.parse(opts);
178
+ }
179
+
180
+ exports.getRequestInfo = getRequestInfo;
@@ -0,0 +1,178 @@
1
+ import { TRPCError } from '../error/TRPCError.mjs';
2
+ import { unsetMarker, isObject } from '../utils.mjs';
3
+
4
+ /**
5
+ * Memoize a function that takes no arguments
6
+ * @internal
7
+ */ function memo(fn) {
8
+ let promise = null;
9
+ let value = unsetMarker;
10
+ return {
11
+ /**
12
+ * Lazily read the value
13
+ */ read: async ()=>{
14
+ if (value !== unsetMarker) {
15
+ return value;
16
+ }
17
+ if (promise === null) {
18
+ // dedupes promises and catches errors
19
+ promise = fn().catch((cause)=>{
20
+ if (cause instanceof TRPCError) {
21
+ throw cause;
22
+ }
23
+ throw new TRPCError({
24
+ code: 'BAD_REQUEST',
25
+ message: cause instanceof Error ? cause.message : 'Invalid input',
26
+ cause
27
+ });
28
+ });
29
+ }
30
+ value = await promise;
31
+ promise = null;
32
+ return value;
33
+ },
34
+ /**
35
+ * Get an already stored result
36
+ */ result: ()=>{
37
+ return value !== unsetMarker ? value : undefined;
38
+ }
39
+ };
40
+ }
41
+ const jsonContentTypeHandler = {
42
+ isMatch (req) {
43
+ return !!req.headers.get('content-type')?.startsWith('application/json');
44
+ },
45
+ parse (opts) {
46
+ const { req } = opts;
47
+ const isBatchCall = opts.searchParams.get('batch') === '1';
48
+ const paths = isBatchCall ? opts.path.split(',') : [
49
+ opts.path
50
+ ];
51
+ const getInputs = memo(async ()=>{
52
+ let inputs = undefined;
53
+ if (req.method === 'GET') {
54
+ const queryInput = opts.searchParams.get('input');
55
+ if (queryInput) {
56
+ inputs = JSON.parse(queryInput);
57
+ }
58
+ } else {
59
+ inputs = await req.json();
60
+ }
61
+ if (inputs === undefined) {
62
+ return {};
63
+ }
64
+ if (!isBatchCall) {
65
+ return {
66
+ 0: opts.config.transformer.input.deserialize(inputs)
67
+ };
68
+ }
69
+ if (!isObject(inputs)) {
70
+ throw new TRPCError({
71
+ code: 'BAD_REQUEST',
72
+ message: '"input" needs to be an object when doing a batch call'
73
+ });
74
+ }
75
+ const acc = {};
76
+ for (const index of paths.keys()){
77
+ const input = inputs[index];
78
+ if (input !== undefined) {
79
+ acc[index] = opts.config.transformer.input.deserialize(input);
80
+ }
81
+ }
82
+ return acc;
83
+ });
84
+ return {
85
+ isBatchCall,
86
+ calls: paths.map((path, index)=>({
87
+ path,
88
+ getRawInput: async ()=>{
89
+ const inputs = await getInputs.read();
90
+ return inputs[index];
91
+ },
92
+ result: ()=>{
93
+ return getInputs.result()?.[index];
94
+ }
95
+ }))
96
+ };
97
+ }
98
+ };
99
+ const formDataContentTypeHandler = {
100
+ isMatch (req) {
101
+ return !!req.headers.get('content-type')?.startsWith('multipart/form-data');
102
+ },
103
+ parse (opts) {
104
+ const { req } = opts;
105
+ if (req.method !== 'POST') {
106
+ throw new TRPCError({
107
+ code: 'METHOD_NOT_SUPPORTED',
108
+ message: 'Only POST requests are supported for multipart/form-data requests'
109
+ });
110
+ }
111
+ const getInputs = memo(async ()=>{
112
+ const fd = await req.formData();
113
+ return fd;
114
+ });
115
+ return {
116
+ calls: [
117
+ {
118
+ path: opts.path,
119
+ getRawInput: getInputs.read,
120
+ result: getInputs.result
121
+ }
122
+ ],
123
+ isBatchCall: false
124
+ };
125
+ }
126
+ };
127
+ const octetStreamContentTypeHandler = {
128
+ isMatch (req) {
129
+ return !!req.headers.get('content-type')?.startsWith('application/octet-stream');
130
+ },
131
+ parse (opts) {
132
+ const { req } = opts;
133
+ if (req.method !== 'POST') {
134
+ throw new TRPCError({
135
+ code: 'METHOD_NOT_SUPPORTED',
136
+ message: 'Only POST requests are supported for application/octet-stream requests'
137
+ });
138
+ }
139
+ const getInputs = memo(async ()=>{
140
+ return req.body;
141
+ });
142
+ return {
143
+ calls: [
144
+ {
145
+ path: opts.path,
146
+ getRawInput: getInputs.read,
147
+ result: getInputs.result
148
+ }
149
+ ],
150
+ isBatchCall: false
151
+ };
152
+ }
153
+ };
154
+ const handlers = [
155
+ jsonContentTypeHandler,
156
+ formDataContentTypeHandler,
157
+ octetStreamContentTypeHandler
158
+ ];
159
+ function getContentTypeHandler(req) {
160
+ const handler = handlers.find((handler)=>handler.isMatch(req));
161
+ if (handler) {
162
+ return handler;
163
+ }
164
+ if (!handler && req.method === 'GET') {
165
+ // fallback to JSON for get requests so GET-requests can be opened in browser easily
166
+ return jsonContentTypeHandler;
167
+ }
168
+ throw new TRPCError({
169
+ code: 'UNSUPPORTED_MEDIA_TYPE',
170
+ message: req.headers.has('content-type') ? `Unsupported content-type "${req.headers.get('content-type')}` : 'Missing content-type header'
171
+ });
172
+ }
173
+ function getRequestInfo(opts) {
174
+ const handler = getContentTypeHandler(opts.req);
175
+ return handler.parse(opts);
176
+ }
177
+
178
+ export { getRequestInfo };
@@ -0,0 +1,14 @@
1
+ import type { ParserZodEsque } from '../parser';
2
+ type UtilityParser<TInput, TOutput> = ParserZodEsque<TInput, TOutput> & {
3
+ parse: (input: unknown) => TOutput;
4
+ };
5
+ /**
6
+ * File is only available from Node19+ but it always extends Blob so we can use that as a type until we eventually drop Node18
7
+ */
8
+ interface FileLike extends Blob {
9
+ readonly name: string;
10
+ }
11
+ type OctetInput = Blob | Uint8Array | FileLike;
12
+ export declare const octetInputParser: UtilityParser<OctetInput, ReadableStream>;
13
+ export {};
14
+ //# sourceMappingURL=contentTypeParsers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contentTypeParsers.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/http/contentTypeParsers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEhD,KAAK,aAAa,CAAC,MAAM,EAAE,OAAO,IAAI,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IACtE,KAAK,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;CACpC,CAAC;AAIF;;GAEG;AACH,UAAU,QAAS,SAAQ,IAAI;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,KAAK,UAAU,GAAG,IAAI,GAAG,UAAU,GAAG,QAAQ,CAAC;AAC/C,eAAO,MAAM,gBAAgB,EAAE,aAAa,CAAC,UAAU,EAAE,cAAc,CAYtE,CAAC"}
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ const octetInputParser = {
4
+ _input: null,
5
+ _output: null,
6
+ parse (input) {
7
+ if (input instanceof ReadableStream) {
8
+ return input;
9
+ }
10
+ throw new Error(`Parsed input was expected to be a ReadableStream but was: ${typeof input}`);
11
+ }
12
+ };
13
+
14
+ exports.octetInputParser = octetInputParser;
@@ -0,0 +1,12 @@
1
+ const octetInputParser = {
2
+ _input: null,
3
+ _output: null,
4
+ parse (input) {
5
+ if (input instanceof ReadableStream) {
6
+ return input;
7
+ }
8
+ throw new Error(`Parsed input was expected to be a ReadableStream but was: ${typeof input}`);
9
+ }
10
+ };
11
+
12
+ export { octetInputParser };
@@ -1,5 +1,5 @@
1
1
  import type { TRPCError } from '../error/TRPCError';
2
2
  import type { TRPCResponse } from '../rpc';
3
- export declare function getHTTPStatusCode(json: TRPCResponse | TRPCResponse[]): any;
3
+ export declare function getHTTPStatusCode(json: TRPCResponse | TRPCResponse[]): number;
4
4
  export declare function getHTTPStatusCodeFromError(error: TRPCError): number;
5
5
  //# sourceMappingURL=getHTTPStatusCode.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getHTTPStatusCode.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/http/getHTTPStatusCode.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAA2B,YAAY,EAAE,MAAM,QAAQ,CAAC;AA6BpE,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,YAAY,GAAG,YAAY,EAAE,OAyBpE;AAED,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,SAAS,UAE1D"}
1
+ {"version":3,"file":"getHTTPStatusCode.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/http/getHTTPStatusCode.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAA2B,YAAY,EAAE,MAAM,QAAQ,CAAC;AA6BpE,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,YAAY,GAAG,YAAY,EAAE,GAAG,MAAM,CAyB7E;AAED,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,SAAS,UAE1D"}
@@ -0,0 +1,15 @@
1
+ import { TRPCError } from '../error/TRPCError';
2
+ import { type AnyRouter } from '../router';
3
+ import type { HTTPBaseHandlerOptions, ResolveHTTPRequestOptionsContextFn } from './types';
4
+ interface ResolveHTTPRequestOptions<TRouter extends AnyRouter> extends HTTPBaseHandlerOptions<TRouter, Request> {
5
+ createContext: ResolveHTTPRequestOptionsContextFn<TRouter>;
6
+ req: Request;
7
+ path: string;
8
+ /**
9
+ * If the request had an issue before reaching the handler
10
+ */
11
+ error: TRPCError | null;
12
+ }
13
+ export declare function resolveResponse<TRouter extends AnyRouter>(opts: ResolveHTTPRequestOptions<TRouter>): Promise<Response>;
14
+ export {};
15
+ //# sourceMappingURL=resolveResponse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveResponse.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/http/resolveResponse.ts"],"names":[],"mappings":"AAEA,OAAO,EAA2B,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAExE,OAAO,EAEL,KAAK,SAAS,EAGf,MAAM,WAAW,CAAC;AAMnB,OAAO,KAAK,EACV,sBAAsB,EACtB,kCAAkC,EAEnC,MAAM,SAAS,CAAC;AAUjB,UAAU,yBAAyB,CAAC,OAAO,SAAS,SAAS,CAC3D,SAAQ,sBAAsB,CAAC,OAAO,EAAE,OAAO,CAAC;IAChD,aAAa,EAAE,kCAAkC,CAAC,OAAO,CAAC,CAAC;IAC3D,GAAG,EAAE,OAAO,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;CACzB;AAuHD,wBAAsB,eAAe,CAAC,OAAO,SAAS,SAAS,EAC7D,IAAI,EAAE,yBAAyB,CAAC,OAAO,CAAC,GACvC,OAAO,CAAC,QAAQ,CAAC,CAkOnB"}