@trpc/server 11.0.0-next.92 → 11.0.0-rc.329

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 (469) hide show
  1. package/README.md +6 -6
  2. package/adapters/next-app-dir/index.d.ts +1 -0
  3. package/adapters/next-app-dir/index.js +1 -0
  4. package/dist/@trpc/server/http.d.ts +8 -0
  5. package/dist/@trpc/server/http.d.ts.map +1 -0
  6. package/dist/@trpc/server/index.d.ts +61 -0
  7. package/dist/@trpc/server/index.d.ts.map +1 -0
  8. package/dist/@trpc/server/rpc.d.ts +3 -0
  9. package/dist/@trpc/server/rpc.d.ts.map +1 -0
  10. package/dist/adapters/aws-lambda/index.d.ts +11 -2
  11. package/dist/adapters/aws-lambda/index.d.ts.map +1 -1
  12. package/dist/adapters/aws-lambda/index.js +28 -106
  13. package/dist/adapters/aws-lambda/index.mjs +15 -91
  14. package/dist/adapters/aws-lambda/utils.d.ts +14 -14
  15. package/dist/adapters/aws-lambda/utils.d.ts.map +1 -1
  16. package/dist/adapters/aws-lambda/utils.js +101 -0
  17. package/dist/adapters/aws-lambda/utils.mjs +94 -0
  18. package/dist/adapters/express.d.ts +11 -2
  19. package/dist/adapters/express.d.ts.map +1 -1
  20. package/dist/adapters/express.js +2 -14
  21. package/dist/adapters/express.mjs +2 -12
  22. package/dist/adapters/fastify/fastifyRequestHandler.d.ts +4 -4
  23. package/dist/adapters/fastify/fastifyRequestHandler.d.ts.map +1 -1
  24. package/dist/adapters/fastify/fastifyRequestHandler.js +81 -0
  25. package/dist/adapters/fastify/fastifyRequestHandler.mjs +79 -0
  26. package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts +13 -4
  27. package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts.map +1 -1
  28. package/dist/adapters/fastify/fastifyTRPCPlugin.js +48 -0
  29. package/dist/adapters/fastify/fastifyTRPCPlugin.mjs +46 -0
  30. package/dist/adapters/fastify/index.js +4 -126
  31. package/dist/adapters/fastify/index.mjs +2 -126
  32. package/dist/adapters/fetch/fetchRequestHandler.d.ts +11 -2
  33. package/dist/adapters/fetch/fetchRequestHandler.d.ts.map +1 -1
  34. package/dist/adapters/fetch/fetchRequestHandler.js +119 -0
  35. package/dist/adapters/fetch/fetchRequestHandler.mjs +117 -0
  36. package/dist/adapters/fetch/index.js +2 -106
  37. package/dist/adapters/fetch/index.mjs +1 -107
  38. package/dist/adapters/fetch/types.d.ts +13 -4
  39. package/dist/adapters/fetch/types.d.ts.map +1 -1
  40. package/dist/adapters/next-app-dir/formDataToObject.d.ts +2 -0
  41. package/dist/adapters/next-app-dir/formDataToObject.d.ts.map +1 -0
  42. package/dist/adapters/next-app-dir/formDataToObject.js +34 -0
  43. package/dist/adapters/next-app-dir/formDataToObject.mjs +32 -0
  44. package/dist/adapters/next-app-dir/nextAppDirCaller.d.ts +24 -0
  45. package/dist/adapters/next-app-dir/nextAppDirCaller.d.ts.map +1 -0
  46. package/dist/adapters/next-app-dir/nextAppDirCaller.js +86 -0
  47. package/dist/adapters/next-app-dir/nextAppDirCaller.mjs +84 -0
  48. package/dist/adapters/next-app-dir/notFound.d.ts +7 -0
  49. package/dist/adapters/next-app-dir/notFound.d.ts.map +1 -0
  50. package/dist/adapters/next-app-dir/notFound.js +16 -0
  51. package/dist/adapters/next-app-dir/notFound.mjs +14 -0
  52. package/dist/adapters/next-app-dir/redirect.d.ts +18 -0
  53. package/dist/adapters/next-app-dir/redirect.d.ts.map +1 -0
  54. package/dist/adapters/next-app-dir/redirect.js +34 -0
  55. package/dist/adapters/next-app-dir/redirect.mjs +31 -0
  56. package/dist/adapters/next-app-dir/rethrowNextErrors.d.ts +6 -0
  57. package/dist/adapters/next-app-dir/rethrowNextErrors.d.ts.map +1 -0
  58. package/dist/adapters/next-app-dir/rethrowNextErrors.js +23 -0
  59. package/dist/adapters/next-app-dir/rethrowNextErrors.mjs +21 -0
  60. package/dist/adapters/next-app-dir.d.ts +4 -0
  61. package/dist/adapters/next-app-dir.d.ts.map +1 -0
  62. package/dist/adapters/next-app-dir.js +11 -0
  63. package/dist/adapters/next-app-dir.mjs +3 -0
  64. package/dist/adapters/next.d.ts +16 -3
  65. package/dist/adapters/next.d.ts.map +1 -1
  66. package/dist/adapters/next.js +20 -19
  67. package/dist/adapters/next.mjs +19 -16
  68. package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.d.ts +6 -3
  69. package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.d.ts.map +1 -1
  70. package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.js +161 -0
  71. package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.mjs +157 -0
  72. package/dist/adapters/node-http/content-type/form-data/index.d.ts +6 -8
  73. package/dist/adapters/node-http/content-type/form-data/index.d.ts.map +1 -1
  74. package/dist/adapters/node-http/content-type/form-data/index.js +21 -647
  75. package/dist/adapters/node-http/content-type/form-data/index.mjs +10 -632
  76. package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.d.ts +2 -2
  77. package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.d.ts.map +1 -1
  78. package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.js +29 -0
  79. package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.mjs +27 -0
  80. package/dist/adapters/node-http/content-type/form-data/streamSlice.d.ts +2 -1
  81. package/dist/adapters/node-http/content-type/form-data/streamSlice.d.ts.map +1 -1
  82. package/dist/adapters/node-http/content-type/form-data/streamSlice.js +46 -0
  83. package/dist/adapters/node-http/content-type/form-data/streamSlice.mjs +44 -0
  84. package/dist/adapters/node-http/content-type/form-data/uploadHandler.d.ts +2 -2
  85. package/dist/adapters/node-http/content-type/form-data/uploadHandler.d.ts.map +1 -1
  86. package/dist/adapters/node-http/content-type/form-data/uploadHandler.js +30 -0
  87. package/dist/adapters/node-http/content-type/form-data/uploadHandler.mjs +26 -0
  88. package/dist/adapters/node-http/content-type/json/getPostBody.d.ts +2 -2
  89. package/dist/adapters/node-http/content-type/json/getPostBody.d.ts.map +1 -1
  90. package/dist/adapters/node-http/content-type/json/getPostBody.js +54 -0
  91. package/dist/adapters/node-http/content-type/json/getPostBody.mjs +52 -0
  92. package/dist/adapters/node-http/content-type/json/index.js +6 -42
  93. package/dist/adapters/node-http/content-type/json/index.mjs +5 -39
  94. package/dist/adapters/node-http/index.js +1 -14
  95. package/dist/adapters/node-http/index.mjs +1 -12
  96. package/dist/adapters/node-http/internals/contentType.d.ts +3 -3
  97. package/dist/adapters/node-http/internals/contentType.d.ts.map +1 -1
  98. package/dist/{contentType-8c16408e.js → adapters/node-http/internals/contentType.js} +1 -0
  99. package/dist/{contentType-3194ed5f.mjs → adapters/node-http/internals/contentType.mjs} +2 -1
  100. package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts +11 -2
  101. package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
  102. package/dist/{nodeHTTPRequestHandler-18f3370e.js → adapters/node-http/nodeHTTPRequestHandler.js} +19 -10
  103. package/dist/{nodeHTTPRequestHandler-0986c5a1.mjs → adapters/node-http/nodeHTTPRequestHandler.mjs} +19 -10
  104. package/dist/adapters/node-http/types.d.ts +18 -9
  105. package/dist/adapters/node-http/types.d.ts.map +1 -1
  106. package/dist/adapters/standalone.d.ts +11 -2
  107. package/dist/adapters/standalone.d.ts.map +1 -1
  108. package/dist/adapters/standalone.js +10 -22
  109. package/dist/adapters/standalone.mjs +10 -16
  110. package/dist/adapters/ws.d.ts +18 -17
  111. package/dist/adapters/ws.d.ts.map +1 -1
  112. package/dist/adapters/ws.js +35 -22
  113. package/dist/adapters/ws.mjs +28 -14
  114. package/dist/bundle-analysis.json +383 -493
  115. package/dist/http.d.ts +2 -0
  116. package/dist/http.d.ts.map +1 -0
  117. package/dist/http.js +18 -0
  118. package/dist/http.mjs +7 -0
  119. package/dist/index.d.ts +1 -14
  120. package/dist/index.d.ts.map +1 -1
  121. package/dist/index.js +17 -86
  122. package/dist/index.mjs +9 -81
  123. package/dist/observable/index.d.ts +4 -4
  124. package/dist/observable/index.d.ts.map +1 -1
  125. package/dist/observable/index.js +6 -149
  126. package/dist/observable/index.mjs +2 -147
  127. package/dist/observable/observable.d.ts +9 -1
  128. package/dist/observable/observable.d.ts.map +1 -1
  129. package/dist/{observable-464116ac.js → observable/observable.js} +50 -20
  130. package/dist/{observable-ade1bad8.mjs → observable/observable.mjs} +50 -21
  131. package/dist/observable/operators.d.ts +8 -0
  132. package/dist/observable/operators.d.ts.map +1 -0
  133. package/dist/observable/operators.js +99 -0
  134. package/dist/observable/operators.mjs +95 -0
  135. package/dist/observable/types.d.ts +2 -5
  136. package/dist/observable/types.d.ts.map +1 -1
  137. package/dist/rpc.d.ts +2 -0
  138. package/dist/rpc.d.ts.map +1 -0
  139. package/dist/rpc.js +12 -0
  140. package/dist/rpc.mjs +4 -0
  141. package/dist/shared.d.ts +26 -0
  142. package/dist/shared.d.ts.map +1 -0
  143. package/dist/shared.js +11 -0
  144. package/dist/shared.mjs +4 -0
  145. package/dist/unstable-core-do-not-import/clientish/inference.d.ts +17 -0
  146. package/dist/unstable-core-do-not-import/clientish/inference.d.ts.map +1 -0
  147. package/dist/unstable-core-do-not-import/clientish/inferrable.d.ts +32 -0
  148. package/dist/unstable-core-do-not-import/clientish/inferrable.d.ts.map +1 -0
  149. package/dist/unstable-core-do-not-import/clientish/serialize.d.ts +62 -0
  150. package/dist/unstable-core-do-not-import/clientish/serialize.d.ts.map +1 -0
  151. package/dist/{shared/createProxy/index.d.ts → unstable-core-do-not-import/createProxy.d.ts} +1 -1
  152. package/dist/unstable-core-do-not-import/createProxy.d.ts.map +1 -0
  153. package/dist/{index-784ff647.js → unstable-core-do-not-import/createProxy.js} +0 -51
  154. package/dist/unstable-core-do-not-import/createProxy.mjs +49 -0
  155. package/dist/{error → unstable-core-do-not-import/error}/TRPCError.d.ts +3 -2
  156. package/dist/unstable-core-do-not-import/error/TRPCError.d.ts.map +1 -0
  157. package/dist/{TRPCError-ae7b67e8.js → unstable-core-do-not-import/error/TRPCError.js} +25 -25
  158. package/dist/{TRPCError-816ff32e.mjs → unstable-core-do-not-import/error/TRPCError.mjs} +24 -25
  159. package/dist/{error → unstable-core-do-not-import/error}/formatter.d.ts +11 -6
  160. package/dist/unstable-core-do-not-import/error/formatter.d.ts.map +1 -0
  161. package/dist/unstable-core-do-not-import/error/formatter.js +7 -0
  162. package/dist/unstable-core-do-not-import/error/formatter.mjs +5 -0
  163. package/dist/unstable-core-do-not-import/error/getErrorShape.d.ts +15 -0
  164. package/dist/unstable-core-do-not-import/error/getErrorShape.d.ts.map +1 -0
  165. package/dist/unstable-core-do-not-import/error/getErrorShape.js +32 -0
  166. package/dist/unstable-core-do-not-import/error/getErrorShape.mjs +30 -0
  167. package/dist/unstable-core-do-not-import/http/batchStreamFormatter.d.ts.map +1 -0
  168. package/dist/{batchStreamFormatter-fc1ffb26.mjs → unstable-core-do-not-import/http/batchStreamFormatter.mjs} +1 -1
  169. package/dist/{http → unstable-core-do-not-import/http}/contentType.d.ts +3 -3
  170. package/dist/unstable-core-do-not-import/http/contentType.d.ts.map +1 -0
  171. package/dist/{contentType-90bad7bb.js → unstable-core-do-not-import/http/contentType.js} +1 -1
  172. package/dist/{contentType-93515a46.mjs → unstable-core-do-not-import/http/contentType.mjs} +2 -2
  173. package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts +5 -0
  174. package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts.map +1 -0
  175. package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.js +53 -0
  176. package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.mjs +50 -0
  177. package/dist/unstable-core-do-not-import/http/index.d.ts +12 -0
  178. package/dist/unstable-core-do-not-import/http/index.d.ts.map +1 -0
  179. package/dist/{http → unstable-core-do-not-import/http}/resolveHTTPResponse.d.ts +4 -5
  180. package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts.map +1 -0
  181. package/dist/{resolveHTTPResponse-5def1b0c.js → unstable-core-do-not-import/http/resolveHTTPResponse.js} +60 -63
  182. package/dist/{resolveHTTPResponse-55c648bd.mjs → unstable-core-do-not-import/http/resolveHTTPResponse.mjs} +54 -57
  183. package/dist/unstable-core-do-not-import/http/toURL.d.ts +2 -0
  184. package/dist/unstable-core-do-not-import/http/toURL.d.ts.map +1 -0
  185. package/dist/unstable-core-do-not-import/http/toURL.js +8 -0
  186. package/dist/unstable-core-do-not-import/http/toURL.mjs +6 -0
  187. package/dist/unstable-core-do-not-import/http/types.d.ts +109 -0
  188. package/dist/unstable-core-do-not-import/http/types.d.ts.map +1 -0
  189. package/dist/unstable-core-do-not-import/initTRPC.d.ts +102 -0
  190. package/dist/unstable-core-do-not-import/initTRPC.d.ts.map +1 -0
  191. package/dist/unstable-core-do-not-import/initTRPC.js +82 -0
  192. package/dist/unstable-core-do-not-import/initTRPC.mjs +80 -0
  193. package/dist/unstable-core-do-not-import/middleware.d.ts +106 -0
  194. package/dist/unstable-core-do-not-import/middleware.d.ts.map +1 -0
  195. package/dist/unstable-core-do-not-import/middleware.js +96 -0
  196. package/dist/unstable-core-do-not-import/middleware.mjs +90 -0
  197. package/dist/{core → unstable-core-do-not-import}/parser.d.ts +3 -7
  198. package/dist/unstable-core-do-not-import/parser.d.ts.map +1 -0
  199. package/dist/unstable-core-do-not-import/parser.js +37 -0
  200. package/dist/unstable-core-do-not-import/parser.mjs +35 -0
  201. package/dist/{core → unstable-core-do-not-import}/procedure.d.ts +26 -27
  202. package/dist/unstable-core-do-not-import/procedure.d.ts.map +1 -0
  203. package/dist/unstable-core-do-not-import/procedure.js +9 -0
  204. package/dist/unstable-core-do-not-import/procedure.mjs +7 -0
  205. package/dist/unstable-core-do-not-import/procedureBuilder.d.ts +134 -0
  206. package/dist/unstable-core-do-not-import/procedureBuilder.d.ts.map +1 -0
  207. package/dist/unstable-core-do-not-import/procedureBuilder.js +204 -0
  208. package/dist/unstable-core-do-not-import/procedureBuilder.mjs +201 -0
  209. package/dist/{core/internals/config.d.ts → unstable-core-do-not-import/rootConfig.d.ts} +19 -27
  210. package/dist/unstable-core-do-not-import/rootConfig.d.ts.map +1 -0
  211. package/dist/unstable-core-do-not-import/rootConfig.js +8 -0
  212. package/dist/unstable-core-do-not-import/rootConfig.mjs +6 -0
  213. package/dist/unstable-core-do-not-import/router.d.ts +81 -0
  214. package/dist/unstable-core-do-not-import/router.d.ts.map +1 -0
  215. package/dist/unstable-core-do-not-import/router.js +168 -0
  216. package/dist/unstable-core-do-not-import/router.mjs +163 -0
  217. package/dist/{rpc → unstable-core-do-not-import/rpc}/codes.d.ts +8 -16
  218. package/dist/unstable-core-do-not-import/rpc/codes.d.ts.map +1 -0
  219. package/dist/{codes-87f6824b.js → unstable-core-do-not-import/rpc/codes.js} +19 -13
  220. package/dist/{codes-c924c3db.mjs → unstable-core-do-not-import/rpc/codes.mjs} +20 -13
  221. package/dist/{rpc → unstable-core-do-not-import/rpc}/envelopes.d.ts +6 -4
  222. package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts.map +1 -0
  223. package/dist/unstable-core-do-not-import/rpc/index.d.ts +5 -0
  224. package/dist/unstable-core-do-not-import/rpc/index.d.ts.map +1 -0
  225. package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.d.ts.map +1 -0
  226. package/dist/{parseTRPCMessage-1377f305.js → unstable-core-do-not-import/rpc/parseTRPCMessage.js} +5 -2
  227. package/dist/{parseTRPCMessage-a0f17853.mjs → unstable-core-do-not-import/rpc/parseTRPCMessage.mjs} +6 -3
  228. package/dist/unstable-core-do-not-import/transformer.d.ts +101 -0
  229. package/dist/unstable-core-do-not-import/transformer.d.ts.map +1 -0
  230. package/dist/unstable-core-do-not-import/transformer.js +106 -0
  231. package/dist/unstable-core-do-not-import/transformer.mjs +101 -0
  232. package/dist/unstable-core-do-not-import/types.d.ts +103 -0
  233. package/dist/unstable-core-do-not-import/types.d.ts.map +1 -0
  234. package/dist/unstable-core-do-not-import/types.js +11 -0
  235. package/dist/unstable-core-do-not-import/types.mjs +9 -0
  236. package/dist/unstable-core-do-not-import/utils.d.ts +24 -0
  237. package/dist/unstable-core-do-not-import/utils.d.ts.map +1 -0
  238. package/dist/unstable-core-do-not-import/utils.js +46 -0
  239. package/dist/unstable-core-do-not-import/utils.mjs +40 -0
  240. package/dist/unstable-core-do-not-import.d.ts +31 -0
  241. package/dist/unstable-core-do-not-import.d.ts.map +1 -0
  242. package/dist/unstable-core-do-not-import.js +67 -0
  243. package/dist/unstable-core-do-not-import.mjs +21 -0
  244. package/package.json +51 -69
  245. package/src/@trpc/server/http.ts +27 -0
  246. package/src/@trpc/server/index.ts +100 -0
  247. package/src/@trpc/server/rpc.ts +26 -0
  248. package/src/adapters/aws-lambda/index.ts +21 -10
  249. package/src/adapters/aws-lambda/utils.ts +33 -26
  250. package/src/adapters/express.ts +18 -4
  251. package/src/adapters/fastify/fastifyRequestHandler.ts +22 -12
  252. package/src/adapters/fastify/fastifyTRPCPlugin.ts +21 -9
  253. package/src/adapters/fetch/fetchRequestHandler.ts +36 -12
  254. package/src/adapters/fetch/types.ts +18 -4
  255. package/src/adapters/next-app-dir/formDataToObject.ts +36 -0
  256. package/src/adapters/next-app-dir/nextAppDirCaller.ts +129 -0
  257. package/src/adapters/next-app-dir/notFound.ts +12 -0
  258. package/src/adapters/next-app-dir/redirect.ts +30 -0
  259. package/src/adapters/next-app-dir/rethrowNextErrors.ts +25 -0
  260. package/src/adapters/next-app-dir.ts +3 -0
  261. package/src/adapters/next.ts +30 -14
  262. package/src/adapters/node-http/content-type/form-data/fileUploadHandler.ts +11 -4
  263. package/src/adapters/node-http/content-type/form-data/index.ts +18 -18
  264. package/src/adapters/node-http/content-type/form-data/memoryUploadHandler.ts +3 -2
  265. package/src/adapters/node-http/content-type/form-data/streamSlice.ts +7 -2
  266. package/src/adapters/node-http/content-type/form-data/uploadHandler.ts +2 -2
  267. package/src/adapters/node-http/content-type/json/getPostBody.ts +20 -3
  268. package/src/adapters/node-http/content-type/json/index.ts +1 -1
  269. package/src/adapters/node-http/internals/contentType.ts +5 -3
  270. package/src/adapters/node-http/nodeHTTPRequestHandler.ts +28 -16
  271. package/src/adapters/node-http/types.ts +24 -9
  272. package/src/adapters/standalone.ts +22 -8
  273. package/src/adapters/ws.ts +68 -39
  274. package/src/http.ts +1 -0
  275. package/src/index.ts +1 -20
  276. package/src/observable/index.ts +10 -4
  277. package/src/observable/observable.ts +63 -3
  278. package/src/observable/operators.ts +114 -0
  279. package/src/observable/types.ts +1 -5
  280. package/src/rpc.ts +1 -0
  281. package/src/shared.ts +26 -0
  282. package/src/unstable-core-do-not-import/clientish/inference.ts +60 -0
  283. package/src/unstable-core-do-not-import/clientish/inferrable.ts +49 -0
  284. package/src/unstable-core-do-not-import/clientish/serialize.ts +122 -0
  285. package/src/{error → unstable-core-do-not-import/error}/TRPCError.ts +33 -27
  286. package/src/{error → unstable-core-do-not-import/error}/formatter.ts +12 -19
  287. package/src/{shared → unstable-core-do-not-import/error}/getErrorShape.ts +8 -8
  288. package/src/{http → unstable-core-do-not-import/http}/contentType.ts +4 -4
  289. package/src/{http → unstable-core-do-not-import/http}/getHTTPStatusCode.ts +8 -8
  290. package/src/unstable-core-do-not-import/http/index.ts +29 -0
  291. package/src/{http → unstable-core-do-not-import/http}/resolveHTTPResponse.ts +69 -69
  292. package/src/unstable-core-do-not-import/http/toURL.ts +7 -0
  293. package/src/unstable-core-do-not-import/http/types.ts +126 -0
  294. package/src/unstable-core-do-not-import/initTRPC.ts +152 -0
  295. package/src/unstable-core-do-not-import/middleware.ts +238 -0
  296. package/src/unstable-core-do-not-import/parser.ts +94 -0
  297. package/src/{core → unstable-core-do-not-import}/procedure.ts +37 -35
  298. package/src/unstable-core-do-not-import/procedureBuilder.ts +623 -0
  299. package/src/{core/internals/config.ts → unstable-core-do-not-import/rootConfig.ts} +22 -33
  300. package/src/unstable-core-do-not-import/router.ts +363 -0
  301. package/src/{rpc → unstable-core-do-not-import/rpc}/codes.ts +30 -3
  302. package/src/{rpc → unstable-core-do-not-import/rpc}/envelopes.ts +6 -9
  303. package/src/unstable-core-do-not-import/rpc/index.ts +21 -0
  304. package/src/{rpc → unstable-core-do-not-import/rpc}/parseTRPCMessage.ts +4 -3
  305. package/src/unstable-core-do-not-import/transformer.ts +194 -0
  306. package/src/unstable-core-do-not-import/types.ts +157 -0
  307. package/src/unstable-core-do-not-import/utils.ts +55 -0
  308. package/src/unstable-core-do-not-import.ts +30 -0
  309. package/unstable-core-do-not-import/index.d.ts +1 -0
  310. package/unstable-core-do-not-import/index.js +1 -0
  311. package/dist/TRPCError-efecb077.js +0 -63
  312. package/dist/batchStreamFormatter-2c1405a1.js +0 -31
  313. package/dist/codes-e5bb4d58.js +0 -48
  314. package/dist/config-5de7eae5.js +0 -10
  315. package/dist/config-60fc2667.js +0 -7
  316. package/dist/config-ab4c1c6b.mjs +0 -5
  317. package/dist/contentType-24c44bba.js +0 -5
  318. package/dist/contentType-9940f5d7.js +0 -58
  319. package/dist/core/index.d.ts +0 -9
  320. package/dist/core/index.d.ts.map +0 -1
  321. package/dist/core/initTRPC.d.ts +0 -105
  322. package/dist/core/initTRPC.d.ts.map +0 -1
  323. package/dist/core/internals/builderTypes.d.ts +0 -11
  324. package/dist/core/internals/builderTypes.d.ts.map +0 -1
  325. package/dist/core/internals/config.d.ts.map +0 -1
  326. package/dist/core/internals/getParseFn.d.ts +0 -4
  327. package/dist/core/internals/getParseFn.d.ts.map +0 -1
  328. package/dist/core/internals/mergeRouters.d.ts +0 -15
  329. package/dist/core/internals/mergeRouters.d.ts.map +0 -1
  330. package/dist/core/internals/mergeWithoutOverrides.d.ts +0 -5
  331. package/dist/core/internals/mergeWithoutOverrides.d.ts.map +0 -1
  332. package/dist/core/internals/omitPrototype.d.ts +0 -6
  333. package/dist/core/internals/omitPrototype.d.ts.map +0 -1
  334. package/dist/core/internals/procedureBuilder.d.ts +0 -113
  335. package/dist/core/internals/procedureBuilder.d.ts.map +0 -1
  336. package/dist/core/internals/utils.d.ts +0 -51
  337. package/dist/core/internals/utils.d.ts.map +0 -1
  338. package/dist/core/middleware.d.ts +0 -158
  339. package/dist/core/middleware.d.ts.map +0 -1
  340. package/dist/core/parser.d.ts.map +0 -1
  341. package/dist/core/procedure.d.ts.map +0 -1
  342. package/dist/core/router.d.ts +0 -65
  343. package/dist/core/router.d.ts.map +0 -1
  344. package/dist/core/types.d.ts +0 -24
  345. package/dist/core/types.d.ts.map +0 -1
  346. package/dist/error/TRPCError.d.ts.map +0 -1
  347. package/dist/error/formatter.d.ts.map +0 -1
  348. package/dist/error/utils.d.ts +0 -9
  349. package/dist/error/utils.d.ts.map +0 -1
  350. package/dist/http/batchStreamFormatter.d.ts.map +0 -1
  351. package/dist/http/contentType.d.ts.map +0 -1
  352. package/dist/http/getHTTPStatusCode.d.ts +0 -24
  353. package/dist/http/getHTTPStatusCode.d.ts.map +0 -1
  354. package/dist/http/index.d.ts +0 -5
  355. package/dist/http/index.d.ts.map +0 -1
  356. package/dist/http/index.js +0 -21
  357. package/dist/http/index.mjs +0 -9
  358. package/dist/http/internals/types.d.ts +0 -32
  359. package/dist/http/internals/types.d.ts.map +0 -1
  360. package/dist/http/resolveHTTPResponse.d.ts.map +0 -1
  361. package/dist/http/types.d.ts +0 -46
  362. package/dist/http/types.d.ts.map +0 -1
  363. package/dist/index-46cb3130.js +0 -94
  364. package/dist/index-f91d720c.mjs +0 -97
  365. package/dist/internals/invert.d.ts +0 -12
  366. package/dist/internals/invert.d.ts.map +0 -1
  367. package/dist/internals/types.d.ts +0 -26
  368. package/dist/internals/types.d.ts.map +0 -1
  369. package/dist/nodeHTTPRequestHandler-388f5fce.js +0 -107
  370. package/dist/observable/internals/identity.d.ts +0 -2
  371. package/dist/observable/internals/identity.d.ts.map +0 -1
  372. package/dist/observable/internals/observableToPromise.d.ts +0 -10
  373. package/dist/observable/internals/observableToPromise.d.ts.map +0 -1
  374. package/dist/observable/internals/pipe.d.ts +0 -4
  375. package/dist/observable/internals/pipe.d.ts.map +0 -1
  376. package/dist/observable/operators/index.d.ts +0 -4
  377. package/dist/observable/operators/index.d.ts.map +0 -1
  378. package/dist/observable/operators/map.d.ts +0 -3
  379. package/dist/observable/operators/map.d.ts.map +0 -1
  380. package/dist/observable/operators/share.d.ts +0 -6
  381. package/dist/observable/operators/share.d.ts.map +0 -1
  382. package/dist/observable/operators/tap.d.ts +0 -3
  383. package/dist/observable/operators/tap.d.ts.map +0 -1
  384. package/dist/observable-15588f28.js +0 -83
  385. package/dist/parseTRPCMessage-95955211.js +0 -63
  386. package/dist/resolveHTTPResponse-8d474952.js +0 -267
  387. package/dist/router-3c22fe56.js +0 -159
  388. package/dist/router-5274e533.mjs +0 -153
  389. package/dist/router-a1635eab.js +0 -147
  390. package/dist/rpc/codes.d.ts.map +0 -1
  391. package/dist/rpc/envelopes.d.ts.map +0 -1
  392. package/dist/rpc/index.d.ts +0 -4
  393. package/dist/rpc/index.d.ts.map +0 -1
  394. package/dist/rpc/index.js +0 -12
  395. package/dist/rpc/index.mjs +0 -2
  396. package/dist/rpc/parseTRPCMessage.d.ts.map +0 -1
  397. package/dist/shared/createProxy/index.d.ts.map +0 -1
  398. package/dist/shared/getErrorShape.d.ts +0 -15
  399. package/dist/shared/getErrorShape.d.ts.map +0 -1
  400. package/dist/shared/index.d.ts +0 -7
  401. package/dist/shared/index.d.ts.map +0 -1
  402. package/dist/shared/index.js +0 -14
  403. package/dist/shared/index.mjs +0 -3
  404. package/dist/shared/internal/serialize.d.ts +0 -30
  405. package/dist/shared/internal/serialize.d.ts.map +0 -1
  406. package/dist/shared/jsonify.d.ts +0 -11
  407. package/dist/shared/jsonify.d.ts.map +0 -1
  408. package/dist/shared/transformTRPCResponse.d.ts +0 -9
  409. package/dist/shared/transformTRPCResponse.d.ts.map +0 -1
  410. package/dist/shared/types.d.ts +0 -6
  411. package/dist/shared/types.d.ts.map +0 -1
  412. package/dist/transformTRPCResponse-1153b421.mjs +0 -53
  413. package/dist/transformTRPCResponse-20ce3b68.js +0 -54
  414. package/dist/transformTRPCResponse-e65f34e9.js +0 -56
  415. package/dist/transformer.d.ts +0 -74
  416. package/dist/transformer.d.ts.map +0 -1
  417. package/dist/types.d.ts +0 -83
  418. package/dist/types.d.ts.map +0 -1
  419. package/dist/unstableInternalsExport-10cc2bae.mjs +0 -353
  420. package/dist/unstableInternalsExport-a064a7dd.js +0 -349
  421. package/dist/unstableInternalsExport-bf8496ea.js +0 -363
  422. package/dist/unstableInternalsExport.d.ts +0 -11
  423. package/dist/unstableInternalsExport.d.ts.map +0 -1
  424. package/dist/unstableInternalsExport.js +0 -16
  425. package/dist/unstableInternalsExport.mjs +0 -5
  426. package/src/core/index.ts +0 -28
  427. package/src/core/initTRPC.ts +0 -169
  428. package/src/core/internals/builderTypes.ts +0 -11
  429. package/src/core/internals/getParseFn.ts +0 -43
  430. package/src/core/internals/mergeRouters.ts +0 -90
  431. package/src/core/internals/mergeWithoutOverrides.ts +0 -19
  432. package/src/core/internals/omitPrototype.ts +0 -9
  433. package/src/core/internals/procedureBuilder.ts +0 -394
  434. package/src/core/internals/utils.ts +0 -84
  435. package/src/core/middleware.ts +0 -295
  436. package/src/core/parser.ts +0 -57
  437. package/src/core/router.ts +0 -226
  438. package/src/core/types.ts +0 -67
  439. package/src/error/utils.ts +0 -23
  440. package/src/http/index.ts +0 -4
  441. package/src/http/internals/types.ts +0 -40
  442. package/src/http/types.ts +0 -51
  443. package/src/internals/invert.ts +0 -21
  444. package/src/internals/types.ts +0 -27
  445. package/src/observable/internals/identity.ts +0 -3
  446. package/src/observable/internals/observableToPromise.ts +0 -49
  447. package/src/observable/internals/pipe.ts +0 -23
  448. package/src/observable/operators/index.ts +0 -3
  449. package/src/observable/operators/map.ts +0 -25
  450. package/src/observable/operators/share.ts +0 -65
  451. package/src/observable/operators/tap.ts +0 -26
  452. package/src/rpc/index.ts +0 -3
  453. package/src/shared/index.ts +0 -10
  454. package/src/shared/internal/serialize.ts +0 -65
  455. package/src/shared/jsonify.ts +0 -22
  456. package/src/shared/transformTRPCResponse.ts +0 -40
  457. package/src/shared/types.ts +0 -9
  458. package/src/transformer.ts +0 -94
  459. package/src/types.ts +0 -125
  460. package/src/unstableInternalsExport.ts +0 -10
  461. package/subscription/index.d.ts +0 -1
  462. package/subscription/index.js +0 -1
  463. package/unstableInternalsExport/index.d.ts +0 -1
  464. package/unstableInternalsExport/index.js +0 -1
  465. /package/dist/{http → unstable-core-do-not-import/http}/batchStreamFormatter.d.ts +0 -0
  466. /package/dist/{batchStreamFormatter-93cdcdd4.js → unstable-core-do-not-import/http/batchStreamFormatter.js} +0 -0
  467. /package/dist/{rpc → unstable-core-do-not-import/rpc}/parseTRPCMessage.d.ts +0 -0
  468. /package/src/{shared/createProxy/index.ts → unstable-core-do-not-import/createProxy.ts} +0 -0
  469. /package/src/{http → unstable-core-do-not-import/http}/batchStreamFormatter.ts +0 -0
@@ -1,634 +1,12 @@
1
1
  import * as fs from 'node:fs/promises';
2
- import { mkdir, rm, unlink, stat } from 'node:fs/promises';
3
- import { Transform, finished, Readable } from 'node:stream';
4
- import { c as createNodeHTTPContentTypeHandler } from '../../../../contentType-3194ed5f.mjs';
5
- import { randomBytes } from 'node:crypto';
6
- import { createWriteStream, statSync, createReadStream } from 'node:fs';
7
- import { tmpdir } from 'node:os';
8
- import { resolve, dirname, basename, extname } from 'node:path';
9
- import { promisify } from 'node:util';
10
-
11
- function stringToArray(s) {
12
- const utf8 = unescape(encodeURIComponent(s));
13
- return Uint8Array.from(utf8, (_, i) => utf8.charCodeAt(i));
14
- }
15
- function arrayToString(a) {
16
- const utf8 = String.fromCharCode.apply(null, a);
17
- return decodeURIComponent(escape(utf8));
18
- }
19
- function mergeArrays(...arrays) {
20
- const out = new Uint8Array(arrays.reduce((total, arr) => total + arr.length, 0));
21
- let offset = 0;
22
- for (const arr of arrays) {
23
- out.set(arr, offset);
24
- offset += arr.length;
25
- }
26
- return out;
27
- }
28
- function arraysEqual(a, b) {
29
- if (a.length !== b.length) {
30
- return false;
31
- }
32
- for (let i = 0; i < a.length; i++) {
33
- if (a[i] !== b[i]) {
34
- return false;
35
- }
36
- }
37
- return true;
38
- }
39
-
40
- function coerce(a) {
41
- if (a instanceof Uint8Array) {
42
- return index => a[index];
43
- }
44
- return a;
45
- }
46
- function jsmemcmp(buf1, pos1, buf2, pos2, len) {
47
- const fn1 = coerce(buf1);
48
- const fn2 = coerce(buf2);
49
- for (let i = 0; i < len; ++i) {
50
- if (fn1(pos1 + i) !== fn2(pos2 + i)) {
51
- return false;
52
- }
53
- }
54
- return true;
55
- }
56
- function createOccurenceTable(s) {
57
- const table = new Array(256).fill(s.length);
58
- if (s.length > 1) {
59
- for (let i = 0; i < s.length - 1; i++) {
60
- table[s[i]] = s.length - 1 - i;
61
- }
62
- }
63
- return table;
64
- }
65
- const MATCH = Symbol('Match');
66
- class StreamSearch {
67
- constructor(needle) {
68
- this._lookbehind = new Uint8Array();
69
- if (typeof needle === 'string') {
70
- this._needle = needle = stringToArray(needle);
71
- } else {
72
- this._needle = needle;
73
- }
74
- this._lastChar = needle[needle.length - 1];
75
- this._occ = createOccurenceTable(needle);
76
- }
77
- feed(chunk) {
78
- let pos = 0;
79
- let tokens;
80
- const allTokens = [];
81
- while (pos !== chunk.length) {
82
- [pos, ...tokens] = this._feed(chunk, pos);
83
- allTokens.push(...tokens);
84
- }
85
- return allTokens;
86
- }
87
- end() {
88
- const tail = this._lookbehind;
89
- this._lookbehind = new Uint8Array();
90
- return tail;
91
- }
92
- _feed(data, bufPos) {
93
- const tokens = [];
94
- let pos = -this._lookbehind.length;
95
- if (pos < 0) {
96
- while (pos < 0 && pos <= data.length - this._needle.length) {
97
- const ch = this._charAt(data, pos + this._needle.length - 1);
98
- if (ch === this._lastChar && this._memcmp(data, pos, this._needle.length - 1)) {
99
- if (pos > -this._lookbehind.length) {
100
- tokens.push(this._lookbehind.slice(0, this._lookbehind.length + pos));
101
- }
102
- tokens.push(MATCH);
103
- this._lookbehind = new Uint8Array();
104
- return [
105
- pos + this._needle.length,
106
- ...tokens
107
- ];
108
- } else {
109
- pos += this._occ[ch];
110
- }
111
- }
112
- if (pos < 0) {
113
- while (pos < 0 && !this._memcmp(data, pos, data.length - pos)) {
114
- pos++;
115
- }
116
- }
117
- if (pos >= 0) {
118
- tokens.push(this._lookbehind);
119
- this._lookbehind = new Uint8Array();
120
- } else {
121
- const bytesToCutOff = this._lookbehind.length + pos;
122
- if (bytesToCutOff > 0) {
123
- tokens.push(this._lookbehind.slice(0, bytesToCutOff));
124
- this._lookbehind = this._lookbehind.slice(bytesToCutOff);
125
- }
126
- this._lookbehind = Uint8Array.from(new Array(this._lookbehind.length + data.length), (_, i) => this._charAt(data, i - this._lookbehind.length));
127
- return [
128
- data.length,
129
- ...tokens
130
- ];
131
- }
132
- }
133
- pos += bufPos;
134
- while (pos <= data.length - this._needle.length) {
135
- const ch = data[pos + this._needle.length - 1];
136
- if (ch === this._lastChar && data[pos] === this._needle[0] && jsmemcmp(this._needle, 0, data, pos, this._needle.length - 1)) {
137
- if (pos > bufPos) {
138
- tokens.push(data.slice(bufPos, pos));
139
- }
140
- tokens.push(MATCH);
141
- return [
142
- pos + this._needle.length,
143
- ...tokens
144
- ];
145
- } else {
146
- pos += this._occ[ch];
147
- }
148
- }
149
- if (pos < data.length) {
150
- while (pos < data.length && (data[pos] !== this._needle[0] || !jsmemcmp(data, pos, this._needle, 0, data.length - pos))) {
151
- ++pos;
152
- }
153
- if (pos < data.length) {
154
- this._lookbehind = data.slice(pos);
155
- }
156
- }
157
- if (pos > 0) {
158
- tokens.push(data.slice(bufPos, pos < data.length ? pos : data.length));
159
- }
160
- return [
161
- data.length,
162
- ...tokens
163
- ];
164
- }
165
- _charAt(data, pos) {
166
- if (pos < 0) {
167
- return this._lookbehind[this._lookbehind.length + pos];
168
- }
169
- return data[pos];
170
- }
171
- _memcmp(data, pos, len) {
172
- return jsmemcmp(this._charAt.bind(this, data), pos, this._needle, 0, len);
173
- }
174
- }
175
- class ReadableStreamSearch {
176
- constructor(needle, _readableStream) {
177
- this._readableStream = _readableStream;
178
- this._search = new StreamSearch(needle);
179
- }
180
- async *[Symbol.asyncIterator]() {
181
- const reader = this._readableStream.getReader();
182
- try {
183
- while (true) {
184
- const result = await reader.read();
185
- if (result.done) {
186
- break;
187
- }
188
- yield* this._search.feed(result.value);
189
- }
190
- const tail = this._search.end();
191
- if (tail.length) {
192
- yield tail;
193
- }
194
- } finally {
195
- reader.releaseLock();
196
- }
197
- }
198
- }
199
-
200
- const mergeArrays2 = Function.prototype.apply.bind(mergeArrays, undefined);
201
- const dash = stringToArray('--');
202
- const CRLF = stringToArray('\r\n');
203
- function parseContentDisposition(header) {
204
- const parts = header.split(';').map(part => part.trim());
205
- if (parts.shift() !== 'form-data') {
206
- throw new Error('malformed content-disposition header: missing "form-data" in `' + JSON.stringify(parts) + '`');
207
- }
208
- const out = {};
209
- for (const part of parts) {
210
- const kv = part.split('=', 2);
211
- if (kv.length !== 2) {
212
- throw new Error('malformed content-disposition header: key-value pair not found - ' + part + ' in `' + header + '`');
213
- }
214
- const [name, value] = kv;
215
- if (value[0] === '"' && value[value.length - 1] === '"') {
216
- out[name] = value.slice(1, -1).replace(/\\"/g, '"');
217
- } else if (value[0] !== '"' && value[value.length - 1] !== '"') {
218
- out[name] = value;
219
- } else if (value[0] === '"' && value[value.length - 1] !== '"' || value[0] !== '"' && value[value.length - 1] === '"') {
220
- throw new Error('malformed content-disposition header: mismatched quotations in `' + header + '`');
221
- }
222
- }
223
- if (!out.name) {
224
- throw new Error('malformed content-disposition header: missing field name in `' + header + '`');
225
- }
226
- return out;
227
- }
228
- function parsePartHeaders(lines) {
229
- const entries = [];
230
- let disposition = false;
231
- let line;
232
- while (typeof (line = lines.shift()) !== 'undefined') {
233
- const colon = line.indexOf(':');
234
- if (colon === -1) {
235
- throw new Error('malformed multipart-form header: missing colon');
236
- }
237
- const header = line.slice(0, colon).trim().toLowerCase();
238
- const value = line.slice(colon + 1).trim();
239
- switch (header) {
240
- case 'content-disposition':
241
- disposition = true;
242
- entries.push(...Object.entries(parseContentDisposition(value)));
243
- break;
244
- case 'content-type':
245
- entries.push([
246
- 'contentType',
247
- value
248
- ]);
249
- }
250
- }
251
- if (!disposition) {
252
- throw new Error('malformed multipart-form header: missing content-disposition');
253
- }
254
- return Object.fromEntries(entries);
255
- }
256
- async function readHeaderLines(it, needle) {
257
- let firstChunk = true;
258
- let lastTokenWasMatch = false;
259
- const headerLines = [[]];
260
- const crlfSearch = new StreamSearch(CRLF);
261
- for (;;) {
262
- const result = await it.next();
263
- if (result.done) {
264
- throw new Error('malformed multipart-form data: unexpected end of stream');
265
- }
266
- if (firstChunk && result.value !== MATCH && arraysEqual(result.value.slice(0, 2), dash)) {
267
- return [
268
- undefined,
269
- new Uint8Array()
270
- ];
271
- }
272
- let chunk;
273
- if (result.value !== MATCH) {
274
- chunk = result.value;
275
- } else if (!lastTokenWasMatch) {
276
- chunk = needle;
277
- } else {
278
- throw new Error('malformed multipart-form data: unexpected boundary');
279
- }
280
- if (!chunk.length) {
281
- continue;
282
- }
283
- if (firstChunk) {
284
- firstChunk = false;
285
- }
286
- const tokens = crlfSearch.feed(chunk);
287
- for (const [i, token] of tokens.entries()) {
288
- const isMatch = token === MATCH;
289
- if (!isMatch && !token.length) {
290
- continue;
291
- }
292
- if (lastTokenWasMatch && isMatch) {
293
- tokens.push(crlfSearch.end());
294
- return [
295
- headerLines.filter(chunks => chunks.length).map(mergeArrays2).map(arrayToString),
296
- mergeArrays(...tokens.slice(i + 1).map(token => token === MATCH ? CRLF : token))
297
- ];
298
- }
299
- if (lastTokenWasMatch = isMatch) {
300
- headerLines.push([]);
301
- } else {
302
- headerLines[headerLines.length - 1].push(token);
303
- }
304
- }
305
- }
306
- }
307
- async function* streamMultipart(body, boundary) {
308
- const needle = mergeArrays(dash, stringToArray(boundary));
309
- const it = new ReadableStreamSearch(needle, body)[Symbol.asyncIterator]();
310
- for (;;) {
311
- const result = await it.next();
312
- if (result.done) {
313
- return;
314
- }
315
- if (result.value === MATCH) {
316
- break;
317
- }
318
- }
319
- const crlfSearch = new StreamSearch(CRLF);
320
- for (;;) {
321
- const [headerLines, tail] = await readHeaderLines(it, needle);
322
- if (!headerLines) {
323
- return;
324
- }
325
- async function nextToken() {
326
- const result = await it.next();
327
- if (result.done) {
328
- throw new Error('malformed multipart-form data: unexpected end of stream');
329
- }
330
- return result;
331
- }
332
- let trailingCRLF = false;
333
- function feedChunk(chunk) {
334
- const chunks = [];
335
- for (const token of crlfSearch.feed(chunk)) {
336
- if (trailingCRLF) {
337
- chunks.push(CRLF);
338
- }
339
- if (!(trailingCRLF = token === MATCH)) {
340
- chunks.push(token);
341
- }
342
- }
343
- return mergeArrays(...chunks);
344
- }
345
- let done = false;
346
- async function nextChunk() {
347
- const result = await nextToken();
348
- let chunk;
349
- if (result.value !== MATCH) {
350
- chunk = result.value;
351
- } else if (!trailingCRLF) {
352
- chunk = CRLF;
353
- } else {
354
- done = true;
355
- return { value: crlfSearch.end() };
356
- }
357
- return { value: feedChunk(chunk) };
358
- }
359
- const bufferedChunks = [{ value: feedChunk(tail) }];
360
- yield {
361
- ...parsePartHeaders(headerLines),
362
- data: {
363
- [Symbol.asyncIterator]() {
364
- return this;
365
- },
366
- async next() {
367
- for (;;) {
368
- const result = bufferedChunks.shift();
369
- if (!result) {
370
- break;
371
- }
372
- if (result.value.length > 0) {
373
- return result;
374
- }
375
- }
376
- for (;;) {
377
- if (done) {
378
- return {
379
- done,
380
- value: undefined
381
- };
382
- }
383
- const result = await nextChunk();
384
- if (result.value.length > 0) {
385
- return result;
386
- }
387
- }
388
- }
389
- }
390
- };
391
- while (!done) {
392
- bufferedChunks.push(await nextChunk());
393
- }
394
- }
395
- }
396
-
397
- class SliceStream extends Transform {
398
- _transform(chunk, _, done) {
399
- this.indexOffset += chunk.length;
400
- if (!this.emitUp && this.indexOffset >= this.startIndex) {
401
- this.emitUp = true;
402
- const start = chunk.length - (this.indexOffset - this.startIndex);
403
- if (this.indexOffset > this.endIndex) {
404
- const end = chunk.length - (this.indexOffset - this.endIndex);
405
- this.emitDown = true;
406
- this.push(chunk.slice(start, end));
407
- } else {
408
- this.push(chunk.slice(start, chunk.length));
409
- }
410
- done();
411
- return;
412
- }
413
- if (this.emitUp && !this.emitDown) {
414
- if (this.indexOffset >= this.endIndex) {
415
- this.emitDown = true;
416
- this.push(chunk.slice(0, chunk.length - (this.indexOffset - this.endIndex)));
417
- } else {
418
- this.push(chunk);
419
- }
420
- done();
421
- return;
422
- }
423
- done();
424
- }
425
- constructor(startIndex = 0, endIndex = Infinity){
426
- super();
427
- this.startIndex = startIndex;
428
- this.endIndex = endIndex;
429
- this.indexOffset = 0;
430
- this.emitUp = false;
431
- this.emitDown = false;
432
- }
433
- }
434
- function streamSlice(startIndex = 0, endIndex = Infinity) {
435
- return new SliceStream(startIndex, endIndex);
436
- }
437
-
438
- function composeUploadHandlers(...handlers) {
439
- return async (part)=>{
440
- for (const handler of handlers){
441
- const value = await handler(part);
442
- if (typeof value !== 'undefined' && value !== null) {
443
- return value;
444
- }
445
- }
446
- return undefined;
447
- };
448
- }
449
- class MaxPartSizeExceededError extends Error {
450
- constructor(field, maxBytes){
451
- super(`Field "${field}" exceeded upload size of ${maxBytes} bytes.`);
452
- this.field = field;
453
- this.maxBytes = maxBytes;
454
- }
455
- }
456
- class MaxBodySizeExceededError extends Error {
457
- constructor(maxBytes){
458
- super(`Body exceeded upload size of ${maxBytes} bytes.`);
459
- this.maxBytes = maxBytes;
460
- }
461
- }
462
-
463
- async function readableStreamToString(stream, encoding) {
464
- const reader = stream.getReader();
465
- const chunks = [];
466
- async function read() {
467
- const { done , value } = await reader.read();
468
- if (done) {
469
- return;
470
- } else if (value) {
471
- chunks.push(value);
472
- }
473
- await read();
474
- }
475
- await read();
476
- return Buffer.concat(chunks).toString(encoding);
477
- }
478
- const defaultFilePathResolver = ({ filename , })=>{
479
- const ext = filename ? extname(filename) : '';
480
- return 'upload_' + randomBytes(4).readUInt32LE(0) + ext;
481
- };
482
- async function uniqueFile(filepath) {
483
- const ext = extname(filepath);
484
- let uniqueFilepath = filepath;
485
- for(let i = 1; await stat(uniqueFilepath).then(()=>true).catch(()=>false); i++){
486
- uniqueFilepath = (ext ? filepath.slice(0, -ext.length) : filepath) + `-${new Date().getTime()}${ext}`;
487
- }
488
- return uniqueFilepath;
489
- }
490
- function createFileUploadHandler({ directory =tmpdir() , avoidFileConflicts =true , file =defaultFilePathResolver , filter , maxPartSize =3000000 } = {}) {
491
- return async ({ name , filename , contentType , data })=>{
492
- if (!filename || filter && !await filter({
493
- name,
494
- filename,
495
- contentType
496
- })) {
497
- return undefined;
498
- }
499
- const dir = typeof directory === 'string' ? directory : directory({
500
- name,
501
- filename,
502
- contentType
503
- });
504
- if (!dir) {
505
- return undefined;
506
- }
507
- const filedir = resolve(dir);
508
- const path = typeof file === 'string' ? file : file({
509
- name,
510
- filename,
511
- contentType
512
- });
513
- if (!path) {
514
- return undefined;
515
- }
516
- let filepath = resolve(filedir, path);
517
- if (avoidFileConflicts) {
518
- filepath = await uniqueFile(filepath);
519
- }
520
- await mkdir(dirname(filepath), {
521
- recursive: true
522
- }).catch(()=>{});
523
- const writeFileStream = createWriteStream(filepath);
524
- let size = 0;
525
- let deleteFile = false;
526
- try {
527
- for await (const chunk of data){
528
- size += chunk.byteLength;
529
- if (size > maxPartSize) {
530
- deleteFile = true;
531
- throw new MaxPartSizeExceededError(name, maxPartSize);
532
- }
533
- writeFileStream.write(chunk);
534
- }
535
- } finally{
536
- writeFileStream.end();
537
- await promisify(finished)(writeFileStream);
538
- if (deleteFile) {
539
- await rm(filepath).catch(()=>{});
540
- }
541
- }
542
- return new NodeOnDiskFile(filepath, contentType);
543
- };
544
- }
545
- let _toStringTag = Symbol.toStringTag;
546
- class NodeOnDiskFile {
547
- get size() {
548
- const stats = statSync(this.filepath);
549
- if (this.slicer) {
550
- const slice = this.slicer.end - this.slicer.start;
551
- return slice < 0 ? 0 : slice > stats.size ? stats.size : slice;
552
- }
553
- return stats.size;
554
- }
555
- slice(start, end, type) {
556
- if (typeof start === 'number' && start < 0) start = this.size + start;
557
- if (typeof end === 'number' && end < 0) end = this.size + end;
558
- const startOffset = this.slicer?.start ?? 0;
559
- start = startOffset + (start ?? 0);
560
- end = startOffset + (end ?? this.size);
561
- return new NodeOnDiskFile(this.filepath, typeof type === 'string' ? type : this.type, {
562
- start,
563
- end
564
- });
565
- }
566
- async arrayBuffer() {
567
- let stream = createReadStream(this.filepath);
568
- if (this.slicer) {
569
- stream = stream.pipe(streamSlice(this.slicer.start, this.slicer.end));
570
- }
571
- return new Promise((resolve, reject)=>{
572
- const buf = [];
573
- stream.on('data', (chunk)=>buf.push(chunk));
574
- stream.on('end', ()=>{
575
- resolve(Buffer.concat(buf));
576
- });
577
- stream.on('error', (err)=>{
578
- reject(err);
579
- });
580
- });
581
- }
582
- stream() {
583
- let stream = createReadStream(this.filepath);
584
- if (this.slicer) {
585
- stream = stream.pipe(streamSlice(this.slicer.start, this.slicer.end));
586
- }
587
- return Readable.toWeb(stream);
588
- }
589
- async text() {
590
- return readableStreamToString(this.stream());
591
- }
592
- remove() {
593
- return unlink(this.filepath);
594
- }
595
- getFilePath() {
596
- return this.filepath;
597
- }
598
- constructor(filepath, type, slicer){
599
- this.filepath = filepath;
600
- this.type = type;
601
- this.slicer = slicer;
602
- this.lastModified = 0;
603
- this.webkitRelativePath = '';
604
- this[_toStringTag] = 'File';
605
- this.name = basename(filepath);
606
- }
607
- }
608
-
609
- function createMemoryUploadHandler({ filter , maxPartSize =3000000 } = {}) {
610
- return async ({ filename , contentType , name , data })=>{
611
- if (filter && !await filter({
612
- filename,
613
- contentType,
614
- name
615
- })) {
616
- return undefined;
617
- }
618
- let size = 0;
619
- const chunks = [];
620
- for await (const chunk of data){
621
- size += chunk.byteLength;
622
- if (size > maxPartSize) {
623
- throw new MaxPartSizeExceededError(name, maxPartSize);
624
- }
625
- chunks.push(chunk);
626
- }
627
- return new File(chunks, filename, {
628
- type: contentType
629
- });
630
- };
631
- }
2
+ import { Readable } from 'node:stream';
3
+ import { streamMultipart } from '@web3-storage/multipart-parser';
4
+ import { createNodeHTTPContentTypeHandler } from '../../internals/contentType.mjs';
5
+ import { NodeOnDiskFile } from './fileUploadHandler.mjs';
6
+ export { createFileUploadHandler as experimental_createFileUploadHandler } from './fileUploadHandler.mjs';
7
+ import { MaxBodySizeExceededError } from './uploadHandler.mjs';
8
+ export { MaxPartSizeExceededError, composeUploadHandlers as experimental_composeUploadHandlers } from './uploadHandler.mjs';
9
+ export { createMemoryUploadHandler as experimental_createMemoryUploadHandler } from './memoryUploadHandler.mjs';
632
10
 
633
11
  const utfTextDecoder = new TextDecoder('utf-8');
634
12
  /**
@@ -639,7 +17,7 @@ const utfTextDecoder = new TextDecoder('utf-8');
639
17
  * @param uploadHandler A function that handles file uploads and returns a value to be used in the request body. If uploaded to disk, the returned value is a NodeOnDiskFile. If uploaded to memory, the returned value is a File.
640
18
  * @param maxBodySize The maximum size of the request body in bytes. Defaults to Infinity.
641
19
  *
642
- * @see https://remix.run/utils/parse-multipart-form-data
20
+ * @link https://remix.run/utils/parse-multipart-form-data
643
21
  */ async function parseMultipartFormData(request, uploadHandler, maxBodySize = Infinity) {
644
22
  const contentType = request.headers['content-type'] ?? '';
645
23
  const [type, boundary] = contentType.split(/\s*;\s*boundary=/);
@@ -727,4 +105,4 @@ const nodeHTTPFormDataContentTypeHandler = createNodeHTTPContentTypeHandler({
727
105
  }
728
106
  });
729
107
 
730
- export { MaxBodySizeExceededError, MaxPartSizeExceededError, NodeOnDiskFile as experimental_NodeOnDiskFile, composeUploadHandlers as experimental_composeUploadHandlers, createFileUploadHandler as experimental_createFileUploadHandler, createMemoryUploadHandler as experimental_createMemoryUploadHandler, isMultipartFormDataRequest as experimental_isMultipartFormDataRequest, parseMultipartFormData as experimental_parseMultipartFormData, nodeHTTPFormDataContentTypeHandler };
108
+ export { MaxBodySizeExceededError, NodeOnDiskFile as experimental_NodeOnDiskFile, isMultipartFormDataRequest as experimental_isMultipartFormDataRequest, parseMultipartFormData as experimental_parseMultipartFormData, nodeHTTPFormDataContentTypeHandler };
@@ -5,9 +5,9 @@
5
5
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
6
6
  */
7
7
  /**
8
- * @see https://github.com/remix-run/remix/blob/0bcb4a304dd2f08f6032c3bf0c3aa7eb5b976901/packages/remix-server-runtime/upload/memoryUploadHandler.ts
8
+ * @link https://github.com/remix-run/remix/blob/0bcb4a304dd2f08f6032c3bf0c3aa7eb5b976901/packages/remix-server-runtime/upload/memoryUploadHandler.ts
9
9
  */
10
- import { UploadHandler } from './uploadHandler';
10
+ import type { UploadHandler } from './uploadHandler';
11
11
  export type MemoryUploadHandlerFilterArgs = {
12
12
  filename?: string;
13
13
  contentType: string;
@@ -1 +1 @@
1
- {"version":3,"file":"memoryUploadHandler.d.ts","sourceRoot":"","sources":["../../../../../src/adapters/node-http/content-type/form-data/memoryUploadHandler.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,OAAO,EAA4B,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAE1E,MAAM,MAAM,6BAA6B,GAAG;IAC1C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;OAKG;IACH,MAAM,CAAC,CAAC,IAAI,EAAE,6BAA6B,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;CAC1E,CAAC;AAEF,wBAAgB,yBAAyB,CAAC,EACxC,MAAM,EACN,WAAqB,GACtB,GAAE,0BAA+B,GAAG,aAAa,CAkBjD"}
1
+ {"version":3,"file":"memoryUploadHandler.d.ts","sourceRoot":"","sources":["../../../../../src/adapters/node-http/content-type/form-data/memoryUploadHandler.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGrD,MAAM,MAAM,6BAA6B,GAAG;IAC1C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;OAKG;IACH,MAAM,CAAC,CAAC,IAAI,EAAE,6BAA6B,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;CAC1E,CAAC;AAEF,wBAAgB,yBAAyB,CAAC,EACxC,MAAM,EACN,WAAqB,GACtB,GAAE,0BAA+B,GAAG,aAAa,CAkBjD"}
@@ -0,0 +1,29 @@
1
+ 'use strict';
2
+
3
+ var uploadHandler = require('./uploadHandler.js');
4
+
5
+ function createMemoryUploadHandler({ filter , maxPartSize =3000000 } = {}) {
6
+ return async ({ filename , contentType , name , data })=>{
7
+ if (filter && !await filter({
8
+ filename,
9
+ contentType,
10
+ name
11
+ })) {
12
+ return undefined;
13
+ }
14
+ let size = 0;
15
+ const chunks = [];
16
+ for await (const chunk of data){
17
+ size += chunk.byteLength;
18
+ if (size > maxPartSize) {
19
+ throw new uploadHandler.MaxPartSizeExceededError(name, maxPartSize);
20
+ }
21
+ chunks.push(chunk);
22
+ }
23
+ return new File(chunks, filename, {
24
+ type: contentType
25
+ });
26
+ };
27
+ }
28
+
29
+ exports.createMemoryUploadHandler = createMemoryUploadHandler;