@trpc/server 11.0.0-alpha-tmp-04-02-no-typesProxy.345 → 11.0.0-alpha-tmp-04-26-resolveResponse.388

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 (141) hide show
  1. package/dist/@trpc/server/http.d.ts +2 -2
  2. package/dist/@trpc/server/http.d.ts.map +1 -1
  3. package/dist/@trpc/server/index.d.ts +1 -1
  4. package/dist/@trpc/server/index.d.ts.map +1 -1
  5. package/dist/adapters/aws-lambda/index.d.ts.map +1 -1
  6. package/dist/adapters/aws-lambda/index.js +26 -24
  7. package/dist/adapters/aws-lambda/index.mjs +27 -26
  8. package/dist/adapters/aws-lambda/utils.d.ts +3 -2
  9. package/dist/adapters/aws-lambda/utils.d.ts.map +1 -1
  10. package/dist/adapters/aws-lambda/utils.js +25 -1
  11. package/dist/adapters/aws-lambda/utils.mjs +25 -2
  12. package/dist/adapters/fastify/fastifyRequestHandler.d.ts +10 -1
  13. package/dist/adapters/fastify/fastifyRequestHandler.d.ts.map +1 -1
  14. package/dist/adapters/fastify/fastifyRequestHandler.js +13 -56
  15. package/dist/adapters/fastify/fastifyRequestHandler.mjs +13 -56
  16. package/dist/adapters/fetch/fetchRequestHandler.d.ts.map +1 -1
  17. package/dist/adapters/fetch/fetchRequestHandler.js +15 -72
  18. package/dist/adapters/fetch/fetchRequestHandler.mjs +15 -72
  19. package/dist/adapters/node-http/index.js +1 -0
  20. package/dist/adapters/node-http/index.mjs +1 -1
  21. package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts +6 -1
  22. package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
  23. package/dist/adapters/node-http/nodeHTTPRequestHandler.js +85 -73
  24. package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +85 -74
  25. package/dist/adapters/node-http/types.d.ts +0 -2
  26. package/dist/adapters/node-http/types.d.ts.map +1 -1
  27. package/dist/bundle-analysis.json +190 -264
  28. package/dist/http.js +2 -2
  29. package/dist/http.mjs +1 -1
  30. package/dist/unstable-core-do-not-import/createProxy.d.ts.map +1 -1
  31. package/dist/unstable-core-do-not-import/createProxy.js +20 -5
  32. package/dist/unstable-core-do-not-import/createProxy.mjs +20 -5
  33. package/dist/unstable-core-do-not-import/http/content-type/contentTypeHandlers.d.ts +8 -0
  34. package/dist/unstable-core-do-not-import/http/content-type/contentTypeHandlers.d.ts.map +1 -0
  35. package/dist/unstable-core-do-not-import/http/content-type/contentTypeHandlers.js +16 -0
  36. package/dist/unstable-core-do-not-import/http/content-type/contentTypeHandlers.mjs +14 -0
  37. package/dist/unstable-core-do-not-import/http/content-type/handlers/formData.d.ts +3 -0
  38. package/dist/unstable-core-do-not-import/http/content-type/handlers/formData.d.ts.map +1 -0
  39. package/dist/unstable-core-do-not-import/http/content-type/handlers/formData.js +24 -0
  40. package/dist/unstable-core-do-not-import/http/content-type/handlers/formData.mjs +22 -0
  41. package/dist/unstable-core-do-not-import/http/content-type/handlers/json.d.ts +3 -0
  42. package/dist/unstable-core-do-not-import/http/content-type/handlers/json.d.ts.map +1 -0
  43. package/dist/unstable-core-do-not-import/http/content-type/handlers/json.js +21 -0
  44. package/dist/unstable-core-do-not-import/http/content-type/handlers/json.mjs +19 -0
  45. package/dist/unstable-core-do-not-import/http/contentType.d.ts +5 -4
  46. package/dist/unstable-core-do-not-import/http/contentType.d.ts.map +1 -1
  47. package/dist/unstable-core-do-not-import/http/index.d.ts +2 -3
  48. package/dist/unstable-core-do-not-import/http/index.d.ts.map +1 -1
  49. package/dist/unstable-core-do-not-import/http/resolveResponse.d.ts +15 -0
  50. package/dist/unstable-core-do-not-import/http/resolveResponse.d.ts.map +1 -0
  51. package/dist/unstable-core-do-not-import/http/resolveResponse.js +350 -0
  52. package/dist/unstable-core-do-not-import/http/resolveResponse.mjs +348 -0
  53. package/dist/unstable-core-do-not-import/http/types.d.ts +1 -3
  54. package/dist/unstable-core-do-not-import/http/types.d.ts.map +1 -1
  55. package/dist/unstable-core-do-not-import/initTRPC.d.ts +2 -2
  56. package/dist/unstable-core-do-not-import/initTRPC.d.ts.map +1 -1
  57. package/dist/unstable-core-do-not-import/procedureBuilder.d.ts +1 -3
  58. package/dist/unstable-core-do-not-import/procedureBuilder.d.ts.map +1 -1
  59. package/dist/unstable-core-do-not-import/procedureBuilder.js +0 -2
  60. package/dist/unstable-core-do-not-import/procedureBuilder.mjs +1 -2
  61. package/dist/unstable-core-do-not-import/router.d.ts.map +1 -1
  62. package/dist/unstable-core-do-not-import/router.js +5 -1
  63. package/dist/unstable-core-do-not-import/router.mjs +5 -1
  64. package/dist/unstable-core-do-not-import/utils.d.ts +8 -0
  65. package/dist/unstable-core-do-not-import/utils.d.ts.map +1 -1
  66. package/dist/unstable-core-do-not-import/utils.js +15 -0
  67. package/dist/unstable-core-do-not-import/utils.mjs +14 -1
  68. package/dist/unstable-core-do-not-import.d.ts +0 -1
  69. package/dist/unstable-core-do-not-import.d.ts.map +1 -1
  70. package/dist/unstable-core-do-not-import.js +4 -3
  71. package/dist/unstable-core-do-not-import.mjs +3 -3
  72. package/package.json +3 -14
  73. package/src/@trpc/server/http.ts +2 -2
  74. package/src/@trpc/server/index.ts +4 -0
  75. package/src/adapters/aws-lambda/index.ts +35 -32
  76. package/src/adapters/aws-lambda/utils.ts +37 -3
  77. package/src/adapters/fastify/fastifyRequestHandler.ts +18 -76
  78. package/src/adapters/fetch/fetchRequestHandler.ts +18 -91
  79. package/src/adapters/node-http/nodeHTTPRequestHandler.ts +111 -109
  80. package/src/adapters/node-http/types.ts +0 -5
  81. package/src/unstable-core-do-not-import/createProxy.ts +16 -5
  82. package/src/unstable-core-do-not-import/http/content-type/contentTypeHandlers.ts +10 -0
  83. package/src/unstable-core-do-not-import/http/content-type/handlers/formData.ts +22 -0
  84. package/src/unstable-core-do-not-import/http/content-type/handlers/json.ts +19 -0
  85. package/src/unstable-core-do-not-import/http/contentType.ts +5 -4
  86. package/src/unstable-core-do-not-import/http/index.ts +5 -3
  87. package/src/unstable-core-do-not-import/http/{resolveHTTPResponse.ts → resolveResponse.ts} +199 -176
  88. package/src/unstable-core-do-not-import/http/types.ts +2 -3
  89. package/src/unstable-core-do-not-import/initTRPC.ts +1 -0
  90. package/src/unstable-core-do-not-import/procedureBuilder.ts +2 -4
  91. package/src/unstable-core-do-not-import/router.ts +5 -0
  92. package/src/unstable-core-do-not-import/utils.ts +18 -0
  93. package/src/unstable-core-do-not-import.ts +0 -1
  94. package/adapters/node-http/content-type/form-data/index.d.ts +0 -1
  95. package/adapters/node-http/content-type/form-data/index.js +0 -1
  96. package/adapters/node-http/content-type/json/index.d.ts +0 -1
  97. package/adapters/node-http/content-type/json/index.js +0 -1
  98. package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.d.ts +0 -73
  99. package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.d.ts.map +0 -1
  100. package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.js +0 -161
  101. package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.mjs +0 -157
  102. package/dist/adapters/node-http/content-type/form-data/index.d.ts +0 -26
  103. package/dist/adapters/node-http/content-type/form-data/index.d.ts.map +0 -1
  104. package/dist/adapters/node-http/content-type/form-data/index.js +0 -135
  105. package/dist/adapters/node-http/content-type/form-data/index.mjs +0 -108
  106. package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.d.ts +0 -31
  107. package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.d.ts.map +0 -1
  108. package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.js +0 -29
  109. package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.mjs +0 -27
  110. package/dist/adapters/node-http/content-type/form-data/streamSlice.d.ts +0 -16
  111. package/dist/adapters/node-http/content-type/form-data/streamSlice.d.ts.map +0 -1
  112. package/dist/adapters/node-http/content-type/form-data/streamSlice.js +0 -46
  113. package/dist/adapters/node-http/content-type/form-data/streamSlice.mjs +0 -44
  114. package/dist/adapters/node-http/content-type/form-data/uploadHandler.d.ts +0 -45
  115. package/dist/adapters/node-http/content-type/form-data/uploadHandler.d.ts.map +0 -1
  116. package/dist/adapters/node-http/content-type/form-data/uploadHandler.js +0 -30
  117. package/dist/adapters/node-http/content-type/form-data/uploadHandler.mjs +0 -26
  118. package/dist/adapters/node-http/content-type/json/getPostBody.d.ts +0 -7
  119. package/dist/adapters/node-http/content-type/json/getPostBody.d.ts.map +0 -1
  120. package/dist/adapters/node-http/content-type/json/getPostBody.js +0 -53
  121. package/dist/adapters/node-http/content-type/json/getPostBody.mjs +0 -51
  122. package/dist/adapters/node-http/content-type/json/index.d.ts +0 -2
  123. package/dist/adapters/node-http/content-type/json/index.d.ts.map +0 -1
  124. package/dist/adapters/node-http/content-type/json/index.js +0 -16
  125. package/dist/adapters/node-http/content-type/json/index.mjs +0 -14
  126. package/dist/adapters/node-http/internals/contentType.d.ts +0 -9
  127. package/dist/adapters/node-http/internals/contentType.d.ts.map +0 -1
  128. package/dist/adapters/node-http/internals/contentType.js +0 -8
  129. package/dist/adapters/node-http/internals/contentType.mjs +0 -6
  130. package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts +0 -51
  131. package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts.map +0 -1
  132. package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.js +0 -292
  133. package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.mjs +0 -290
  134. package/src/adapters/node-http/content-type/form-data/fileUploadHandler.ts +0 -277
  135. package/src/adapters/node-http/content-type/form-data/index.ts +0 -163
  136. package/src/adapters/node-http/content-type/form-data/memoryUploadHandler.ts +0 -56
  137. package/src/adapters/node-http/content-type/form-data/streamSlice.ts +0 -56
  138. package/src/adapters/node-http/content-type/form-data/uploadHandler.ts +0 -89
  139. package/src/adapters/node-http/content-type/json/getPostBody.ts +0 -58
  140. package/src/adapters/node-http/content-type/json/index.ts +0 -11
  141. package/src/adapters/node-http/internals/contentType.ts +0 -31
@@ -1,8 +1,8 @@
1
1
  export { getHTTPStatusCode, getHTTPStatusCodeFromError, } from '../../unstable-core-do-not-import';
2
- export { resolveHTTPResponse } from '../../unstable-core-do-not-import';
2
+ export { resolveResponse } from '../../unstable-core-do-not-import';
3
3
  export type { BaseHandlerOptions, HTTPBaseHandlerOptions, HTTPHeaders, HTTPRequest, HTTPResponse, OnErrorFunction, ProcedureCall, ResolveHTTPRequestOptionsContextFn, ResponseChunk, ResponseMeta, ResponseMetaFn, TRPCRequestInfo, } from '../../unstable-core-do-not-import';
4
4
  export { getBatchStreamFormatter } from '../../unstable-core-do-not-import';
5
- export type { BaseContentTypeHandler, BodyResult, } from '../../unstable-core-do-not-import';
5
+ export type { ContentTypeHandler, BodyResult, } from '../../unstable-core-do-not-import';
6
6
  export { getJsonContentTypeInputs } from '../../unstable-core-do-not-import';
7
7
  export { toURL } from '../../unstable-core-do-not-import';
8
8
  //# sourceMappingURL=http.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/@trpc/server/http.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,0BAA0B,GAC3B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AACxE,YAAY,EACV,kBAAkB,EAClB,sBAAsB,EACtB,WAAW,EACX,WAAW,EACX,YAAY,EACZ,eAAe,EACf,aAAa,EACb,kCAAkC,EAClC,aAAa,EACb,YAAY,EACZ,cAAc,EACd,eAAe,GAChB,MAAM,mCAAmC,CAAC;AAE3C,OAAO,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AAC5E,YAAY,EACV,sBAAsB,EACtB,UAAU,GACX,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC"}
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/@trpc/server/http.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,0BAA0B,GAC3B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACpE,YAAY,EACV,kBAAkB,EAClB,sBAAsB,EACtB,WAAW,EACX,WAAW,EACX,YAAY,EACZ,eAAe,EACf,aAAa,EACb,kCAAkC,EAClC,aAAa,EACb,YAAY,EACZ,cAAc,EACd,eAAe,GAChB,MAAM,mCAAmC,CAAC;AAE3C,OAAO,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AAC5E,YAAY,EACV,kBAAkB,EAClB,UAAU,GACX,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC"}
@@ -2,7 +2,7 @@ export { TRPCError,
2
2
  /**
3
3
  * @deprecated use `experimental_trpcMiddleware` instead
4
4
  */
5
- experimental_standaloneMiddleware, experimental_standaloneMiddleware as experimental_trpcMiddleware, initTRPC, callProcedure as callTRPCProcedure, getTRPCErrorFromUnknown, transformTRPCResponse, createFlatProxy as createTRPCFlatProxy, type inferProcedureInput, type inferProcedureOutput, type inferProcedureBuilderResolverOptions, type inferRouterError, type inferRouterInputs, type inferRouterOutputs, type inferRouterContext, type inferClientTypes as inferTRPCClientTypes, type AnyClientTypes as AnyTRPCClientTypes, type inferTransformedProcedureOutput, type inferTransformedSubscriptionOutput, type AnyProcedure as AnyTRPCProcedure, type AnyRouter as AnyTRPCRouter, type AnyMiddlewareFunction as AnyTRPCMiddlewareFunction, type CombinedDataTransformer as TRPCCombinedDataTransformer, type ProcedureType as TRPCProcedureType, type AnyMutationProcedure as AnyTRPCMutationProcedure, type AnyQueryProcedure as AnyTRPCQueryProcedure, type RouterRecord as TRPCRouterRecord, type AnySubscriptionProcedure as AnyTRPCSubscriptionProcedure, type ProcedureOptions as TRPCProcedureOptions, } from '../../unstable-core-do-not-import';
5
+ experimental_standaloneMiddleware, experimental_standaloneMiddleware as experimental_trpcMiddleware, initTRPC, callProcedure as callTRPCProcedure, getTRPCErrorFromUnknown, transformTRPCResponse, createFlatProxy as createTRPCFlatProxy, type inferProcedureInput, type inferProcedureOutput, type inferProcedureBuilderResolverOptions, type inferRouterError, type inferRouterInputs, type inferRouterOutputs, type inferRouterContext, type inferClientTypes as inferTRPCClientTypes, type AnyClientTypes as AnyTRPCClientTypes, type inferTransformedProcedureOutput, type inferTransformedSubscriptionOutput, type AnyProcedure as AnyTRPCProcedure, type AnyRouter as AnyTRPCRouter, type AnyMiddlewareFunction as AnyTRPCMiddlewareFunction, type CombinedDataTransformer as TRPCCombinedDataTransformer, type ProcedureType as TRPCProcedureType, type AnyMutationProcedure as AnyTRPCMutationProcedure, type AnyQueryProcedure as AnyTRPCQueryProcedure, type RouterRecord as TRPCRouterRecord, type AnySubscriptionProcedure as AnyTRPCSubscriptionProcedure, type ProcedureOptions as TRPCProcedureOptions, type MutationProcedure as TRPCMutationProcedure, type QueryProcedure as TRPCQueryProcedure, type SubscriptionProcedure as TRPCSubscriptionProcedure, type TRPCBuilder, } from '../../unstable-core-do-not-import';
6
6
  export type {
7
7
  /**
8
8
  * @deprecated use `AnyTRPCProcedure` instead
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/@trpc/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS;AACT;;GAEG;AACH,iCAAiC,EACjC,iCAAiC,IAAI,2BAA2B,EAChE,QAAQ,EAER,aAAa,IAAI,iBAAiB,EAClC,uBAAuB,EACvB,qBAAqB,EACrB,eAAe,IAAI,mBAAmB,EACtC,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,oCAAoC,EACzC,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,E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AE,GAAG,EAAE,KAAK,GAAG,IACxE,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/aws-lambda/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EACV,oBAAoB,EACpB,sBAAsB,EACtB,qBAAqB,EACrB,iCAAiC,EACjC,OAAO,IAAI,YAAY,EACxB,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AASpD,OAAO,KAAK,EACV,eAAe,EAEf,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAUjB,cAAc,SAAS,CAAC;AAqDxB;;IAEI;AACJ,KAAK,gBAAgB,CAAC,KAAK,IAAI,KAAK,SAAS,oBAAoB,GAC7D,qBAAqB,GACrB,KAAK,SAAS,sBAAsB,GACpC,iCAAiC,GACjC,KAAK,CAAC;AACV,wBAAgB,uBAAuB,CACrC,OAAO,SAAS,SAAS,EACzB,MAAM,SAAS,eAAe,EAC9B,OAAO,SAAS,gBAAgB,CAAC,MAAM,CAAC,EAExC,IAAI,EAAE,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,GACtC,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,KAAK,OAAO,CAAC,OAAO,CAAC,CA0B5D"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/aws-lambda/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EACV,oBAAoB,EACpB,sBAAsB,EACtB,qBAAqB,EACrB,iCAAiC,EACjC,OAAO,IAAI,YAAY,EACxB,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAKpD,OAAO,KAAK,EACV,eAAe,EAEf,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAWjB,cAAc,SAAS,CAAC;AAyDxB;;IAEI;AACJ,KAAK,gBAAgB,CAAC,KAAK,IAAI,KAAK,SAAS,oBAAoB,GAC7D,qBAAqB,GACrB,KAAK,SAAS,sBAAsB,GACpC,iCAAiC,GACjC,KAAK,CAAC;AACV,wBAAgB,uBAAuB,CACrC,OAAO,SAAS,SAAS,EACzB,MAAM,SAAS,eAAe,EAC9B,OAAO,SAAS,gBAAgB,CAAC,MAAM,CAAC,EAExC,IAAI,EAAE,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,GACtC,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,KAAK,OAAO,CAAC,OAAO,CAAC,CA4B5D"}
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var TRPCError = require('../../unstable-core-do-not-import/error/TRPCError.js');
4
- var resolveHTTPResponse = require('../../unstable-core-do-not-import/http/resolveHTTPResponse.js');
4
+ var resolveResponse = require('../../unstable-core-do-not-import/http/resolveResponse.js');
5
5
  require('../../unstable-core-do-not-import/rootConfig.js');
6
6
  var utils = require('./utils.js');
7
7
 
@@ -14,41 +14,42 @@ var utils = require('./utils.js');
14
14
  * import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
15
15
  * ```
16
16
  */ // @trpc/server
17
- function lambdaEventToHTTPRequest(event) {
18
- const query = new URLSearchParams();
19
- for (const [key, value] of Object.entries(event.queryStringParameters ?? {})){
20
- if (typeof value !== 'undefined') {
21
- query.append(key, value);
22
- }
23
- }
17
+ function lambdaEventToRequest(event) {
24
18
  let body;
25
19
  if (event.body && event.isBase64Encoded) {
26
20
  body = Buffer.from(event.body, 'base64').toString('utf8');
27
21
  } else {
28
22
  body = event.body;
29
23
  }
30
- return {
31
- method: utils.getHTTPMethod(event),
32
- query: query,
24
+ const url = utils.getURLFromEvent(event);
25
+ const method = utils.getHTTPMethod(event);
26
+ const init = {
33
27
  headers: event.headers,
34
- body: body
28
+ method,
29
+ // @ts-expect-error this is fine
30
+ duplex: 'half'
35
31
  };
32
+ if (method === 'POST') {
33
+ init.body = body;
34
+ }
35
+ const request = new Request(url, init);
36
+ return request;
36
37
  }
37
- function tRPCOutputToAPIGatewayOutput(event, response) {
38
+ async function tRPCOutputToAPIGatewayOutput(event, response) {
38
39
  if (utils.isPayloadV1(event)) {
39
- const resp = {
40
+ const result = {
40
41
  statusCode: response.status,
41
- body: response.body ?? '',
42
- headers: utils.transformHeaders(response.headers ?? {})
42
+ body: await response.text(),
43
+ headers: utils.transformHeaders(response.headers)
43
44
  };
44
- return resp;
45
+ return result;
45
46
  } else if (utils.isPayloadV2(event)) {
46
- const resp1 = {
47
+ const resp = {
47
48
  statusCode: response.status,
48
- body: response.body ?? undefined,
49
- headers: utils.transformHeaders(response.headers ?? {})
49
+ body: await response.text(),
50
+ headers: utils.transformHeaders(response.headers)
50
51
  };
51
- return resp1;
52
+ return resp;
52
53
  } else {
53
54
  throw new TRPCError.TRPCError({
54
55
  code: 'INTERNAL_SERVER_ERROR',
@@ -58,7 +59,7 @@ function tRPCOutputToAPIGatewayOutput(event, response) {
58
59
  }
59
60
  function awsLambdaRequestHandler(opts) {
60
61
  return async (event, context)=>{
61
- const req = lambdaEventToHTTPRequest(event);
62
+ const req = lambdaEventToRequest(event);
62
63
  const path = utils.getPath(event);
63
64
  const createContext = async (innerOpts)=>{
64
65
  return await opts.createContext?.({
@@ -67,7 +68,7 @@ function awsLambdaRequestHandler(opts) {
67
68
  ...innerOpts
68
69
  });
69
70
  };
70
- const response = await resolveHTTPResponse.resolveHTTPResponse({
71
+ const response = await resolveResponse.resolveResponse({
71
72
  ...opts,
72
73
  createContext,
73
74
  req,
@@ -80,13 +81,14 @@ function awsLambdaRequestHandler(opts) {
80
81
  });
81
82
  }
82
83
  });
83
- return tRPCOutputToAPIGatewayOutput(event, response);
84
+ return await tRPCOutputToAPIGatewayOutput(event, response);
84
85
  };
85
86
  }
86
87
 
87
88
  exports.UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE = utils.UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE;
88
89
  exports.getHTTPMethod = utils.getHTTPMethod;
89
90
  exports.getPath = utils.getPath;
91
+ exports.getURLFromEvent = utils.getURLFromEvent;
90
92
  exports.isPayloadV1 = utils.isPayloadV1;
91
93
  exports.isPayloadV2 = utils.isPayloadV2;
92
94
  exports.transformHeaders = utils.transformHeaders;
@@ -1,7 +1,7 @@
1
1
  import { TRPCError } from '../../unstable-core-do-not-import/error/TRPCError.mjs';
2
- import { resolveHTTPResponse } from '../../unstable-core-do-not-import/http/resolveHTTPResponse.mjs';
2
+ import { resolveResponse } from '../../unstable-core-do-not-import/http/resolveResponse.mjs';
3
3
  import '../../unstable-core-do-not-import/rootConfig.mjs';
4
- import { getPath, getHTTPMethod, isPayloadV1, transformHeaders, isPayloadV2, UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE } from './utils.mjs';
4
+ import { getPath, getURLFromEvent, getHTTPMethod, isPayloadV1, transformHeaders, isPayloadV2, UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE } from './utils.mjs';
5
5
 
6
6
  /**
7
7
  * If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`
@@ -12,41 +12,42 @@ import { getPath, getHTTPMethod, isPayloadV1, transformHeaders, isPayloadV2, UNK
12
12
  * import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
13
13
  * ```
14
14
  */ // @trpc/server
15
- function lambdaEventToHTTPRequest(event) {
16
- const query = new URLSearchParams();
17
- for (const [key, value] of Object.entries(event.queryStringParameters ?? {})){
18
- if (typeof value !== 'undefined') {
19
- query.append(key, value);
20
- }
21
- }
15
+ function lambdaEventToRequest(event) {
22
16
  let body;
23
17
  if (event.body && event.isBase64Encoded) {
24
18
  body = Buffer.from(event.body, 'base64').toString('utf8');
25
19
  } else {
26
20
  body = event.body;
27
21
  }
28
- return {
29
- method: getHTTPMethod(event),
30
- query: query,
22
+ const url = getURLFromEvent(event);
23
+ const method = getHTTPMethod(event);
24
+ const init = {
31
25
  headers: event.headers,
32
- body: body
26
+ method,
27
+ // @ts-expect-error this is fine
28
+ duplex: 'half'
33
29
  };
30
+ if (method === 'POST') {
31
+ init.body = body;
32
+ }
33
+ const request = new Request(url, init);
34
+ return request;
34
35
  }
35
- function tRPCOutputToAPIGatewayOutput(event, response) {
36
+ async function tRPCOutputToAPIGatewayOutput(event, response) {
36
37
  if (isPayloadV1(event)) {
37
- const resp = {
38
+ const result = {
38
39
  statusCode: response.status,
39
- body: response.body ?? '',
40
- headers: transformHeaders(response.headers ?? {})
40
+ body: await response.text(),
41
+ headers: transformHeaders(response.headers)
41
42
  };
42
- return resp;
43
+ return result;
43
44
  } else if (isPayloadV2(event)) {
44
- const resp1 = {
45
+ const resp = {
45
46
  statusCode: response.status,
46
- body: response.body ?? undefined,
47
- headers: transformHeaders(response.headers ?? {})
47
+ body: await response.text(),
48
+ headers: transformHeaders(response.headers)
48
49
  };
49
- return resp1;
50
+ return resp;
50
51
  } else {
51
52
  throw new TRPCError({
52
53
  code: 'INTERNAL_SERVER_ERROR',
@@ -56,7 +57,7 @@ function tRPCOutputToAPIGatewayOutput(event, response) {
56
57
  }
57
58
  function awsLambdaRequestHandler(opts) {
58
59
  return async (event, context)=>{
59
- const req = lambdaEventToHTTPRequest(event);
60
+ const req = lambdaEventToRequest(event);
60
61
  const path = getPath(event);
61
62
  const createContext = async (innerOpts)=>{
62
63
  return await opts.createContext?.({
@@ -65,7 +66,7 @@ function awsLambdaRequestHandler(opts) {
65
66
  ...innerOpts
66
67
  });
67
68
  };
68
- const response = await resolveHTTPResponse({
69
+ const response = await resolveResponse({
69
70
  ...opts,
70
71
  createContext,
71
72
  req,
@@ -78,8 +79,8 @@ function awsLambdaRequestHandler(opts) {
78
79
  });
79
80
  }
80
81
  });
81
- return tRPCOutputToAPIGatewayOutput(event, response);
82
+ return await tRPCOutputToAPIGatewayOutput(event, response);
82
83
  };
83
84
  }
84
85
 
85
- export { UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE, awsLambdaRequestHandler, getHTTPMethod, getPath, isPayloadV1, isPayloadV2, transformHeaders };
86
+ export { UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE, awsLambdaRequestHandler, getHTTPMethod, getPath, getURLFromEvent, isPayloadV1, isPayloadV2, transformHeaders };
@@ -9,7 +9,7 @@
9
9
  */
10
10
  import type { APIGatewayProxyEvent, APIGatewayProxyEventV2, APIGatewayProxyResult, APIGatewayProxyStructuredResultV2, Context as APIGWContext } from 'aws-lambda';
11
11
  import type { AnyRouter, inferRouterContext } from '../../@trpc/server';
12
- import type { HTTPBaseHandlerOptions, HTTPHeaders, TRPCRequestInfo } from '../../@trpc/server/http';
12
+ import type { HTTPBaseHandlerOptions, TRPCRequestInfo } from '../../@trpc/server/http';
13
13
  export type APIGatewayEvent = APIGatewayProxyEvent | APIGatewayProxyEventV2;
14
14
  export type APIGatewayResult = APIGatewayProxyResult | APIGatewayProxyStructuredResultV2;
15
15
  export type CreateAWSLambdaContextOptions<TEvent extends APIGatewayEvent> = {
@@ -33,7 +33,8 @@ export declare function isPayloadV1(event: APIGatewayEvent): event is APIGateway
33
33
  export declare function isPayloadV2(event: APIGatewayEvent): event is APIGatewayProxyEventV2;
34
34
  export declare function getHTTPMethod(event: APIGatewayEvent): string;
35
35
  export declare function getPath(event: APIGatewayEvent): string;
36
- export declare function transformHeaders(headers: HTTPHeaders): APIGatewayResult['headers'];
36
+ export declare function getURLFromEvent(event: APIGatewayEvent): URL;
37
+ export declare function transformHeaders(headers: Request['headers']): APIGatewayResult['headers'];
37
38
  export type DefinedAPIGatewayPayloadFormats = '1.0' | '2.0';
38
39
  export type APIGatewayPayloadFormatVersion = DefinedAPIGatewayPayloadFormats | 'custom';
39
40
  export declare const UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE: string;
@@ -1 +1 @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CAAC,EACH,KAAK,EACL,OAAO,EACP,IAAI,GACL,EAAE,6BAA6B,CAAC,MAAM,CAAC,KACpC,kBAAkB,CAAC,OAAO,CAAC,GAC3B,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC;AAEzC,MAAM,MAAM,gBAAgB,CAC1B,OAAO,SAAS,SAAS,EACzB,MAAM,SAAS,eAAe,IAE5B,sBAAsB,CAAC,OAAO,EAAE,MAAM,CAAC,GACrC,CACI;IACE;;QAEI;IACJ,aAAa,EAAE,wBAAwB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;CAC1D,GACD;IACE;;QAEI;IACJ,aAAa,CAAC,EAAE,wBAAwB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;CAC3D,CACJ,CAAC;AAER,wBAAgB,WAAW,CACzB,KAAK,EAAE,eAAe,GACrB,KAAK,IAAI,oBAAoB,CAE/B;AACD,wBAAgB,WAAW,CACzB,KAAK,EAAE,eAAe,GACrB,KAAK,IAAI,sBAAsB,CAEjC;AAoBD,wBAAgB,aAAa,CAAC,KAAK,EAAE,eAAe,UAWnD;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,eAAe,UA+B7C;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,eAAe,GAAG,GAAG,CAiC3D;AAED,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC,GAC1B,gBAAgB,CAAC,SAAS,CAAC,CAU7B;AAED,MAAM,MAAM,+BAA+B,GAAG,KAAK,GAAG,KAAK,CAAC;AAC5D,MAAM,MAAM,8BAA8B,GACtC,+BAA+B,GAC/B,QAAQ,CAAC;AAEb,eAAO,MAAM,4CAA4C,QAEiD,CAAC"}
@@ -80,9 +80,32 @@ function getPath(event) {
80
80
  message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
81
81
  });
82
82
  }
83
+ function getURLFromEvent(event) {
84
+ const path = getPath(event);
85
+ const searchParams = new URLSearchParams();
86
+ for (const [key, value] of Object.entries(event.queryStringParameters ?? {})){
87
+ if (typeof value !== 'undefined') {
88
+ searchParams.append(key, value);
89
+ }
90
+ }
91
+ if (isPayloadV1(event)) {
92
+ const hostname = event.requestContext.domainName ?? 'localhost';
93
+ const protocol = 'http';
94
+ return new URL(`${protocol}://${hostname}${path}?${searchParams.toString()}`);
95
+ }
96
+ if (isPayloadV2(event)) {
97
+ const hostname1 = event.requestContext.domainName;
98
+ const protocol1 = event.requestContext.http.protocol;
99
+ return new URL(`${protocol1}://${hostname1}${path}?${searchParams.toString()}`);
100
+ }
101
+ throw new TRPCError.TRPCError({
102
+ code: 'INTERNAL_SERVER_ERROR',
103
+ message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
104
+ });
105
+ }
83
106
  function transformHeaders(headers) {
84
107
  const obj = {};
85
- for (const [key, value] of Object.entries(headers)){
108
+ for (const [key, value] of headers){
86
109
  if (typeof value === 'undefined') {
87
110
  continue;
88
111
  }
@@ -95,6 +118,7 @@ const UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE = 'Custom payload format vers
95
118
  exports.UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE = UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE;
96
119
  exports.getHTTPMethod = getHTTPMethod;
97
120
  exports.getPath = getPath;
121
+ exports.getURLFromEvent = getURLFromEvent;
98
122
  exports.isPayloadV1 = isPayloadV1;
99
123
  exports.isPayloadV2 = isPayloadV2;
100
124
  exports.transformHeaders = transformHeaders;
@@ -78,9 +78,32 @@ function getPath(event) {
78
78
  message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
79
79
  });
80
80
  }
81
+ function getURLFromEvent(event) {
82
+ const path = getPath(event);
83
+ const searchParams = new URLSearchParams();
84
+ for (const [key, value] of Object.entries(event.queryStringParameters ?? {})){
85
+ if (typeof value !== 'undefined') {
86
+ searchParams.append(key, value);
87
+ }
88
+ }
89
+ if (isPayloadV1(event)) {
90
+ const hostname = event.requestContext.domainName ?? 'localhost';
91
+ const protocol = 'http';
92
+ return new URL(`${protocol}://${hostname}${path}?${searchParams.toString()}`);
93
+ }
94
+ if (isPayloadV2(event)) {
95
+ const hostname1 = event.requestContext.domainName;
96
+ const protocol1 = event.requestContext.http.protocol;
97
+ return new URL(`${protocol1}://${hostname1}${path}?${searchParams.toString()}`);
98
+ }
99
+ throw new TRPCError({
100
+ code: 'INTERNAL_SERVER_ERROR',
101
+ message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
102
+ });
103
+ }
81
104
  function transformHeaders(headers) {
82
105
  const obj = {};
83
- for (const [key, value] of Object.entries(headers)){
106
+ for (const [key, value] of headers){
84
107
  if (typeof value === 'undefined') {
85
108
  continue;
86
109
  }
@@ -90,4 +113,4 @@ function transformHeaders(headers) {
90
113
  }
91
114
  const UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE = 'Custom payload format version not handled by this adapter. Please use either 1.0 or 2.0. More information here' + 'https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html';
92
115
 
93
- export { UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE, getHTTPMethod, getPath, isPayloadV1, isPayloadV2, transformHeaders };
116
+ export { UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE, getHTTPMethod, getPath, getURLFromEvent, isPayloadV1, isPayloadV2, transformHeaders };
@@ -1,3 +1,12 @@
1
+ /**
2
+ * If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import type { AnyTRPCRouter } from '@trpc/server'
7
+ * import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
8
+ * ```
9
+ */
1
10
  import type { FastifyReply, FastifyRequest } from 'fastify';
2
11
  import type { AnyRouter } from '../../@trpc/server';
3
12
  import type { HTTPBaseHandlerOptions } from '../../@trpc/server/http';
@@ -8,6 +17,6 @@ type FastifyRequestHandlerOptions<TRouter extends AnyRouter, TRequest extends Fa
8
17
  res: TResponse;
9
18
  path: string;
10
19
  };
11
- export declare function fastifyRequestHandler<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply>(opts: FastifyRequestHandlerOptions<TRouter, TRequest, TResponse>): Promise<never>;
20
+ export declare function fastifyRequestHandler<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply>(opts: FastifyRequestHandlerOptions<TRouter, TRequest, TResponse>): Promise<void>;
12
21
  export {};
13
22
  //# sourceMappingURL=fastifyRequestHandler.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fastifyRequestHandler.d.ts","sourceRoot":"","sources":["../../../src/adapters/fastify/fastifyRequestHandler.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EACV,sBAAsB,EAKvB,MAAM,yBAAyB,CAAC;AAKjC,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAEhE,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,IA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 -1,9 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var node_stream = require('node:stream');
4
- var resolveHTTPResponse = require('../../unstable-core-do-not-import/http/resolveHTTPResponse.js');
5
- var batchStreamFormatter = require('../../unstable-core-do-not-import/http/batchStreamFormatter.js');
3
+ var resolveResponse = require('../../unstable-core-do-not-import/http/resolveResponse.js');
6
4
  require('../../unstable-core-do-not-import/rootConfig.js');
5
+ var nodeHTTPRequestHandler = require('../node-http/nodeHTTPRequestHandler.js');
7
6
 
8
7
  async function fastifyRequestHandler(opts) {
9
8
  const createContext = async (innerOpts)=>{
@@ -12,69 +11,27 @@ async function fastifyRequestHandler(opts) {
12
11
  ...innerOpts
13
12
  });
14
13
  };
15
- const query = opts.req.query ? new URLSearchParams(opts.req.query) : new URLSearchParams(opts.req.url.split('?')[1]);
16
- const req = {
17
- query,
18
- method: opts.req.method,
19
- headers: opts.req.headers,
20
- body: opts.req.body ?? 'null'
21
- };
22
- let resolve;
23
- const promise = new Promise((r)=>resolve = r);
24
- let isStream = false;
25
- let stream;
26
- let formatter;
27
- const unstable_onHead = (head, isStreaming)=>{
28
- if (!opts.res.statusCode || opts.res.statusCode === 200) {
29
- opts.res.statusCode = head.status;
30
- }
31
- for (const [key, value] of Object.entries(head.headers ?? {})){
32
- /* istanbul ignore if -- @preserve */ if (typeof value === 'undefined') {
33
- continue;
34
- }
35
- void opts.res.header(key, value);
36
- }
37
- if (isStreaming) {
38
- void opts.res.header('Transfer-Encoding', 'chunked');
39
- void opts.res.header('Vary', opts.res.hasHeader('Vary') ? 'trpc-batch-mode, ' + opts.res.getHeader('Vary') : 'trpc-batch-mode');
40
- stream = new node_stream.Readable();
41
- stream._read = ()=>{}; // eslint-disable-line @typescript-eslint/no-empty-function -- https://github.com/fastify/fastify/issues/805#issuecomment-369172154
42
- resolve(opts.res.send(stream));
43
- isStream = true;
44
- formatter = batchStreamFormatter.getBatchStreamFormatter();
45
- }
46
- };
47
- const unstable_onChunk = ([index, string])=>{
48
- if (index === -1) {
49
- // full response, no streaming
50
- resolve(opts.res.send(string));
51
- } else {
52
- stream.push(formatter(index, string));
53
- }
54
- };
55
- resolveHTTPResponse.resolveHTTPResponse({
14
+ const incomingMessage = opts.req.raw;
15
+ // monkey-path body to the IncomingMessage
16
+ if ('body' in opts.req) {
17
+ incomingMessage.body = opts.req.body;
18
+ }
19
+ const req = nodeHTTPRequestHandler.incomingMessageToRequest(incomingMessage, {
20
+ maxBodySize: null
21
+ });
22
+ const res = await resolveResponse.resolveResponse({
56
23
  ...opts,
57
24
  req,
25
+ error: null,
58
26
  createContext,
59
27
  onError (o) {
60
28
  opts?.onError?.({
61
29
  ...o,
62
30
  req: opts.req
63
31
  });
64
- },
65
- unstable_onHead,
66
- unstable_onChunk
67
- }).then(()=>{
68
- if (isStream) {
69
- stream.push(formatter.end());
70
- stream.push(null); // https://github.com/fastify/fastify/issues/805#issuecomment-369172154
71
- }
72
- }).catch(()=>{
73
- if (isStream) {
74
- stream.push(null);
75
32
  }
76
33
  });
77
- return promise;
34
+ await opts.res.send(res);
78
35
  }
79
36
 
80
37
  exports.fastifyRequestHandler = fastifyRequestHandler;
@@ -1,7 +1,6 @@
1
- import { Readable } from 'node:stream';
2
- import { resolveHTTPResponse } from '../../unstable-core-do-not-import/http/resolveHTTPResponse.mjs';
3
- import { getBatchStreamFormatter } from '../../unstable-core-do-not-import/http/batchStreamFormatter.mjs';
1
+ import { resolveResponse } from '../../unstable-core-do-not-import/http/resolveResponse.mjs';
4
2
  import '../../unstable-core-do-not-import/rootConfig.mjs';
3
+ import { incomingMessageToRequest } from '../node-http/nodeHTTPRequestHandler.mjs';
5
4
 
6
5
  async function fastifyRequestHandler(opts) {
7
6
  const createContext = async (innerOpts)=>{
@@ -10,69 +9,27 @@ async function fastifyRequestHandler(opts) {
10
9
  ...innerOpts
11
10
  });
12
11
  };
13
- const query = opts.req.query ? new URLSearchParams(opts.req.query) : new URLSearchParams(opts.req.url.split('?')[1]);
14
- const req = {
15
- query,
16
- method: opts.req.method,
17
- headers: opts.req.headers,
18
- body: opts.req.body ?? 'null'
19
- };
20
- let resolve;
21
- const promise = new Promise((r)=>resolve = r);
22
- let isStream = false;
23
- let stream;
24
- let formatter;
25
- const unstable_onHead = (head, isStreaming)=>{
26
- if (!opts.res.statusCode || opts.res.statusCode === 200) {
27
- opts.res.statusCode = head.status;
28
- }
29
- for (const [key, value] of Object.entries(head.headers ?? {})){
30
- /* istanbul ignore if -- @preserve */ if (typeof value === 'undefined') {
31
- continue;
32
- }
33
- void opts.res.header(key, value);
34
- }
35
- if (isStreaming) {
36
- void opts.res.header('Transfer-Encoding', 'chunked');
37
- void opts.res.header('Vary', opts.res.hasHeader('Vary') ? 'trpc-batch-mode, ' + opts.res.getHeader('Vary') : 'trpc-batch-mode');
38
- stream = new Readable();
39
- stream._read = ()=>{}; // eslint-disable-line @typescript-eslint/no-empty-function -- https://github.com/fastify/fastify/issues/805#issuecomment-369172154
40
- resolve(opts.res.send(stream));
41
- isStream = true;
42
- formatter = getBatchStreamFormatter();
43
- }
44
- };
45
- const unstable_onChunk = ([index, string])=>{
46
- if (index === -1) {
47
- // full response, no streaming
48
- resolve(opts.res.send(string));
49
- } else {
50
- stream.push(formatter(index, string));
51
- }
52
- };
53
- resolveHTTPResponse({
12
+ const incomingMessage = opts.req.raw;
13
+ // monkey-path body to the IncomingMessage
14
+ if ('body' in opts.req) {
15
+ incomingMessage.body = opts.req.body;
16
+ }
17
+ const req = incomingMessageToRequest(incomingMessage, {
18
+ maxBodySize: null
19
+ });
20
+ const res = await resolveResponse({
54
21
  ...opts,
55
22
  req,
23
+ error: null,
56
24
  createContext,
57
25
  onError (o) {
58
26
  opts?.onError?.({
59
27
  ...o,
60
28
  req: opts.req
61
29
  });
62
- },
63
- unstable_onHead,
64
- unstable_onChunk
65
- }).then(()=>{
66
- if (isStream) {
67
- stream.push(formatter.end());
68
- stream.push(null); // https://github.com/fastify/fastify/issues/805#issuecomment-369172154
69
- }
70
- }).catch(()=>{
71
- if (isStream) {
72
- stream.push(null);
73
30
  }
74
31
  });
75
- return promise;
32
+ await opts.res.send(res);
76
33
  }
77
34
 
78
35
  export { fastifyRequestHandler };
@@ -1 +1 @@
1
- {"version":3,"file":"fetchRequestHandler.d.ts","sourceRoot":"","sources":["../../../src/adapters/fetch/fetchRequestHandler.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAYpD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEnD,MAAM,MAAM,0BAA0B,CAAC,OAAO,SAAS,SAAS,IAC9D,mBAAmB,CAAC,OAAO,CAAC,GAAG;IAC7B,GAAG,EAAE,OAAO,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AASJ,wBAAsB,mBAAmB,CAAC,OAAO,SAAS,SAAS,EACjE,IAAI,EAAE,0BAA0B,CAAC,OAAO,CAAC,GACxC,OAAO,CAAC,QAAQ,CAAC,CAuGnB"}
1
+ {"version":3,"file":"fetchRequestHandler.d.ts","sourceRoot":"","sources":["../../../src/adapters/fetch/fetchRequestHandler.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAGpD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEnD,MAAM,MAAM,0BAA0B,CAAC,OAAO,SAAS,SAAS,IAC9D,mBAAmB,CAAC,OAAO,CAAC,GAAG;IAC7B,GAAG,EAAE,OAAO,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AASJ,wBAAsB,mBAAmB,CAAC,OAAO,SAAS,SAAS,EACjE,IAAI,EAAE,0BAA0B,CAAC,OAAO,CAAC,GACxC,OAAO,CAAC,QAAQ,CAAC,CAuCnB"}