@trpc/server 11.0.0-alpha-tmp-export-from-main-nuke-core.240 → 11.0.0-alpha-tmp-export-from-main.222

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 (308) hide show
  1. package/dist/adapters/aws-lambda/index.d.mts +68 -0
  2. package/dist/adapters/aws-lambda/index.d.ts +55 -6
  3. package/dist/adapters/aws-lambda/index.js +111 -23
  4. package/dist/adapters/aws-lambda/index.mjs +95 -7
  5. package/dist/adapters/express.d.mts +19 -0
  6. package/dist/adapters/express.d.ts +10 -6
  7. package/dist/adapters/express.js +3 -3
  8. package/dist/adapters/express.mjs +1 -1
  9. package/dist/adapters/fastify/index.d.mts +33 -0
  10. package/dist/adapters/fastify/index.d.ts +33 -3
  11. package/dist/adapters/fastify/index.js +124 -5
  12. package/dist/adapters/fastify/index.mjs +125 -2
  13. package/dist/adapters/fetch/index.d.mts +51 -0
  14. package/dist/adapters/fetch/index.d.ts +51 -3
  15. package/dist/adapters/fetch/index.js +115 -4
  16. package/dist/adapters/fetch/index.mjs +116 -1
  17. package/dist/adapters/next.d.mts +21 -0
  18. package/dist/adapters/next.d.ts +12 -6
  19. package/dist/adapters/next.js +7 -9
  20. package/dist/adapters/next.mjs +3 -5
  21. package/dist/adapters/node-http/content-type/form-data/index.d.mts +219 -0
  22. package/dist/adapters/node-http/content-type/form-data/index.d.ts +201 -10
  23. package/dist/adapters/node-http/content-type/form-data/index.js +662 -23
  24. package/dist/adapters/node-http/content-type/form-data/index.mjs +646 -10
  25. package/dist/adapters/node-http/{types.d.ts → content-type/json/index.d.mts} +22 -15
  26. package/dist/adapters/node-http/content-type/json/index.d.ts +89 -2
  27. package/dist/adapters/node-http/content-type/json/index.js +48 -9
  28. package/dist/adapters/node-http/content-type/json/index.mjs +44 -5
  29. package/dist/adapters/node-http/index.d.mts +100 -0
  30. package/dist/adapters/node-http/index.d.ts +100 -3
  31. package/dist/adapters/node-http/index.js +106 -4
  32. package/dist/adapters/node-http/index.mjs +107 -1
  33. package/dist/adapters/standalone.d.mts +21 -0
  34. package/dist/adapters/standalone.d.ts +12 -9
  35. package/dist/adapters/standalone.js +9 -6
  36. package/dist/adapters/standalone.mjs +2 -3
  37. package/dist/adapters/ws.d.mts +36 -0
  38. package/dist/adapters/ws.d.ts +12 -14
  39. package/dist/adapters/ws.js +33 -38
  40. package/dist/adapters/ws.mjs +12 -17
  41. package/dist/http.d.mts +1 -0
  42. package/dist/http.d.ts +1 -2
  43. package/dist/http.js +22 -12
  44. package/dist/http.mjs +1 -6
  45. package/dist/index.d.mts +9 -0
  46. package/dist/index.d.ts +9 -2
  47. package/dist/index.js +809 -23
  48. package/dist/index.mjs +798 -8
  49. package/dist/observable.d.mts +1 -0
  50. package/dist/observable.d.ts +1 -0
  51. package/dist/observable.js +30 -0
  52. package/dist/observable.mjs +1 -0
  53. package/dist/rpc.d.mts +1 -0
  54. package/dist/rpc.d.ts +1 -2
  55. package/dist/rpc.js +14 -7
  56. package/dist/rpc.mjs +1 -3
  57. package/dist/shared.d.mts +1 -0
  58. package/dist/shared.d.ts +1 -26
  59. package/dist/shared.js +10 -7
  60. package/dist/shared.mjs +1 -4
  61. package/dist/unstableDontImportMe.d.mts +1 -0
  62. package/dist/unstableDontImportMe.d.ts +1 -0
  63. package/dist/unstableDontImportMe.js +1549 -0
  64. package/dist/unstableDontImportMe.mjs +1514 -0
  65. package/package.json +138 -53
  66. package/src/@trpc-server/http.ts +2 -0
  67. package/src/adapters/aws-lambda/index.ts +5 -4
  68. package/src/adapters/aws-lambda/utils.ts +4 -3
  69. package/src/adapters/express.ts +3 -1
  70. package/src/adapters/fastify/fastifyRequestHandler.ts +4 -6
  71. package/src/adapters/fastify/fastifyTRPCPlugin.ts +2 -1
  72. package/src/adapters/fetch/fetchRequestHandler.ts +4 -6
  73. package/src/adapters/fetch/types.ts +3 -2
  74. package/src/adapters/next.ts +4 -2
  75. package/src/adapters/node-http/content-type/form-data/index.ts +1 -1
  76. package/src/adapters/node-http/content-type/json/getPostBody.ts +2 -2
  77. package/src/adapters/node-http/content-type/json/index.ts +1 -1
  78. package/src/adapters/node-http/internals/contentType.ts +2 -2
  79. package/src/adapters/node-http/nodeHTTPRequestHandler.ts +4 -6
  80. package/src/adapters/node-http/types.ts +5 -4
  81. package/src/adapters/standalone.ts +2 -2
  82. package/src/adapters/ws.ts +13 -14
  83. package/src/http.ts +26 -1
  84. package/src/index.ts +106 -1
  85. package/src/observable.ts +16 -0
  86. package/src/rpc.ts +26 -1
  87. package/src/shared.ts +1 -1
  88. package/src/unstableDontImportMe.ts +146 -0
  89. package/unstableDontImportMe/index.d.ts +1 -0
  90. package/unstableDontImportMe/index.js +1 -0
  91. package/dist/@trpc/server/http.d.ts +0 -7
  92. package/dist/@trpc/server/http.d.ts.map +0 -1
  93. package/dist/@trpc/server/index.d.ts +0 -69
  94. package/dist/@trpc/server/index.d.ts.map +0 -1
  95. package/dist/@trpc/server/rpc.d.ts +0 -3
  96. package/dist/@trpc/server/rpc.d.ts.map +0 -1
  97. package/dist/adapters/aws-lambda/index.d.ts.map +0 -1
  98. package/dist/adapters/aws-lambda/utils.d.ts +0 -47
  99. package/dist/adapters/aws-lambda/utils.d.ts.map +0 -1
  100. package/dist/adapters/aws-lambda/utils.js +0 -101
  101. package/dist/adapters/aws-lambda/utils.mjs +0 -94
  102. package/dist/adapters/express.d.ts.map +0 -1
  103. package/dist/adapters/fastify/fastifyRequestHandler.d.ts +0 -13
  104. package/dist/adapters/fastify/fastifyRequestHandler.d.ts.map +0 -1
  105. package/dist/adapters/fastify/fastifyRequestHandler.js +0 -84
  106. package/dist/adapters/fastify/fastifyRequestHandler.mjs +0 -82
  107. package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts +0 -21
  108. package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts.map +0 -1
  109. package/dist/adapters/fastify/fastifyTRPCPlugin.js +0 -50
  110. package/dist/adapters/fastify/fastifyTRPCPlugin.mjs +0 -48
  111. package/dist/adapters/fastify/index.d.ts.map +0 -1
  112. package/dist/adapters/fetch/fetchRequestHandler.d.ts +0 -17
  113. package/dist/adapters/fetch/fetchRequestHandler.d.ts.map +0 -1
  114. package/dist/adapters/fetch/fetchRequestHandler.js +0 -120
  115. package/dist/adapters/fetch/fetchRequestHandler.mjs +0 -118
  116. package/dist/adapters/fetch/index.d.ts.map +0 -1
  117. package/dist/adapters/fetch/types.d.ts +0 -30
  118. package/dist/adapters/fetch/types.d.ts.map +0 -1
  119. package/dist/adapters/next.d.ts.map +0 -1
  120. package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.d.ts +0 -70
  121. package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.d.ts.map +0 -1
  122. package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.js +0 -161
  123. package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.mjs +0 -157
  124. package/dist/adapters/node-http/content-type/form-data/index.d.ts.map +0 -1
  125. package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.d.ts +0 -31
  126. package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.d.ts.map +0 -1
  127. package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.js +0 -29
  128. package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.mjs +0 -27
  129. package/dist/adapters/node-http/content-type/form-data/streamSlice.d.ts +0 -16
  130. package/dist/adapters/node-http/content-type/form-data/streamSlice.d.ts.map +0 -1
  131. package/dist/adapters/node-http/content-type/form-data/streamSlice.js +0 -46
  132. package/dist/adapters/node-http/content-type/form-data/streamSlice.mjs +0 -44
  133. package/dist/adapters/node-http/content-type/form-data/uploadHandler.d.ts +0 -45
  134. package/dist/adapters/node-http/content-type/form-data/uploadHandler.d.ts.map +0 -1
  135. package/dist/adapters/node-http/content-type/form-data/uploadHandler.js +0 -30
  136. package/dist/adapters/node-http/content-type/form-data/uploadHandler.mjs +0 -26
  137. package/dist/adapters/node-http/content-type/json/getPostBody.d.ts +0 -7
  138. package/dist/adapters/node-http/content-type/json/getPostBody.d.ts.map +0 -1
  139. package/dist/adapters/node-http/content-type/json/getPostBody.js +0 -44
  140. package/dist/adapters/node-http/content-type/json/getPostBody.mjs +0 -42
  141. package/dist/adapters/node-http/content-type/json/index.d.ts.map +0 -1
  142. package/dist/adapters/node-http/index.d.ts.map +0 -1
  143. package/dist/adapters/node-http/internals/contentType.d.ts +0 -9
  144. package/dist/adapters/node-http/internals/contentType.d.ts.map +0 -1
  145. package/dist/adapters/node-http/internals/contentType.js +0 -8
  146. package/dist/adapters/node-http/internals/contentType.mjs +0 -6
  147. package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts +0 -13
  148. package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +0 -1
  149. package/dist/adapters/node-http/nodeHTTPRequestHandler.js +0 -111
  150. package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +0 -109
  151. package/dist/adapters/node-http/types.d.ts.map +0 -1
  152. package/dist/adapters/standalone.d.ts.map +0 -1
  153. package/dist/adapters/ws.d.ts.map +0 -1
  154. package/dist/bundle-analysis.json +0 -757
  155. package/dist/http.d.ts.map +0 -1
  156. package/dist/index.d.ts.map +0 -1
  157. package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/index.js +0 -203
  158. package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/index.mjs +0 -201
  159. package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/search.js +0 -167
  160. package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/search.mjs +0 -163
  161. package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/utils.js +0 -35
  162. package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/utils.mjs +0 -30
  163. package/dist/observable/index.d.ts +0 -5
  164. package/dist/observable/index.d.ts.map +0 -1
  165. package/dist/observable/index.js +0 -13
  166. package/dist/observable/index.mjs +0 -2
  167. package/dist/observable/observable.d.ts +0 -13
  168. package/dist/observable/observable.d.ts.map +0 -1
  169. package/dist/observable/observable.js +0 -126
  170. package/dist/observable/observable.mjs +0 -122
  171. package/dist/observable/operators.d.ts +0 -8
  172. package/dist/observable/operators.d.ts.map +0 -1
  173. package/dist/observable/operators.js +0 -103
  174. package/dist/observable/operators.mjs +0 -99
  175. package/dist/observable/types.d.ts +0 -26
  176. package/dist/observable/types.d.ts.map +0 -1
  177. package/dist/rpc.d.ts.map +0 -1
  178. package/dist/shared.d.ts.map +0 -1
  179. package/dist/unstable-core-do-not-import/TRPCInferrable.d.ts +0 -6
  180. package/dist/unstable-core-do-not-import/TRPCInferrable.d.ts.map +0 -1
  181. package/dist/unstable-core-do-not-import/createProxy.d.ts +0 -19
  182. package/dist/unstable-core-do-not-import/createProxy.d.ts.map +0 -1
  183. package/dist/unstable-core-do-not-import/createProxy.js +0 -52
  184. package/dist/unstable-core-do-not-import/createProxy.mjs +0 -49
  185. package/dist/unstable-core-do-not-import/error/TRPCError.d.ts +0 -13
  186. package/dist/unstable-core-do-not-import/error/TRPCError.d.ts.map +0 -1
  187. package/dist/unstable-core-do-not-import/error/TRPCError.js +0 -67
  188. package/dist/unstable-core-do-not-import/error/TRPCError.mjs +0 -63
  189. package/dist/unstable-core-do-not-import/error/formatter.d.ts +0 -33
  190. package/dist/unstable-core-do-not-import/error/formatter.d.ts.map +0 -1
  191. package/dist/unstable-core-do-not-import/error/formatter.js +0 -7
  192. package/dist/unstable-core-do-not-import/error/formatter.mjs +0 -5
  193. package/dist/unstable-core-do-not-import/error/getErrorShape.d.ts +0 -15
  194. package/dist/unstable-core-do-not-import/error/getErrorShape.d.ts.map +0 -1
  195. package/dist/unstable-core-do-not-import/error/getErrorShape.js +0 -31
  196. package/dist/unstable-core-do-not-import/error/getErrorShape.mjs +0 -29
  197. package/dist/unstable-core-do-not-import/http/batchStreamFormatter.d.ts +0 -24
  198. package/dist/unstable-core-do-not-import/http/batchStreamFormatter.d.ts.map +0 -1
  199. package/dist/unstable-core-do-not-import/http/batchStreamFormatter.js +0 -32
  200. package/dist/unstable-core-do-not-import/http/batchStreamFormatter.mjs +0 -30
  201. package/dist/unstable-core-do-not-import/http/contentType.d.ts +0 -29
  202. package/dist/unstable-core-do-not-import/http/contentType.d.ts.map +0 -1
  203. package/dist/unstable-core-do-not-import/http/contentType.js +0 -54
  204. package/dist/unstable-core-do-not-import/http/contentType.mjs +0 -52
  205. package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts +0 -5
  206. package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts.map +0 -1
  207. package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.js +0 -51
  208. package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.mjs +0 -48
  209. package/dist/unstable-core-do-not-import/http/index.d.ts +0 -7
  210. package/dist/unstable-core-do-not-import/http/index.d.ts.map +0 -1
  211. package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts +0 -51
  212. package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts.map +0 -1
  213. package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.js +0 -295
  214. package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.mjs +0 -293
  215. package/dist/unstable-core-do-not-import/http/types.d.ts +0 -96
  216. package/dist/unstable-core-do-not-import/http/types.d.ts.map +0 -1
  217. package/dist/unstable-core-do-not-import/index.d.ts +0 -37
  218. package/dist/unstable-core-do-not-import/index.d.ts.map +0 -1
  219. package/dist/unstable-core-do-not-import/index.js +0 -48
  220. package/dist/unstable-core-do-not-import/index.mjs +0 -16
  221. package/dist/unstable-core-do-not-import/initTRPC.d.ts +0 -96
  222. package/dist/unstable-core-do-not-import/initTRPC.d.ts.map +0 -1
  223. package/dist/unstable-core-do-not-import/initTRPC.js +0 -95
  224. package/dist/unstable-core-do-not-import/initTRPC.mjs +0 -93
  225. package/dist/unstable-core-do-not-import/middleware.d.ts +0 -105
  226. package/dist/unstable-core-do-not-import/middleware.d.ts.map +0 -1
  227. package/dist/unstable-core-do-not-import/middleware.js +0 -95
  228. package/dist/unstable-core-do-not-import/middleware.mjs +0 -89
  229. package/dist/unstable-core-do-not-import/parser.d.ts +0 -30
  230. package/dist/unstable-core-do-not-import/parser.d.ts.map +0 -1
  231. package/dist/unstable-core-do-not-import/parser.js +0 -37
  232. package/dist/unstable-core-do-not-import/parser.mjs +0 -35
  233. package/dist/unstable-core-do-not-import/procedure.d.ts +0 -72
  234. package/dist/unstable-core-do-not-import/procedure.d.ts.map +0 -1
  235. package/dist/unstable-core-do-not-import/procedure.js +0 -9
  236. package/dist/unstable-core-do-not-import/procedure.mjs +0 -7
  237. package/dist/unstable-core-do-not-import/procedureBuilder.d.ts +0 -101
  238. package/dist/unstable-core-do-not-import/procedureBuilder.d.ts.map +0 -1
  239. package/dist/unstable-core-do-not-import/procedureBuilder.js +0 -176
  240. package/dist/unstable-core-do-not-import/procedureBuilder.mjs +0 -173
  241. package/dist/unstable-core-do-not-import/rootConfig.d.ts +0 -75
  242. package/dist/unstable-core-do-not-import/rootConfig.d.ts.map +0 -1
  243. package/dist/unstable-core-do-not-import/rootConfig.js +0 -8
  244. package/dist/unstable-core-do-not-import/rootConfig.mjs +0 -6
  245. package/dist/unstable-core-do-not-import/router.d.ts +0 -85
  246. package/dist/unstable-core-do-not-import/router.d.ts.map +0 -1
  247. package/dist/unstable-core-do-not-import/router.js +0 -156
  248. package/dist/unstable-core-do-not-import/router.mjs +0 -151
  249. package/dist/unstable-core-do-not-import/rpc/codes.d.ts +0 -51
  250. package/dist/unstable-core-do-not-import/rpc/codes.d.ts.map +0 -1
  251. package/dist/unstable-core-do-not-import/rpc/codes.js +0 -38
  252. package/dist/unstable-core-do-not-import/rpc/codes.mjs +0 -35
  253. package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts +0 -97
  254. package/dist/unstable-core-do-not-import/rpc/envelopes.d.ts.map +0 -1
  255. package/dist/unstable-core-do-not-import/rpc/index.d.ts +0 -5
  256. package/dist/unstable-core-do-not-import/rpc/index.d.ts.map +0 -1
  257. package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.d.ts +0 -5
  258. package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.d.ts.map +0 -1
  259. package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.js +0 -59
  260. package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.mjs +0 -57
  261. package/dist/unstable-core-do-not-import/serialize.d.ts +0 -62
  262. package/dist/unstable-core-do-not-import/serialize.d.ts.map +0 -1
  263. package/dist/unstable-core-do-not-import/transformer.d.ts +0 -107
  264. package/dist/unstable-core-do-not-import/transformer.d.ts.map +0 -1
  265. package/dist/unstable-core-do-not-import/transformer.js +0 -107
  266. package/dist/unstable-core-do-not-import/transformer.mjs +0 -102
  267. package/dist/unstable-core-do-not-import/types.d.ts +0 -98
  268. package/dist/unstable-core-do-not-import/types.d.ts.map +0 -1
  269. package/dist/unstable-core-do-not-import/utils.d.ts +0 -27
  270. package/dist/unstable-core-do-not-import/utils.d.ts.map +0 -1
  271. package/dist/unstable-core-do-not-import/utils.js +0 -44
  272. package/dist/unstable-core-do-not-import/utils.mjs +0 -39
  273. package/src/@trpc/server/http.ts +0 -26
  274. package/src/@trpc/server/index.ts +0 -105
  275. package/src/@trpc/server/rpc.ts +0 -26
  276. package/src/observable/index.ts +0 -10
  277. package/src/observable/observable.ts +0 -158
  278. package/src/observable/operators.ts +0 -119
  279. package/src/observable/types.ts +0 -76
  280. package/src/unstable-core-do-not-import/TRPCInferrable.ts +0 -9
  281. package/src/unstable-core-do-not-import/createProxy.ts +0 -59
  282. package/src/unstable-core-do-not-import/error/TRPCError.ts +0 -82
  283. package/src/unstable-core-do-not-import/error/formatter.ts +0 -51
  284. package/src/unstable-core-do-not-import/error/getErrorShape.ts +0 -36
  285. package/src/unstable-core-do-not-import/http/batchStreamFormatter.ts +0 -29
  286. package/src/unstable-core-do-not-import/http/contentType.ts +0 -99
  287. package/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts +0 -57
  288. package/src/unstable-core-do-not-import/http/index.ts +0 -23
  289. package/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts +0 -458
  290. package/src/unstable-core-do-not-import/http/types.ts +0 -111
  291. package/src/unstable-core-do-not-import/index.ts +0 -110
  292. package/src/unstable-core-do-not-import/initTRPC.ts +0 -206
  293. package/src/unstable-core-do-not-import/middleware.ts +0 -233
  294. package/src/unstable-core-do-not-import/parser.ts +0 -94
  295. package/src/unstable-core-do-not-import/procedure.ts +0 -108
  296. package/src/unstable-core-do-not-import/procedureBuilder.ts +0 -458
  297. package/src/unstable-core-do-not-import/rootConfig.ts +0 -90
  298. package/src/unstable-core-do-not-import/router.ts +0 -370
  299. package/src/unstable-core-do-not-import/rpc/codes.ts +0 -44
  300. package/src/unstable-core-do-not-import/rpc/envelopes.ts +0 -136
  301. package/src/unstable-core-do-not-import/rpc/index.ts +0 -21
  302. package/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts +0 -85
  303. package/src/unstable-core-do-not-import/serialize.ts +0 -122
  304. package/src/unstable-core-do-not-import/transformer.ts +0 -202
  305. package/src/unstable-core-do-not-import/types.ts +0 -151
  306. package/src/unstable-core-do-not-import/utils.ts +0 -59
  307. package/unstable-core-do-not-import/index.d.ts +0 -1
  308. package/unstable-core-do-not-import/index.js +0 -1
@@ -1,12 +1,648 @@
1
- import * as fs from 'node:fs/promises';
2
- import { Readable } from 'node:stream';
3
- import { streamMultipart } from '../../../../node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/index.mjs';
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';
1
+ import * as fs from 'fs/promises';
2
+ import { Transform, finished, Readable } from 'node:stream';
3
+ import { randomBytes } from 'node:crypto';
4
+ import { createWriteStream, statSync, createReadStream } from 'node:fs';
5
+ import { mkdir, rm, unlink, stat } from 'node:fs/promises';
6
+ import { tmpdir } from 'node:os';
7
+ import { resolve, dirname, basename, extname } from 'node:path';
8
+ import { promisify } from 'node:util';
9
+
10
+ function stringToArray(s) {
11
+ const utf8 = unescape(encodeURIComponent(s));
12
+ return Uint8Array.from(utf8, (_, i)=>utf8.charCodeAt(i));
13
+ }
14
+ function arrayToString(a) {
15
+ const utf8 = String.fromCharCode.apply(null, a);
16
+ return decodeURIComponent(escape(utf8));
17
+ }
18
+ function mergeArrays(...arrays) {
19
+ const out = new Uint8Array(arrays.reduce((total, arr)=>total + arr.length, 0));
20
+ let offset = 0;
21
+ for (const arr of arrays){
22
+ out.set(arr, offset);
23
+ offset += arr.length;
24
+ }
25
+ return out;
26
+ }
27
+ function arraysEqual(a, b) {
28
+ if (a.length !== b.length) {
29
+ return false;
30
+ }
31
+ for(let i = 0; i < a.length; i++){
32
+ if (a[i] !== b[i]) {
33
+ return false;
34
+ }
35
+ }
36
+ return true;
37
+ }
38
+
39
+ function coerce(a) {
40
+ if (a instanceof Uint8Array) {
41
+ return (index)=>a[index];
42
+ }
43
+ return a;
44
+ }
45
+ function jsmemcmp(buf1, pos1, buf2, pos2, len) {
46
+ const fn1 = coerce(buf1);
47
+ const fn2 = coerce(buf2);
48
+ for(let i = 0; i < len; ++i){
49
+ if (fn1(pos1 + i) !== fn2(pos2 + i)) {
50
+ return false;
51
+ }
52
+ }
53
+ return true;
54
+ }
55
+ function createOccurenceTable(s) {
56
+ const table = new Array(256).fill(s.length);
57
+ if (s.length > 1) {
58
+ for(let i = 0; i < s.length - 1; i++){
59
+ table[s[i]] = s.length - 1 - i;
60
+ }
61
+ }
62
+ return table;
63
+ }
64
+ const MATCH = Symbol('Match');
65
+ class StreamSearch {
66
+ constructor(needle){
67
+ this._lookbehind = new Uint8Array();
68
+ if (typeof needle === 'string') {
69
+ this._needle = needle = stringToArray(needle);
70
+ } else {
71
+ this._needle = needle;
72
+ }
73
+ this._lastChar = needle[needle.length - 1];
74
+ this._occ = createOccurenceTable(needle);
75
+ }
76
+ feed(chunk) {
77
+ let pos = 0;
78
+ let tokens;
79
+ const allTokens = [];
80
+ while(pos !== chunk.length){
81
+ [pos, ...tokens] = this._feed(chunk, pos);
82
+ allTokens.push(...tokens);
83
+ }
84
+ return allTokens;
85
+ }
86
+ end() {
87
+ const tail = this._lookbehind;
88
+ this._lookbehind = new Uint8Array();
89
+ return tail;
90
+ }
91
+ _feed(data, bufPos) {
92
+ const tokens = [];
93
+ let pos = -this._lookbehind.length;
94
+ if (pos < 0) {
95
+ while(pos < 0 && pos <= data.length - this._needle.length){
96
+ const ch = this._charAt(data, pos + this._needle.length - 1);
97
+ if (ch === this._lastChar && this._memcmp(data, pos, this._needle.length - 1)) {
98
+ if (pos > -this._lookbehind.length) {
99
+ tokens.push(this._lookbehind.slice(0, this._lookbehind.length + pos));
100
+ }
101
+ tokens.push(MATCH);
102
+ this._lookbehind = new Uint8Array();
103
+ return [
104
+ pos + this._needle.length,
105
+ ...tokens
106
+ ];
107
+ } else {
108
+ pos += this._occ[ch];
109
+ }
110
+ }
111
+ if (pos < 0) {
112
+ while(pos < 0 && !this._memcmp(data, pos, data.length - pos)){
113
+ pos++;
114
+ }
115
+ }
116
+ if (pos >= 0) {
117
+ tokens.push(this._lookbehind);
118
+ this._lookbehind = new Uint8Array();
119
+ } else {
120
+ const bytesToCutOff = this._lookbehind.length + pos;
121
+ if (bytesToCutOff > 0) {
122
+ tokens.push(this._lookbehind.slice(0, bytesToCutOff));
123
+ this._lookbehind = this._lookbehind.slice(bytesToCutOff);
124
+ }
125
+ this._lookbehind = Uint8Array.from(new Array(this._lookbehind.length + data.length), (_, i)=>this._charAt(data, i - this._lookbehind.length));
126
+ return [
127
+ data.length,
128
+ ...tokens
129
+ ];
130
+ }
131
+ }
132
+ pos += bufPos;
133
+ while(pos <= data.length - this._needle.length){
134
+ const ch = data[pos + this._needle.length - 1];
135
+ if (ch === this._lastChar && data[pos] === this._needle[0] && jsmemcmp(this._needle, 0, data, pos, this._needle.length - 1)) {
136
+ if (pos > bufPos) {
137
+ tokens.push(data.slice(bufPos, pos));
138
+ }
139
+ tokens.push(MATCH);
140
+ return [
141
+ pos + this._needle.length,
142
+ ...tokens
143
+ ];
144
+ } else {
145
+ pos += this._occ[ch];
146
+ }
147
+ }
148
+ if (pos < data.length) {
149
+ while(pos < data.length && (data[pos] !== this._needle[0] || !jsmemcmp(data, pos, this._needle, 0, data.length - pos))){
150
+ ++pos;
151
+ }
152
+ if (pos < data.length) {
153
+ this._lookbehind = data.slice(pos);
154
+ }
155
+ }
156
+ if (pos > 0) {
157
+ tokens.push(data.slice(bufPos, pos < data.length ? pos : data.length));
158
+ }
159
+ return [
160
+ data.length,
161
+ ...tokens
162
+ ];
163
+ }
164
+ _charAt(data, pos) {
165
+ if (pos < 0) {
166
+ return this._lookbehind[this._lookbehind.length + pos];
167
+ }
168
+ return data[pos];
169
+ }
170
+ _memcmp(data, pos, len) {
171
+ return jsmemcmp(this._charAt.bind(this, data), pos, this._needle, 0, len);
172
+ }
173
+ }
174
+ class ReadableStreamSearch {
175
+ constructor(needle, _readableStream){
176
+ this._readableStream = _readableStream;
177
+ this._search = new StreamSearch(needle);
178
+ }
179
+ async *[Symbol.asyncIterator]() {
180
+ const reader = this._readableStream.getReader();
181
+ try {
182
+ while(true){
183
+ const result = await reader.read();
184
+ if (result.done) {
185
+ break;
186
+ }
187
+ yield* this._search.feed(result.value);
188
+ }
189
+ const tail = this._search.end();
190
+ if (tail.length) {
191
+ yield tail;
192
+ }
193
+ } finally{
194
+ reader.releaseLock();
195
+ }
196
+ }
197
+ }
198
+
199
+ const mergeArrays2 = Function.prototype.apply.bind(mergeArrays, undefined);
200
+ const dash = stringToArray('--');
201
+ const CRLF = stringToArray('\r\n');
202
+ function parseContentDisposition(header) {
203
+ const parts = header.split(';').map((part)=>part.trim());
204
+ if (parts.shift() !== 'form-data') {
205
+ throw new Error('malformed content-disposition header: missing "form-data" in `' + JSON.stringify(parts) + '`');
206
+ }
207
+ const out = {};
208
+ for (const part of parts){
209
+ const kv = part.split('=', 2);
210
+ if (kv.length !== 2) {
211
+ throw new Error('malformed content-disposition header: key-value pair not found - ' + part + ' in `' + header + '`');
212
+ }
213
+ const [name, value] = kv;
214
+ if (value[0] === '"' && value[value.length - 1] === '"') {
215
+ out[name] = value.slice(1, -1).replace(/\\"/g, '"');
216
+ } else if (value[0] !== '"' && value[value.length - 1] !== '"') {
217
+ out[name] = value;
218
+ } else if (value[0] === '"' && value[value.length - 1] !== '"' || value[0] !== '"' && value[value.length - 1] === '"') {
219
+ throw new Error('malformed content-disposition header: mismatched quotations in `' + header + '`');
220
+ }
221
+ }
222
+ if (!out.name) {
223
+ throw new Error('malformed content-disposition header: missing field name in `' + header + '`');
224
+ }
225
+ return out;
226
+ }
227
+ function parsePartHeaders(lines) {
228
+ const entries = [];
229
+ let disposition = false;
230
+ let line;
231
+ while(typeof (line = lines.shift()) !== 'undefined'){
232
+ const colon = line.indexOf(':');
233
+ if (colon === -1) {
234
+ throw new Error('malformed multipart-form header: missing colon');
235
+ }
236
+ const header = line.slice(0, colon).trim().toLowerCase();
237
+ const value = line.slice(colon + 1).trim();
238
+ switch(header){
239
+ case 'content-disposition':
240
+ disposition = true;
241
+ entries.push(...Object.entries(parseContentDisposition(value)));
242
+ break;
243
+ case 'content-type':
244
+ entries.push([
245
+ 'contentType',
246
+ value
247
+ ]);
248
+ }
249
+ }
250
+ if (!disposition) {
251
+ throw new Error('malformed multipart-form header: missing content-disposition');
252
+ }
253
+ return Object.fromEntries(entries);
254
+ }
255
+ async function readHeaderLines(it, needle) {
256
+ let firstChunk = true;
257
+ let lastTokenWasMatch = false;
258
+ const headerLines = [
259
+ []
260
+ ];
261
+ const crlfSearch = new StreamSearch(CRLF);
262
+ for(;;){
263
+ const result = await it.next();
264
+ if (result.done) {
265
+ throw new Error('malformed multipart-form data: unexpected end of stream');
266
+ }
267
+ if (firstChunk && result.value !== MATCH && arraysEqual(result.value.slice(0, 2), dash)) {
268
+ return [
269
+ undefined,
270
+ new Uint8Array()
271
+ ];
272
+ }
273
+ let chunk;
274
+ if (result.value !== MATCH) {
275
+ chunk = result.value;
276
+ } else if (!lastTokenWasMatch) {
277
+ chunk = needle;
278
+ } else {
279
+ throw new Error('malformed multipart-form data: unexpected boundary');
280
+ }
281
+ if (!chunk.length) {
282
+ continue;
283
+ }
284
+ if (firstChunk) {
285
+ firstChunk = false;
286
+ }
287
+ const tokens = crlfSearch.feed(chunk);
288
+ for (const [i, token] of tokens.entries()){
289
+ const isMatch = token === MATCH;
290
+ if (!isMatch && !token.length) {
291
+ continue;
292
+ }
293
+ if (lastTokenWasMatch && isMatch) {
294
+ tokens.push(crlfSearch.end());
295
+ return [
296
+ headerLines.filter((chunks)=>chunks.length).map(mergeArrays2).map(arrayToString),
297
+ mergeArrays(...tokens.slice(i + 1).map((token)=>token === MATCH ? CRLF : token))
298
+ ];
299
+ }
300
+ if (lastTokenWasMatch = isMatch) {
301
+ headerLines.push([]);
302
+ } else {
303
+ headerLines[headerLines.length - 1].push(token);
304
+ }
305
+ }
306
+ }
307
+ }
308
+ async function* streamMultipart(body, boundary) {
309
+ const needle = mergeArrays(dash, stringToArray(boundary));
310
+ const it = new ReadableStreamSearch(needle, body)[Symbol.asyncIterator]();
311
+ for(;;){
312
+ const result = await it.next();
313
+ if (result.done) {
314
+ return;
315
+ }
316
+ if (result.value === MATCH) {
317
+ break;
318
+ }
319
+ }
320
+ const crlfSearch = new StreamSearch(CRLF);
321
+ for(;;){
322
+ const [headerLines, tail] = await readHeaderLines(it, needle);
323
+ if (!headerLines) {
324
+ return;
325
+ }
326
+ async function nextToken() {
327
+ const result = await it.next();
328
+ if (result.done) {
329
+ throw new Error('malformed multipart-form data: unexpected end of stream');
330
+ }
331
+ return result;
332
+ }
333
+ let trailingCRLF = false;
334
+ function feedChunk(chunk) {
335
+ const chunks = [];
336
+ for (const token of crlfSearch.feed(chunk)){
337
+ if (trailingCRLF) {
338
+ chunks.push(CRLF);
339
+ }
340
+ if (!(trailingCRLF = token === MATCH)) {
341
+ chunks.push(token);
342
+ }
343
+ }
344
+ return mergeArrays(...chunks);
345
+ }
346
+ let done = false;
347
+ async function nextChunk() {
348
+ const result = await nextToken();
349
+ let chunk;
350
+ if (result.value !== MATCH) {
351
+ chunk = result.value;
352
+ } else if (!trailingCRLF) {
353
+ chunk = CRLF;
354
+ } else {
355
+ done = true;
356
+ return {
357
+ value: crlfSearch.end()
358
+ };
359
+ }
360
+ return {
361
+ value: feedChunk(chunk)
362
+ };
363
+ }
364
+ const bufferedChunks = [
365
+ {
366
+ value: feedChunk(tail)
367
+ }
368
+ ];
369
+ yield {
370
+ ...parsePartHeaders(headerLines),
371
+ data: {
372
+ [Symbol.asyncIterator] () {
373
+ return this;
374
+ },
375
+ async next () {
376
+ for(;;){
377
+ const result = bufferedChunks.shift();
378
+ if (!result) {
379
+ break;
380
+ }
381
+ if (result.value.length > 0) {
382
+ return result;
383
+ }
384
+ }
385
+ for(;;){
386
+ if (done) {
387
+ return {
388
+ done,
389
+ value: undefined
390
+ };
391
+ }
392
+ const result = await nextChunk();
393
+ if (result.value.length > 0) {
394
+ return result;
395
+ }
396
+ }
397
+ }
398
+ }
399
+ };
400
+ while(!done){
401
+ bufferedChunks.push(await nextChunk());
402
+ }
403
+ }
404
+ }
405
+
406
+ // @trpc/server
407
+ function createNodeHTTPContentTypeHandler(contentTypeHandler) {
408
+ return ()=>contentTypeHandler;
409
+ }
410
+
411
+ class SliceStream extends Transform {
412
+ constructor(startIndex = 0, endIndex = Infinity){
413
+ super();
414
+ this.startIndex = startIndex;
415
+ this.endIndex = endIndex;
416
+ this.indexOffset = 0;
417
+ this.emitUp = false;
418
+ this.emitDown = false;
419
+ }
420
+ _transform(chunk, _, done) {
421
+ this.indexOffset += chunk.length;
422
+ if (!this.emitUp && this.indexOffset >= this.startIndex) {
423
+ this.emitUp = true;
424
+ const start = chunk.length - (this.indexOffset - this.startIndex);
425
+ if (this.indexOffset > this.endIndex) {
426
+ const end = chunk.length - (this.indexOffset - this.endIndex);
427
+ this.emitDown = true;
428
+ this.push(chunk.slice(start, end));
429
+ } else {
430
+ this.push(chunk.slice(start, chunk.length));
431
+ }
432
+ done();
433
+ return;
434
+ }
435
+ if (this.emitUp && !this.emitDown) {
436
+ if (this.indexOffset >= this.endIndex) {
437
+ this.emitDown = true;
438
+ this.push(chunk.slice(0, chunk.length - (this.indexOffset - this.endIndex)));
439
+ } else {
440
+ this.push(chunk);
441
+ }
442
+ done();
443
+ return;
444
+ }
445
+ done();
446
+ }
447
+ }
448
+ function streamSlice(startIndex = 0, endIndex = Infinity) {
449
+ return new SliceStream(startIndex, endIndex);
450
+ }
451
+
452
+ function composeUploadHandlers(...handlers) {
453
+ return async (part)=>{
454
+ for (const handler of handlers){
455
+ const value = await handler(part);
456
+ if (typeof value !== 'undefined' && value !== null) {
457
+ return value;
458
+ }
459
+ }
460
+ return undefined;
461
+ };
462
+ }
463
+ class MaxPartSizeExceededError extends Error {
464
+ constructor(field, maxBytes){
465
+ super(`Field "${field}" exceeded upload size of ${maxBytes} bytes.`);
466
+ this.field = field;
467
+ this.maxBytes = maxBytes;
468
+ }
469
+ }
470
+ class MaxBodySizeExceededError extends Error {
471
+ constructor(maxBytes){
472
+ super(`Body exceeded upload size of ${maxBytes} bytes.`);
473
+ this.maxBytes = maxBytes;
474
+ }
475
+ }
476
+
477
+ async function readableStreamToString(stream, encoding) {
478
+ const reader = stream.getReader();
479
+ const chunks = [];
480
+ async function read() {
481
+ const { done, value } = await reader.read();
482
+ if (done) {
483
+ return;
484
+ } else if (value) {
485
+ chunks.push(value);
486
+ }
487
+ await read();
488
+ }
489
+ await read();
490
+ return Buffer.concat(chunks).toString(encoding);
491
+ }
492
+ const defaultFilePathResolver = ({ filename })=>{
493
+ const ext = filename ? extname(filename) : '';
494
+ return 'upload_' + randomBytes(4).readUInt32LE(0) + ext;
495
+ };
496
+ async function uniqueFile(filepath) {
497
+ const ext = extname(filepath);
498
+ let uniqueFilepath = filepath;
499
+ for(let i = 1; await stat(uniqueFilepath).then(()=>true).catch(()=>false); i++){
500
+ uniqueFilepath = (ext ? filepath.slice(0, -ext.length) : filepath) + `-${new Date().getTime()}${ext}`;
501
+ }
502
+ return uniqueFilepath;
503
+ }
504
+ function createFileUploadHandler({ directory = tmpdir(), avoidFileConflicts = true, file = defaultFilePathResolver, filter, maxPartSize = 3000000 } = {}) {
505
+ return async ({ name, filename, contentType, data })=>{
506
+ if (!filename || filter && !await filter({
507
+ name,
508
+ filename,
509
+ contentType
510
+ })) {
511
+ return undefined;
512
+ }
513
+ const dir = typeof directory === 'string' ? directory : directory({
514
+ name,
515
+ filename,
516
+ contentType
517
+ });
518
+ if (!dir) {
519
+ return undefined;
520
+ }
521
+ const filedir = resolve(dir);
522
+ const path = typeof file === 'string' ? file : file({
523
+ name,
524
+ filename,
525
+ contentType
526
+ });
527
+ if (!path) {
528
+ return undefined;
529
+ }
530
+ let filepath = resolve(filedir, path);
531
+ if (avoidFileConflicts) {
532
+ filepath = await uniqueFile(filepath);
533
+ }
534
+ await mkdir(dirname(filepath), {
535
+ recursive: true
536
+ }).catch(()=>{});
537
+ const writeFileStream = createWriteStream(filepath);
538
+ let size = 0;
539
+ let deleteFile = false;
540
+ try {
541
+ for await (const chunk of data){
542
+ size += chunk.byteLength;
543
+ if (size > maxPartSize) {
544
+ deleteFile = true;
545
+ throw new MaxPartSizeExceededError(name, maxPartSize);
546
+ }
547
+ writeFileStream.write(chunk);
548
+ }
549
+ } finally{
550
+ writeFileStream.end();
551
+ await promisify(finished)(writeFileStream);
552
+ if (deleteFile) {
553
+ await rm(filepath).catch(()=>{});
554
+ }
555
+ }
556
+ return new NodeOnDiskFile(filepath, contentType);
557
+ };
558
+ }
559
+ let _Symbol_toStringTag = Symbol.toStringTag;
560
+ class NodeOnDiskFile {
561
+ constructor(filepath, type, slicer){
562
+ this.filepath = filepath;
563
+ this.type = type;
564
+ this.slicer = slicer;
565
+ this.lastModified = 0;
566
+ this.webkitRelativePath = '';
567
+ this[_Symbol_toStringTag] = 'File';
568
+ this.name = basename(filepath);
569
+ }
570
+ get size() {
571
+ const stats = statSync(this.filepath);
572
+ if (this.slicer) {
573
+ const slice = this.slicer.end - this.slicer.start;
574
+ return slice < 0 ? 0 : slice > stats.size ? stats.size : slice;
575
+ }
576
+ return stats.size;
577
+ }
578
+ slice(start, end, type) {
579
+ if (typeof start === 'number' && start < 0) start = this.size + start;
580
+ if (typeof end === 'number' && end < 0) end = this.size + end;
581
+ const startOffset = this.slicer?.start ?? 0;
582
+ start = startOffset + (start ?? 0);
583
+ end = startOffset + (end ?? this.size);
584
+ return new NodeOnDiskFile(this.filepath, typeof type === 'string' ? type : this.type, {
585
+ start,
586
+ end
587
+ });
588
+ }
589
+ async arrayBuffer() {
590
+ let stream = createReadStream(this.filepath);
591
+ if (this.slicer) {
592
+ stream = stream.pipe(streamSlice(this.slicer.start, this.slicer.end));
593
+ }
594
+ return new Promise((resolve, reject)=>{
595
+ const buf = [];
596
+ stream.on('data', (chunk)=>buf.push(chunk));
597
+ stream.on('end', ()=>{
598
+ resolve(Buffer.concat(buf));
599
+ });
600
+ stream.on('error', (err)=>{
601
+ reject(err);
602
+ });
603
+ });
604
+ }
605
+ stream() {
606
+ let stream = createReadStream(this.filepath);
607
+ if (this.slicer) {
608
+ stream = stream.pipe(streamSlice(this.slicer.start, this.slicer.end));
609
+ }
610
+ return Readable.toWeb(stream);
611
+ }
612
+ async text() {
613
+ return readableStreamToString(this.stream());
614
+ }
615
+ remove() {
616
+ return unlink(this.filepath);
617
+ }
618
+ getFilePath() {
619
+ return this.filepath;
620
+ }
621
+ }
622
+
623
+ function createMemoryUploadHandler({ filter, maxPartSize = 3000000 } = {}) {
624
+ return async ({ filename, contentType, name, data })=>{
625
+ if (filter && !await filter({
626
+ filename,
627
+ contentType,
628
+ name
629
+ })) {
630
+ return undefined;
631
+ }
632
+ let size = 0;
633
+ const chunks = [];
634
+ for await (const chunk of data){
635
+ size += chunk.byteLength;
636
+ if (size > maxPartSize) {
637
+ throw new MaxPartSizeExceededError(name, maxPartSize);
638
+ }
639
+ chunks.push(chunk);
640
+ }
641
+ return new File(chunks, filename, {
642
+ type: contentType
643
+ });
644
+ };
645
+ }
10
646
 
11
647
  const utfTextDecoder = new TextDecoder('utf-8');
12
648
  /**
@@ -105,4 +741,4 @@ const nodeHTTPFormDataContentTypeHandler = createNodeHTTPContentTypeHandler({
105
741
  }
106
742
  });
107
743
 
108
- export { MaxBodySizeExceededError, NodeOnDiskFile as experimental_NodeOnDiskFile, isMultipartFormDataRequest as experimental_isMultipartFormDataRequest, parseMultipartFormData as experimental_parseMultipartFormData, nodeHTTPFormDataContentTypeHandler };
744
+ 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 };