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

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 +811 -23
  48. package/dist/index.mjs +799 -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 +107 -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 +0,0 @@
1
- {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
@@ -1,203 +0,0 @@
1
- 'use strict';
2
-
3
- var search = require('./search.js');
4
- var utils = require('./utils.js');
5
-
6
- const mergeArrays2 = Function.prototype.apply.bind(utils.mergeArrays, undefined);
7
- const dash = utils.stringToArray('--');
8
- const CRLF = utils.stringToArray('\r\n');
9
- function parseContentDisposition(header) {
10
- const parts = header.split(';').map(part => part.trim());
11
- if (parts.shift() !== 'form-data') {
12
- throw new Error('malformed content-disposition header: missing "form-data" in `' + JSON.stringify(parts) + '`');
13
- }
14
- const out = {};
15
- for (const part of parts) {
16
- const kv = part.split('=', 2);
17
- if (kv.length !== 2) {
18
- throw new Error('malformed content-disposition header: key-value pair not found - ' + part + ' in `' + header + '`');
19
- }
20
- const [name, value] = kv;
21
- if (value[0] === '"' && value[value.length - 1] === '"') {
22
- out[name] = value.slice(1, -1).replace(/\\"/g, '"');
23
- } else if (value[0] !== '"' && value[value.length - 1] !== '"') {
24
- out[name] = value;
25
- } else if (value[0] === '"' && value[value.length - 1] !== '"' || value[0] !== '"' && value[value.length - 1] === '"') {
26
- throw new Error('malformed content-disposition header: mismatched quotations in `' + header + '`');
27
- }
28
- }
29
- if (!out.name) {
30
- throw new Error('malformed content-disposition header: missing field name in `' + header + '`');
31
- }
32
- return out;
33
- }
34
- function parsePartHeaders(lines) {
35
- const entries = [];
36
- let disposition = false;
37
- let line;
38
- while (typeof (line = lines.shift()) !== 'undefined') {
39
- const colon = line.indexOf(':');
40
- if (colon === -1) {
41
- throw new Error('malformed multipart-form header: missing colon');
42
- }
43
- const header = line.slice(0, colon).trim().toLowerCase();
44
- const value = line.slice(colon + 1).trim();
45
- switch (header) {
46
- case 'content-disposition':
47
- disposition = true;
48
- entries.push(...Object.entries(parseContentDisposition(value)));
49
- break;
50
- case 'content-type':
51
- entries.push([
52
- 'contentType',
53
- value
54
- ]);
55
- }
56
- }
57
- if (!disposition) {
58
- throw new Error('malformed multipart-form header: missing content-disposition');
59
- }
60
- return Object.fromEntries(entries);
61
- }
62
- async function readHeaderLines(it, needle) {
63
- let firstChunk = true;
64
- let lastTokenWasMatch = false;
65
- const headerLines = [[]];
66
- const crlfSearch = new search.StreamSearch(CRLF);
67
- for (;;) {
68
- const result = await it.next();
69
- if (result.done) {
70
- throw new Error('malformed multipart-form data: unexpected end of stream');
71
- }
72
- if (firstChunk && result.value !== search.MATCH && utils.arraysEqual(result.value.slice(0, 2), dash)) {
73
- return [
74
- undefined,
75
- new Uint8Array()
76
- ];
77
- }
78
- let chunk;
79
- if (result.value !== search.MATCH) {
80
- chunk = result.value;
81
- } else if (!lastTokenWasMatch) {
82
- chunk = needle;
83
- } else {
84
- throw new Error('malformed multipart-form data: unexpected boundary');
85
- }
86
- if (!chunk.length) {
87
- continue;
88
- }
89
- if (firstChunk) {
90
- firstChunk = false;
91
- }
92
- const tokens = crlfSearch.feed(chunk);
93
- for (const [i, token] of tokens.entries()) {
94
- const isMatch = token === search.MATCH;
95
- if (!isMatch && !token.length) {
96
- continue;
97
- }
98
- if (lastTokenWasMatch && isMatch) {
99
- tokens.push(crlfSearch.end());
100
- return [
101
- headerLines.filter(chunks => chunks.length).map(mergeArrays2).map(utils.arrayToString),
102
- utils.mergeArrays(...tokens.slice(i + 1).map(token => token === search.MATCH ? CRLF : token))
103
- ];
104
- }
105
- if (lastTokenWasMatch = isMatch) {
106
- headerLines.push([]);
107
- } else {
108
- headerLines[headerLines.length - 1].push(token);
109
- }
110
- }
111
- }
112
- }
113
- async function* streamMultipart(body, boundary) {
114
- const needle = utils.mergeArrays(dash, utils.stringToArray(boundary));
115
- const it = new search.ReadableStreamSearch(needle, body)[Symbol.asyncIterator]();
116
- for (;;) {
117
- const result = await it.next();
118
- if (result.done) {
119
- return;
120
- }
121
- if (result.value === search.MATCH) {
122
- break;
123
- }
124
- }
125
- const crlfSearch = new search.StreamSearch(CRLF);
126
- for (;;) {
127
- const [headerLines, tail] = await readHeaderLines(it, needle);
128
- if (!headerLines) {
129
- return;
130
- }
131
- async function nextToken() {
132
- const result = await it.next();
133
- if (result.done) {
134
- throw new Error('malformed multipart-form data: unexpected end of stream');
135
- }
136
- return result;
137
- }
138
- let trailingCRLF = false;
139
- function feedChunk(chunk) {
140
- const chunks = [];
141
- for (const token of crlfSearch.feed(chunk)) {
142
- if (trailingCRLF) {
143
- chunks.push(CRLF);
144
- }
145
- if (!(trailingCRLF = token === search.MATCH)) {
146
- chunks.push(token);
147
- }
148
- }
149
- return utils.mergeArrays(...chunks);
150
- }
151
- let done = false;
152
- async function nextChunk() {
153
- const result = await nextToken();
154
- let chunk;
155
- if (result.value !== search.MATCH) {
156
- chunk = result.value;
157
- } else if (!trailingCRLF) {
158
- chunk = CRLF;
159
- } else {
160
- done = true;
161
- return { value: crlfSearch.end() };
162
- }
163
- return { value: feedChunk(chunk) };
164
- }
165
- const bufferedChunks = [{ value: feedChunk(tail) }];
166
- yield {
167
- ...parsePartHeaders(headerLines),
168
- data: {
169
- [Symbol.asyncIterator]() {
170
- return this;
171
- },
172
- async next() {
173
- for (;;) {
174
- const result = bufferedChunks.shift();
175
- if (!result) {
176
- break;
177
- }
178
- if (result.value.length > 0) {
179
- return result;
180
- }
181
- }
182
- for (;;) {
183
- if (done) {
184
- return {
185
- done,
186
- value: undefined
187
- };
188
- }
189
- const result = await nextChunk();
190
- if (result.value.length > 0) {
191
- return result;
192
- }
193
- }
194
- }
195
- }
196
- };
197
- while (!done) {
198
- bufferedChunks.push(await nextChunk());
199
- }
200
- }
201
- }
202
-
203
- exports.streamMultipart = streamMultipart;
@@ -1,201 +0,0 @@
1
- import { ReadableStreamSearch, MATCH, StreamSearch } from './search.mjs';
2
- import { mergeArrays, stringToArray, arraysEqual, arrayToString } from './utils.mjs';
3
-
4
- const mergeArrays2 = Function.prototype.apply.bind(mergeArrays, undefined);
5
- const dash = stringToArray('--');
6
- const CRLF = stringToArray('\r\n');
7
- function parseContentDisposition(header) {
8
- const parts = header.split(';').map(part => part.trim());
9
- if (parts.shift() !== 'form-data') {
10
- throw new Error('malformed content-disposition header: missing "form-data" in `' + JSON.stringify(parts) + '`');
11
- }
12
- const out = {};
13
- for (const part of parts) {
14
- const kv = part.split('=', 2);
15
- if (kv.length !== 2) {
16
- throw new Error('malformed content-disposition header: key-value pair not found - ' + part + ' in `' + header + '`');
17
- }
18
- const [name, value] = kv;
19
- if (value[0] === '"' && value[value.length - 1] === '"') {
20
- out[name] = value.slice(1, -1).replace(/\\"/g, '"');
21
- } else if (value[0] !== '"' && value[value.length - 1] !== '"') {
22
- out[name] = value;
23
- } else if (value[0] === '"' && value[value.length - 1] !== '"' || value[0] !== '"' && value[value.length - 1] === '"') {
24
- throw new Error('malformed content-disposition header: mismatched quotations in `' + header + '`');
25
- }
26
- }
27
- if (!out.name) {
28
- throw new Error('malformed content-disposition header: missing field name in `' + header + '`');
29
- }
30
- return out;
31
- }
32
- function parsePartHeaders(lines) {
33
- const entries = [];
34
- let disposition = false;
35
- let line;
36
- while (typeof (line = lines.shift()) !== 'undefined') {
37
- const colon = line.indexOf(':');
38
- if (colon === -1) {
39
- throw new Error('malformed multipart-form header: missing colon');
40
- }
41
- const header = line.slice(0, colon).trim().toLowerCase();
42
- const value = line.slice(colon + 1).trim();
43
- switch (header) {
44
- case 'content-disposition':
45
- disposition = true;
46
- entries.push(...Object.entries(parseContentDisposition(value)));
47
- break;
48
- case 'content-type':
49
- entries.push([
50
- 'contentType',
51
- value
52
- ]);
53
- }
54
- }
55
- if (!disposition) {
56
- throw new Error('malformed multipart-form header: missing content-disposition');
57
- }
58
- return Object.fromEntries(entries);
59
- }
60
- async function readHeaderLines(it, needle) {
61
- let firstChunk = true;
62
- let lastTokenWasMatch = false;
63
- const headerLines = [[]];
64
- const crlfSearch = new StreamSearch(CRLF);
65
- for (;;) {
66
- const result = await it.next();
67
- if (result.done) {
68
- throw new Error('malformed multipart-form data: unexpected end of stream');
69
- }
70
- if (firstChunk && result.value !== MATCH && arraysEqual(result.value.slice(0, 2), dash)) {
71
- return [
72
- undefined,
73
- new Uint8Array()
74
- ];
75
- }
76
- let chunk;
77
- if (result.value !== MATCH) {
78
- chunk = result.value;
79
- } else if (!lastTokenWasMatch) {
80
- chunk = needle;
81
- } else {
82
- throw new Error('malformed multipart-form data: unexpected boundary');
83
- }
84
- if (!chunk.length) {
85
- continue;
86
- }
87
- if (firstChunk) {
88
- firstChunk = false;
89
- }
90
- const tokens = crlfSearch.feed(chunk);
91
- for (const [i, token] of tokens.entries()) {
92
- const isMatch = token === MATCH;
93
- if (!isMatch && !token.length) {
94
- continue;
95
- }
96
- if (lastTokenWasMatch && isMatch) {
97
- tokens.push(crlfSearch.end());
98
- return [
99
- headerLines.filter(chunks => chunks.length).map(mergeArrays2).map(arrayToString),
100
- mergeArrays(...tokens.slice(i + 1).map(token => token === MATCH ? CRLF : token))
101
- ];
102
- }
103
- if (lastTokenWasMatch = isMatch) {
104
- headerLines.push([]);
105
- } else {
106
- headerLines[headerLines.length - 1].push(token);
107
- }
108
- }
109
- }
110
- }
111
- async function* streamMultipart(body, boundary) {
112
- const needle = mergeArrays(dash, stringToArray(boundary));
113
- const it = new ReadableStreamSearch(needle, body)[Symbol.asyncIterator]();
114
- for (;;) {
115
- const result = await it.next();
116
- if (result.done) {
117
- return;
118
- }
119
- if (result.value === MATCH) {
120
- break;
121
- }
122
- }
123
- const crlfSearch = new StreamSearch(CRLF);
124
- for (;;) {
125
- const [headerLines, tail] = await readHeaderLines(it, needle);
126
- if (!headerLines) {
127
- return;
128
- }
129
- async function nextToken() {
130
- const result = await it.next();
131
- if (result.done) {
132
- throw new Error('malformed multipart-form data: unexpected end of stream');
133
- }
134
- return result;
135
- }
136
- let trailingCRLF = false;
137
- function feedChunk(chunk) {
138
- const chunks = [];
139
- for (const token of crlfSearch.feed(chunk)) {
140
- if (trailingCRLF) {
141
- chunks.push(CRLF);
142
- }
143
- if (!(trailingCRLF = token === MATCH)) {
144
- chunks.push(token);
145
- }
146
- }
147
- return mergeArrays(...chunks);
148
- }
149
- let done = false;
150
- async function nextChunk() {
151
- const result = await nextToken();
152
- let chunk;
153
- if (result.value !== MATCH) {
154
- chunk = result.value;
155
- } else if (!trailingCRLF) {
156
- chunk = CRLF;
157
- } else {
158
- done = true;
159
- return { value: crlfSearch.end() };
160
- }
161
- return { value: feedChunk(chunk) };
162
- }
163
- const bufferedChunks = [{ value: feedChunk(tail) }];
164
- yield {
165
- ...parsePartHeaders(headerLines),
166
- data: {
167
- [Symbol.asyncIterator]() {
168
- return this;
169
- },
170
- async next() {
171
- for (;;) {
172
- const result = bufferedChunks.shift();
173
- if (!result) {
174
- break;
175
- }
176
- if (result.value.length > 0) {
177
- return result;
178
- }
179
- }
180
- for (;;) {
181
- if (done) {
182
- return {
183
- done,
184
- value: undefined
185
- };
186
- }
187
- const result = await nextChunk();
188
- if (result.value.length > 0) {
189
- return result;
190
- }
191
- }
192
- }
193
- }
194
- };
195
- while (!done) {
196
- bufferedChunks.push(await nextChunk());
197
- }
198
- }
199
- }
200
-
201
- export { streamMultipart };
@@ -1,167 +0,0 @@
1
- 'use strict';
2
-
3
- var utils = require('./utils.js');
4
-
5
- function coerce(a) {
6
- if (a instanceof Uint8Array) {
7
- return index => a[index];
8
- }
9
- return a;
10
- }
11
- function jsmemcmp(buf1, pos1, buf2, pos2, len) {
12
- const fn1 = coerce(buf1);
13
- const fn2 = coerce(buf2);
14
- for (let i = 0; i < len; ++i) {
15
- if (fn1(pos1 + i) !== fn2(pos2 + i)) {
16
- return false;
17
- }
18
- }
19
- return true;
20
- }
21
- function createOccurenceTable(s) {
22
- const table = new Array(256).fill(s.length);
23
- if (s.length > 1) {
24
- for (let i = 0; i < s.length - 1; i++) {
25
- table[s[i]] = s.length - 1 - i;
26
- }
27
- }
28
- return table;
29
- }
30
- const MATCH = Symbol('Match');
31
- class StreamSearch {
32
- constructor(needle) {
33
- this._lookbehind = new Uint8Array();
34
- if (typeof needle === 'string') {
35
- this._needle = needle = utils.stringToArray(needle);
36
- } else {
37
- this._needle = needle;
38
- }
39
- this._lastChar = needle[needle.length - 1];
40
- this._occ = createOccurenceTable(needle);
41
- }
42
- feed(chunk) {
43
- let pos = 0;
44
- let tokens;
45
- const allTokens = [];
46
- while (pos !== chunk.length) {
47
- [pos, ...tokens] = this._feed(chunk, pos);
48
- allTokens.push(...tokens);
49
- }
50
- return allTokens;
51
- }
52
- end() {
53
- const tail = this._lookbehind;
54
- this._lookbehind = new Uint8Array();
55
- return tail;
56
- }
57
- _feed(data, bufPos) {
58
- const tokens = [];
59
- let pos = -this._lookbehind.length;
60
- if (pos < 0) {
61
- while (pos < 0 && pos <= data.length - this._needle.length) {
62
- const ch = this._charAt(data, pos + this._needle.length - 1);
63
- if (ch === this._lastChar && this._memcmp(data, pos, this._needle.length - 1)) {
64
- if (pos > -this._lookbehind.length) {
65
- tokens.push(this._lookbehind.slice(0, this._lookbehind.length + pos));
66
- }
67
- tokens.push(MATCH);
68
- this._lookbehind = new Uint8Array();
69
- return [
70
- pos + this._needle.length,
71
- ...tokens
72
- ];
73
- } else {
74
- pos += this._occ[ch];
75
- }
76
- }
77
- if (pos < 0) {
78
- while (pos < 0 && !this._memcmp(data, pos, data.length - pos)) {
79
- pos++;
80
- }
81
- }
82
- if (pos >= 0) {
83
- tokens.push(this._lookbehind);
84
- this._lookbehind = new Uint8Array();
85
- } else {
86
- const bytesToCutOff = this._lookbehind.length + pos;
87
- if (bytesToCutOff > 0) {
88
- tokens.push(this._lookbehind.slice(0, bytesToCutOff));
89
- this._lookbehind = this._lookbehind.slice(bytesToCutOff);
90
- }
91
- this._lookbehind = Uint8Array.from(new Array(this._lookbehind.length + data.length), (_, i) => this._charAt(data, i - this._lookbehind.length));
92
- return [
93
- data.length,
94
- ...tokens
95
- ];
96
- }
97
- }
98
- pos += bufPos;
99
- while (pos <= data.length - this._needle.length) {
100
- const ch = data[pos + this._needle.length - 1];
101
- if (ch === this._lastChar && data[pos] === this._needle[0] && jsmemcmp(this._needle, 0, data, pos, this._needle.length - 1)) {
102
- if (pos > bufPos) {
103
- tokens.push(data.slice(bufPos, pos));
104
- }
105
- tokens.push(MATCH);
106
- return [
107
- pos + this._needle.length,
108
- ...tokens
109
- ];
110
- } else {
111
- pos += this._occ[ch];
112
- }
113
- }
114
- if (pos < data.length) {
115
- while (pos < data.length && (data[pos] !== this._needle[0] || !jsmemcmp(data, pos, this._needle, 0, data.length - pos))) {
116
- ++pos;
117
- }
118
- if (pos < data.length) {
119
- this._lookbehind = data.slice(pos);
120
- }
121
- }
122
- if (pos > 0) {
123
- tokens.push(data.slice(bufPos, pos < data.length ? pos : data.length));
124
- }
125
- return [
126
- data.length,
127
- ...tokens
128
- ];
129
- }
130
- _charAt(data, pos) {
131
- if (pos < 0) {
132
- return this._lookbehind[this._lookbehind.length + pos];
133
- }
134
- return data[pos];
135
- }
136
- _memcmp(data, pos, len) {
137
- return jsmemcmp(this._charAt.bind(this, data), pos, this._needle, 0, len);
138
- }
139
- }
140
- class ReadableStreamSearch {
141
- constructor(needle, _readableStream) {
142
- this._readableStream = _readableStream;
143
- this._search = new StreamSearch(needle);
144
- }
145
- async *[Symbol.asyncIterator]() {
146
- const reader = this._readableStream.getReader();
147
- try {
148
- while (true) {
149
- const result = await reader.read();
150
- if (result.done) {
151
- break;
152
- }
153
- yield* this._search.feed(result.value);
154
- }
155
- const tail = this._search.end();
156
- if (tail.length) {
157
- yield tail;
158
- }
159
- } finally {
160
- reader.releaseLock();
161
- }
162
- }
163
- }
164
-
165
- exports.MATCH = MATCH;
166
- exports.ReadableStreamSearch = ReadableStreamSearch;
167
- exports.StreamSearch = StreamSearch;