@volter/tabnode 0.2.14-volter.88

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 (429) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +78 -0
  3. package/THIRD-PARTY-NOTICES.md +12 -0
  4. package/dist/__sw__.js +526 -0
  5. package/dist/assets/runtime-worker-4MKaHFVb.js +75221 -0
  6. package/dist/assets/runtime-worker-4MKaHFVb.js.map +1 -0
  7. package/dist/code-transforms.d.ts +21 -0
  8. package/dist/code-transforms.d.ts.map +1 -0
  9. package/dist/config/cdn.d.ts +12 -0
  10. package/dist/config/cdn.d.ts.map +1 -0
  11. package/dist/create-runtime.d.ts +22 -0
  12. package/dist/create-runtime.d.ts.map +1 -0
  13. package/dist/host-globals.d.ts +62 -0
  14. package/dist/host-globals.d.ts.map +1 -0
  15. package/dist/index.cjs +36021 -0
  16. package/dist/index.cjs.map +1 -0
  17. package/dist/index.d.ts +127 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.mjs +36020 -0
  20. package/dist/index.mjs.map +1 -0
  21. package/dist/node-internals.d.ts +68 -0
  22. package/dist/node-internals.d.ts.map +1 -0
  23. package/dist/node-lib/binding/blob.d.ts +12 -0
  24. package/dist/node-lib/binding/blob.d.ts.map +1 -0
  25. package/dist/node-lib/binding/buffer.d.ts +144 -0
  26. package/dist/node-lib/binding/buffer.d.ts.map +1 -0
  27. package/dist/node-lib/binding/cares_wrap.d.ts +14 -0
  28. package/dist/node-lib/binding/cares_wrap.d.ts.map +1 -0
  29. package/dist/node-lib/binding/fds.d.ts +30 -0
  30. package/dist/node-lib/binding/fds.d.ts.map +1 -0
  31. package/dist/node-lib/binding/fs.d.ts +157 -0
  32. package/dist/node-lib/binding/fs.d.ts.map +1 -0
  33. package/dist/node-lib/binding/handles.d.ts +81 -0
  34. package/dist/node-lib/binding/handles.d.ts.map +1 -0
  35. package/dist/node-lib/binding/http_parser.d.ts +122 -0
  36. package/dist/node-lib/binding/http_parser.d.ts.map +1 -0
  37. package/dist/node-lib/binding/index.d.ts +3 -0
  38. package/dist/node-lib/binding/index.d.ts.map +1 -0
  39. package/dist/node-lib/binding/llhttp-wasm.d.ts +22 -0
  40. package/dist/node-lib/binding/llhttp-wasm.d.ts.map +1 -0
  41. package/dist/node-lib/binding/misc.d.ts +123 -0
  42. package/dist/node-lib/binding/misc.d.ts.map +1 -0
  43. package/dist/node-lib/binding/pipe_wrap.d.ts +84 -0
  44. package/dist/node-lib/binding/pipe_wrap.d.ts.map +1 -0
  45. package/dist/node-lib/binding/process_wrap.d.ts +173 -0
  46. package/dist/node-lib/binding/process_wrap.d.ts.map +1 -0
  47. package/dist/node-lib/binding/spawn_sync.d.ts +30 -0
  48. package/dist/node-lib/binding/spawn_sync.d.ts.map +1 -0
  49. package/dist/node-lib/binding/stream_wrap.d.ts +191 -0
  50. package/dist/node-lib/binding/stream_wrap.d.ts.map +1 -0
  51. package/dist/node-lib/binding/stubs.d.ts +23 -0
  52. package/dist/node-lib/binding/stubs.d.ts.map +1 -0
  53. package/dist/node-lib/binding/tcp_wrap.d.ts +98 -0
  54. package/dist/node-lib/binding/tcp_wrap.d.ts.map +1 -0
  55. package/dist/node-lib/binding/tty_wrap.d.ts +36 -0
  56. package/dist/node-lib/binding/tty_wrap.d.ts.map +1 -0
  57. package/dist/node-lib/binding/util.d.ts +126 -0
  58. package/dist/node-lib/binding/util.d.ts.map +1 -0
  59. package/dist/node-lib/binding/uv.d.ts +32 -0
  60. package/dist/node-lib/binding/uv.d.ts.map +1 -0
  61. package/dist/node-lib/binding/zlib-pako.d.ts +22 -0
  62. package/dist/node-lib/binding/zlib-pako.d.ts.map +1 -0
  63. package/dist/node-lib/binding/zlib.d.ts +38 -0
  64. package/dist/node-lib/binding/zlib.d.ts.map +1 -0
  65. package/dist/node-lib/buffer-module.d.ts +51 -0
  66. package/dist/node-lib/buffer-module.d.ts.map +1 -0
  67. package/dist/node-lib/child-process-module.d.ts +26 -0
  68. package/dist/node-lib/child-process-module.d.ts.map +1 -0
  69. package/dist/node-lib/events-module.d.ts +58 -0
  70. package/dist/node-lib/events-module.d.ts.map +1 -0
  71. package/dist/node-lib/fs-module.d.ts +5 -0
  72. package/dist/node-lib/fs-module.d.ts.map +1 -0
  73. package/dist/node-lib/http-bridge.d.ts +43 -0
  74. package/dist/node-lib/http-bridge.d.ts.map +1 -0
  75. package/dist/node-lib/http-module.d.ts +35 -0
  76. package/dist/node-lib/http-module.d.ts.map +1 -0
  77. package/dist/node-lib/internals/addresses.d.ts +40 -0
  78. package/dist/node-lib/internals/addresses.d.ts.map +1 -0
  79. package/dist/node-lib/internals/buffer-and-streams.d.ts +96 -0
  80. package/dist/node-lib/internals/buffer-and-streams.d.ts.map +1 -0
  81. package/dist/node-lib/internals/child-process.d.ts +27 -0
  82. package/dist/node-lib/internals/child-process.d.ts.map +1 -0
  83. package/dist/node-lib/internals/events-util.d.ts +83 -0
  84. package/dist/node-lib/internals/events-util.d.ts.map +1 -0
  85. package/dist/node-lib/internals/index.d.ts +2 -0
  86. package/dist/node-lib/internals/index.d.ts.map +1 -0
  87. package/dist/node-lib/internals/modules.d.ts +67 -0
  88. package/dist/node-lib/internals/modules.d.ts.map +1 -0
  89. package/dist/node-lib/internals/readline-access.d.ts +2 -0
  90. package/dist/node-lib/internals/readline-access.d.ts.map +1 -0
  91. package/dist/node-lib/internals/runtime.d.ts +150 -0
  92. package/dist/node-lib/internals/runtime.d.ts.map +1 -0
  93. package/dist/node-lib/internals/util.d.ts +33 -0
  94. package/dist/node-lib/internals/util.d.ts.map +1 -0
  95. package/dist/node-lib/lazy.d.ts +31 -0
  96. package/dist/node-lib/lazy.d.ts.map +1 -0
  97. package/dist/node-lib/load.d.ts +27 -0
  98. package/dist/node-lib/load.d.ts.map +1 -0
  99. package/dist/node-lib/module-hooks.d.ts +89 -0
  100. package/dist/node-lib/module-hooks.d.ts.map +1 -0
  101. package/dist/node-lib/net-module.d.ts +181 -0
  102. package/dist/node-lib/net-module.d.ts.map +1 -0
  103. package/dist/node-lib/node-versions.d.ts +27 -0
  104. package/dist/node-lib/node-versions.d.ts.map +1 -0
  105. package/dist/node-lib/public-modules.d.ts +2 -0
  106. package/dist/node-lib/public-modules.d.ts.map +1 -0
  107. package/dist/node-lib/require-hook.d.ts +15 -0
  108. package/dist/node-lib/require-hook.d.ts.map +1 -0
  109. package/dist/node-lib/small-modules.d.ts +16 -0
  110. package/dist/node-lib/small-modules.d.ts.map +1 -0
  111. package/dist/node-lib/sources.d.ts +4 -0
  112. package/dist/node-lib/sources.d.ts.map +1 -0
  113. package/dist/node-lib/stream-module.d.ts +77 -0
  114. package/dist/node-lib/stream-module.d.ts.map +1 -0
  115. package/dist/node-lib/timers.d.ts +19 -0
  116. package/dist/node-lib/timers.d.ts.map +1 -0
  117. package/dist/node-lib/util-module.d.ts +76 -0
  118. package/dist/node-lib/util-module.d.ts.map +1 -0
  119. package/dist/node-resolution.d.ts +50 -0
  120. package/dist/node-resolution.d.ts.map +1 -0
  121. package/dist/node-resolver.d.ts +7 -0
  122. package/dist/node-resolver.d.ts.map +1 -0
  123. package/dist/npm/index.d.ts +73 -0
  124. package/dist/npm/index.d.ts.map +1 -0
  125. package/dist/npm/registry.d.ts +111 -0
  126. package/dist/npm/registry.d.ts.map +1 -0
  127. package/dist/npm/resolver.d.ts +79 -0
  128. package/dist/npm/resolver.d.ts.map +1 -0
  129. package/dist/npm/tarball.d.ts +28 -0
  130. package/dist/npm/tarball.d.ts.map +1 -0
  131. package/dist/process-tokens.d.ts +77 -0
  132. package/dist/process-tokens.d.ts.map +1 -0
  133. package/dist/punycode-source.d.ts +3 -0
  134. package/dist/punycode-source.d.ts.map +1 -0
  135. package/dist/runtime-interface.d.ts +74 -0
  136. package/dist/runtime-interface.d.ts.map +1 -0
  137. package/dist/runtime.d.ts +144 -0
  138. package/dist/runtime.d.ts.map +1 -0
  139. package/dist/server-bridge.d.ts +147 -0
  140. package/dist/server-bridge.d.ts.map +1 -0
  141. package/dist/shims/async_hooks.d.ts +50 -0
  142. package/dist/shims/async_hooks.d.ts.map +1 -0
  143. package/dist/shims/child_process.d.ts +104 -0
  144. package/dist/shims/child_process.d.ts.map +1 -0
  145. package/dist/shims/cluster.d.ts +52 -0
  146. package/dist/shims/cluster.d.ts.map +1 -0
  147. package/dist/shims/command-line.d.ts +43 -0
  148. package/dist/shims/command-line.d.ts.map +1 -0
  149. package/dist/shims/constants.d.ts +222 -0
  150. package/dist/shims/constants.d.ts.map +1 -0
  151. package/dist/shims/crypto-constants.d.ts +12 -0
  152. package/dist/shims/crypto-constants.d.ts.map +1 -0
  153. package/dist/shims/crypto.d.ts +144 -0
  154. package/dist/shims/crypto.d.ts.map +1 -0
  155. package/dist/shims/dgram.d.ts +34 -0
  156. package/dist/shims/dgram.d.ts.map +1 -0
  157. package/dist/shims/dns.d.ts +91 -0
  158. package/dist/shims/dns.d.ts.map +1 -0
  159. package/dist/shims/domain.d.ts +25 -0
  160. package/dist/shims/domain.d.ts.map +1 -0
  161. package/dist/shims/esbuild.d.ts +205 -0
  162. package/dist/shims/esbuild.d.ts.map +1 -0
  163. package/dist/shims/fs.d.ts +25 -0
  164. package/dist/shims/fs.d.ts.map +1 -0
  165. package/dist/shims/http2.d.ts +81 -0
  166. package/dist/shims/http2.d.ts.map +1 -0
  167. package/dist/shims/inspector.d.ts +25 -0
  168. package/dist/shims/inspector.d.ts.map +1 -0
  169. package/dist/shims/module.d.ts +22 -0
  170. package/dist/shims/module.d.ts.map +1 -0
  171. package/dist/shims/os.d.ts +159 -0
  172. package/dist/shims/os.d.ts.map +1 -0
  173. package/dist/shims/path.d.ts +52 -0
  174. package/dist/shims/path.d.ts.map +1 -0
  175. package/dist/shims/perf_hooks.d.ts +50 -0
  176. package/dist/shims/perf_hooks.d.ts.map +1 -0
  177. package/dist/shims/process.d.ts +226 -0
  178. package/dist/shims/process.d.ts.map +1 -0
  179. package/dist/shims/rollup.d.ts +71 -0
  180. package/dist/shims/rollup.d.ts.map +1 -0
  181. package/dist/shims/string_decoder.d.ts +41 -0
  182. package/dist/shims/string_decoder.d.ts.map +1 -0
  183. package/dist/shims/sync-child.d.ts +64 -0
  184. package/dist/shims/sync-child.d.ts.map +1 -0
  185. package/dist/shims/tls.d.ts +53 -0
  186. package/dist/shims/tls.d.ts.map +1 -0
  187. package/dist/shims/url.d.ts +84 -0
  188. package/dist/shims/url.d.ts.map +1 -0
  189. package/dist/shims/v8.d.ts +73 -0
  190. package/dist/shims/v8.d.ts.map +1 -0
  191. package/dist/shims/vfs-adapter.d.ts +126 -0
  192. package/dist/shims/vfs-adapter.d.ts.map +1 -0
  193. package/dist/shims/vm.d.ts +52 -0
  194. package/dist/shims/vm.d.ts.map +1 -0
  195. package/dist/shims/wasi.d.ts +78 -0
  196. package/dist/shims/wasi.d.ts.map +1 -0
  197. package/dist/shims/worker_threads.d.ts +66 -0
  198. package/dist/shims/worker_threads.d.ts.map +1 -0
  199. package/dist/shims/zlib-constants.d.ts +66 -0
  200. package/dist/shims/zlib-constants.d.ts.map +1 -0
  201. package/dist/shims/zlib.d.ts +102 -0
  202. package/dist/shims/zlib.d.ts.map +1 -0
  203. package/dist/transform.d.ts +24 -0
  204. package/dist/transform.d.ts.map +1 -0
  205. package/dist/types/package-json.d.ts +18 -0
  206. package/dist/types/package-json.d.ts.map +1 -0
  207. package/dist/utils/binary-encoding.d.ts +13 -0
  208. package/dist/utils/binary-encoding.d.ts.map +1 -0
  209. package/dist/utils/glob.d.ts +19 -0
  210. package/dist/utils/glob.d.ts.map +1 -0
  211. package/dist/utils/hash.d.ts +6 -0
  212. package/dist/utils/hash.d.ts.map +1 -0
  213. package/dist/virtual-fs.d.ts +259 -0
  214. package/dist/virtual-fs.d.ts.map +1 -0
  215. package/dist/vite-plugin.cjs +50 -0
  216. package/dist/vite-plugin.cjs.map +1 -0
  217. package/dist/vite-plugin.d.ts +36 -0
  218. package/dist/vite-plugin.d.ts.map +1 -0
  219. package/dist/vite-plugin.mjs +31 -0
  220. package/dist/vite-plugin.mjs.map +1 -0
  221. package/dist/worker/runtime-worker.d.ts +8 -0
  222. package/dist/worker/runtime-worker.d.ts.map +1 -0
  223. package/dist/worker-runtime.d.ts +50 -0
  224. package/dist/worker-runtime.d.ts.map +1 -0
  225. package/package.json +88 -0
  226. package/src/code-transforms.ts +560 -0
  227. package/src/config/cdn.ts +13 -0
  228. package/src/create-runtime.ts +89 -0
  229. package/src/host-globals.ts +121 -0
  230. package/src/index.ts +235 -0
  231. package/src/node-internals.ts +283 -0
  232. package/src/node-lib/LICENSE +47 -0
  233. package/src/node-lib/_http_agent.js +547 -0
  234. package/src/node-lib/_http_client.js +996 -0
  235. package/src/node-lib/_http_common.js +269 -0
  236. package/src/node-lib/_http_incoming.js +453 -0
  237. package/src/node-lib/_http_outgoing.js +1262 -0
  238. package/src/node-lib/_http_server.js +1230 -0
  239. package/src/node-lib/assert/strict.js +3 -0
  240. package/src/node-lib/assert.js +844 -0
  241. package/src/node-lib/binding/blob.ts +35 -0
  242. package/src/node-lib/binding/buffer.ts +465 -0
  243. package/src/node-lib/binding/cares_wrap.ts +57 -0
  244. package/src/node-lib/binding/fds.ts +80 -0
  245. package/src/node-lib/binding/fs.ts +857 -0
  246. package/src/node-lib/binding/handles.ts +187 -0
  247. package/src/node-lib/binding/http_parser.ts +536 -0
  248. package/src/node-lib/binding/index.ts +77 -0
  249. package/src/node-lib/binding/llhttp-wasm.ts +670 -0
  250. package/src/node-lib/binding/misc.ts +252 -0
  251. package/src/node-lib/binding/pipe_wrap.ts +166 -0
  252. package/src/node-lib/binding/process_wrap.ts +371 -0
  253. package/src/node-lib/binding/spawn_sync.ts +141 -0
  254. package/src/node-lib/binding/stream_wrap.ts +413 -0
  255. package/src/node-lib/binding/stubs.ts +19 -0
  256. package/src/node-lib/binding/tcp_wrap.ts +254 -0
  257. package/src/node-lib/binding/tty_wrap.ts +56 -0
  258. package/src/node-lib/binding/util.ts +274 -0
  259. package/src/node-lib/binding/uv.ts +102 -0
  260. package/src/node-lib/binding/zlib-pako.ts +50 -0
  261. package/src/node-lib/binding/zlib.ts +259 -0
  262. package/src/node-lib/buffer-module.ts +70 -0
  263. package/src/node-lib/buffer.js +1373 -0
  264. package/src/node-lib/child-process-module.ts +58 -0
  265. package/src/node-lib/child_process.js +1046 -0
  266. package/src/node-lib/constants.js +41 -0
  267. package/src/node-lib/diagnostics_channel.js +438 -0
  268. package/src/node-lib/events-module.ts +80 -0
  269. package/src/node-lib/events.js +1223 -0
  270. package/src/node-lib/fs-module.ts +43 -0
  271. package/src/node-lib/fs.js +3377 -0
  272. package/src/node-lib/http-bridge.ts +299 -0
  273. package/src/node-lib/http-module.ts +53 -0
  274. package/src/node-lib/http.js +198 -0
  275. package/src/node-lib/https.js +429 -0
  276. package/src/node-lib/internal/assert/assertion_error.js +417 -0
  277. package/src/node-lib/internal/assert/calltracker.js +153 -0
  278. package/src/node-lib/internal/assert/myers_diff.js +177 -0
  279. package/src/node-lib/internal/assert/utils.js +278 -0
  280. package/src/node-lib/internal/buffer.js +1120 -0
  281. package/src/node-lib/internal/child_process/serialization.js +169 -0
  282. package/src/node-lib/internal/child_process.js +1135 -0
  283. package/src/node-lib/internal/constants.js +56 -0
  284. package/src/node-lib/internal/deps/minimatch/index.js +1628 -0
  285. package/src/node-lib/internal/errors.js +1912 -0
  286. package/src/node-lib/internal/events/abort_listener.js +54 -0
  287. package/src/node-lib/internal/events/symbols.js +11 -0
  288. package/src/node-lib/internal/fixed_queue.js +119 -0
  289. package/src/node-lib/internal/freelist.js +30 -0
  290. package/src/node-lib/internal/fs/cp/cp-sync.js +242 -0
  291. package/src/node-lib/internal/fs/cp/cp.js +382 -0
  292. package/src/node-lib/internal/fs/dir.js +369 -0
  293. package/src/node-lib/internal/fs/glob.js +763 -0
  294. package/src/node-lib/internal/fs/promises.js +1312 -0
  295. package/src/node-lib/internal/fs/read/context.js +129 -0
  296. package/src/node-lib/internal/fs/recursive_watch.js +275 -0
  297. package/src/node-lib/internal/fs/rimraf.js +311 -0
  298. package/src/node-lib/internal/fs/streams.js +571 -0
  299. package/src/node-lib/internal/fs/sync_write_stream.js +49 -0
  300. package/src/node-lib/internal/fs/utils.js +987 -0
  301. package/src/node-lib/internal/fs/watchers.js +418 -0
  302. package/src/node-lib/internal/http.js +62 -0
  303. package/src/node-lib/internal/mime.js +389 -0
  304. package/src/node-lib/internal/modules/customization_hooks.js +406 -0
  305. package/src/node-lib/internal/net.js +95 -0
  306. package/src/node-lib/internal/querystring.js +119 -0
  307. package/src/node-lib/internal/readline/callbacks.js +132 -0
  308. package/src/node-lib/internal/readline/emitKeypressEvents.js +99 -0
  309. package/src/node-lib/internal/readline/interface.js +1418 -0
  310. package/src/node-lib/internal/readline/promises.js +144 -0
  311. package/src/node-lib/internal/readline/utils.js +405 -0
  312. package/src/node-lib/internal/socket_list.js +108 -0
  313. package/src/node-lib/internal/stream_base_commons.js +280 -0
  314. package/src/node-lib/internal/streams/add-abort-signal.js +60 -0
  315. package/src/node-lib/internal/streams/compose.js +257 -0
  316. package/src/node-lib/internal/streams/destroy.js +361 -0
  317. package/src/node-lib/internal/streams/duplex.js +203 -0
  318. package/src/node-lib/internal/streams/duplexify.js +379 -0
  319. package/src/node-lib/internal/streams/duplexpair.js +62 -0
  320. package/src/node-lib/internal/streams/end-of-stream.js +331 -0
  321. package/src/node-lib/internal/streams/from.js +208 -0
  322. package/src/node-lib/internal/streams/lazy_transform.js +57 -0
  323. package/src/node-lib/internal/streams/legacy.js +125 -0
  324. package/src/node-lib/internal/streams/operators.js +436 -0
  325. package/src/node-lib/internal/streams/passthrough.js +47 -0
  326. package/src/node-lib/internal/streams/pipeline.js +465 -0
  327. package/src/node-lib/internal/streams/readable.js +1762 -0
  328. package/src/node-lib/internal/streams/state.js +51 -0
  329. package/src/node-lib/internal/streams/transform.js +204 -0
  330. package/src/node-lib/internal/streams/utils.js +363 -0
  331. package/src/node-lib/internal/streams/writable.js +1163 -0
  332. package/src/node-lib/internal/tty.js +260 -0
  333. package/src/node-lib/internal/util/colors.js +40 -0
  334. package/src/node-lib/internal/util/comparisons.js +1028 -0
  335. package/src/node-lib/internal/util/debuglog.js +524 -0
  336. package/src/node-lib/internal/util/inspect.js +2535 -0
  337. package/src/node-lib/internal/util/parse_args/parse_args.js +412 -0
  338. package/src/node-lib/internal/util/parse_args/utils.js +197 -0
  339. package/src/node-lib/internal/util.js +1003 -0
  340. package/src/node-lib/internal/validators.js +654 -0
  341. package/src/node-lib/internals/addresses.ts +159 -0
  342. package/src/node-lib/internals/buffer-and-streams.ts +224 -0
  343. package/src/node-lib/internals/child-process.ts +64 -0
  344. package/src/node-lib/internals/events-util.ts +105 -0
  345. package/src/node-lib/internals/index.ts +66 -0
  346. package/src/node-lib/internals/modules.ts +117 -0
  347. package/src/node-lib/internals/readline-access.ts +16 -0
  348. package/src/node-lib/internals/runtime.ts +277 -0
  349. package/src/node-lib/internals/util.ts +98 -0
  350. package/src/node-lib/lazy.ts +158 -0
  351. package/src/node-lib/load.ts +390 -0
  352. package/src/node-lib/module-hooks.ts +281 -0
  353. package/src/node-lib/net-module.ts +248 -0
  354. package/src/node-lib/net.js +2540 -0
  355. package/src/node-lib/node-versions.ts +34 -0
  356. package/src/node-lib/os.js +356 -0
  357. package/src/node-lib/path.js +1694 -0
  358. package/src/node-lib/primordials.js +743 -0
  359. package/src/node-lib/public-modules.ts +109 -0
  360. package/src/node-lib/punycode.js +455 -0
  361. package/src/node-lib/querystring.js +484 -0
  362. package/src/node-lib/readline/promises.js +73 -0
  363. package/src/node-lib/readline.js +523 -0
  364. package/src/node-lib/require-hook.ts +27 -0
  365. package/src/node-lib/small-modules.ts +35 -0
  366. package/src/node-lib/sources.ts +200 -0
  367. package/src/node-lib/stream/promises.js +44 -0
  368. package/src/node-lib/stream-module.ts +101 -0
  369. package/src/node-lib/stream.js +152 -0
  370. package/src/node-lib/timers.ts +33 -0
  371. package/src/node-lib/tty.js +168 -0
  372. package/src/node-lib/util-module.ts +104 -0
  373. package/src/node-lib/util.js +689 -0
  374. package/src/node-lib/wasi.js +179 -0
  375. package/src/node-lib/zlib.js +1036 -0
  376. package/src/node-resolution.ts +241 -0
  377. package/src/node-resolver.ts +33 -0
  378. package/src/npm/index.ts +425 -0
  379. package/src/npm/registry.ts +235 -0
  380. package/src/npm/resolver.ts +589 -0
  381. package/src/npm/tarball.ts +246 -0
  382. package/src/process-tokens.ts +156 -0
  383. package/src/punycode-source.ts +6 -0
  384. package/src/runtime-interface.ts +85 -0
  385. package/src/runtime.ts +3073 -0
  386. package/src/server-bridge.ts +971 -0
  387. package/src/shims/async_hooks.ts +181 -0
  388. package/src/shims/child_process.ts +1591 -0
  389. package/src/shims/cluster.ts +79 -0
  390. package/src/shims/command-line.ts +79 -0
  391. package/src/shims/constants.ts +68 -0
  392. package/src/shims/crypto-constants.ts +11 -0
  393. package/src/shims/crypto.ts +1061 -0
  394. package/src/shims/dgram.ts +47 -0
  395. package/src/shims/dns.ts +185 -0
  396. package/src/shims/domain.ts +58 -0
  397. package/src/shims/esbuild.ts +1638 -0
  398. package/src/shims/fs.ts +82 -0
  399. package/src/shims/http2.ts +96 -0
  400. package/src/shims/inspector.ts +30 -0
  401. package/src/shims/module.ts +86 -0
  402. package/src/shims/os.ts +195 -0
  403. package/src/shims/path.ts +246 -0
  404. package/src/shims/perf_hooks.ts +92 -0
  405. package/src/shims/process.ts +804 -0
  406. package/src/shims/rollup.ts +149 -0
  407. package/src/shims/string_decoder.ts +396 -0
  408. package/src/shims/sync-child.ts +469 -0
  409. package/src/shims/tls.ts +94 -0
  410. package/src/shims/url.ts +217 -0
  411. package/src/shims/v8.ts +113 -0
  412. package/src/shims/vfs-adapter.ts +408 -0
  413. package/src/shims/vm.ts +132 -0
  414. package/src/shims/wasi.ts +1440 -0
  415. package/src/shims/worker_threads.ts +114 -0
  416. package/src/shims/zlib-constants.ts +65 -0
  417. package/src/shims/zlib.ts +228 -0
  418. package/src/transform.ts +324 -0
  419. package/src/types/external.d.ts +55 -0
  420. package/src/types/package-json.ts +17 -0
  421. package/src/types/pako-zlib.d.ts +30 -0
  422. package/src/types/sha.js.d.ts +14 -0
  423. package/src/utils/binary-encoding.ts +43 -0
  424. package/src/utils/glob.ts +54 -0
  425. package/src/utils/hash.ts +12 -0
  426. package/src/virtual-fs.ts +1048 -0
  427. package/src/vite-plugin.ts +76 -0
  428. package/src/worker/runtime-worker.ts +128 -0
  429. package/src/worker-runtime.ts +145 -0
@@ -0,0 +1,536 @@
1
+ /**
2
+ * `internalBinding('http_parser')`: Node's `HTTPParser`, on llhttp's own
3
+ * WebAssembly build.
4
+ *
5
+ * Node parses HTTP with llhttp, a C parser it links. The engine's `http` was
6
+ * a hand-written parser in TypeScript, and a hand-written HTTP parser is the
7
+ * shape of bug that does not announce itself: a chunked body whose extension
8
+ * it ignores, a header it folds where Node rejects, a request it accepts that
9
+ * a proxy in front of it reads differently. So the parser here is llhttp
10
+ * itself -- the same parser, the same state machine, the same rejections --
11
+ * compiled to wasm (see `./llhttp-wasm.ts` for the build and its provenance),
12
+ * and this file is only the shape Node's own `_http_common.js` expects around
13
+ * it.
14
+ *
15
+ * WHAT THIS FILE DOES, and nothing else: it hands llhttp the bytes, turns
16
+ * llhttp's eight callbacks into the seven Node hangs off a parser by index,
17
+ * and reports an error the way `execute` reports one. Every rule about
18
+ * HTTP -- what a valid method is, when a message needs EOF, whether a
19
+ * connection may be kept alive -- is llhttp's answer, read back through its
20
+ * own exports.
21
+ *
22
+ * THE ONE ENVIRONMENTAL REQUIREMENT: the module is compiled synchronously,
23
+ * on the first parser a program makes. A browser refuses a synchronous
24
+ * compile of more than 4 KB on the MAIN thread, so `http` works where the
25
+ * engine runs a guest -- the substrate's execution worker, a Node process --
26
+ * and a main-thread realm that asks for it is told exactly that rather than
27
+ * left with a parser that does nothing.
28
+ */
29
+ import { LLHTTP_WASM_BASE64 } from './llhttp-wasm';
30
+
31
+ /** llhttp's `llhttp_type`. */
32
+ const TYPE_REQUEST = 1;
33
+ const TYPE_RESPONSE = 2;
34
+
35
+ /** llhttp's `llhttp_errno`, the ones this file acts on. */
36
+ const ERROR_OK = 0;
37
+ const ERROR_PAUSED = 21;
38
+ const ERROR_PAUSED_UPGRADE = 22;
39
+
40
+ /** The callback slots Node hangs off a parser, by the index its C++ uses. */
41
+ const kOnMessageBegin = 0;
42
+ const kOnHeaders = 1;
43
+ const kOnHeadersComplete = 2;
44
+ const kOnBody = 3;
45
+ const kOnMessageComplete = 4;
46
+ const kOnExecute = 5;
47
+ const kOnTimeout = 6;
48
+
49
+ interface LlhttpExports {
50
+ memory: WebAssembly.Memory;
51
+ _initialize(): void;
52
+ llhttp_alloc(type: number): number;
53
+ llhttp_free(ptr: number): void;
54
+ llhttp_reset(ptr: number): void;
55
+ llhttp_execute(ptr: number, data: number, len: number): number;
56
+ llhttp_finish(ptr: number): number;
57
+ llhttp_resume(ptr: number): void;
58
+ llhttp_resume_after_upgrade(ptr: number): void;
59
+ llhttp_pause(ptr: number): void;
60
+ llhttp_get_error_pos(ptr: number): number;
61
+ llhttp_get_error_reason(ptr: number): number;
62
+ llhttp_get_errno(ptr: number): number;
63
+ llhttp_errno_name(errno: number): number;
64
+ llhttp_method_name(method: number): number;
65
+ llhttp_get_http_major(ptr: number): number;
66
+ llhttp_get_http_minor(ptr: number): number;
67
+ llhttp_get_method(ptr: number): number;
68
+ llhttp_get_status_code(ptr: number): number;
69
+ llhttp_get_upgrade(ptr: number): number;
70
+ llhttp_should_keep_alive(ptr: number): number;
71
+ llhttp_message_needs_eof(ptr: number): number;
72
+ llhttp_set_lenient_headers(ptr: number, on: number): void;
73
+ llhttp_set_lenient_chunked_length(ptr: number, on: number): void;
74
+ llhttp_set_lenient_keep_alive(ptr: number, on: number): void;
75
+ llhttp_set_lenient_transfer_encoding(ptr: number, on: number): void;
76
+ malloc(size: number): number;
77
+ free(ptr: number): void;
78
+ }
79
+
80
+ /** The parser whose `execute` is on the stack; llhttp's callbacks carry no state of ours. */
81
+ // eslint-disable-next-line no-var, vars-on-top
82
+ var current: HTTPParser | null = null;
83
+ // eslint-disable-next-line no-var, vars-on-top
84
+ var wasm: LlhttpExports | undefined;
85
+ // eslint-disable-next-line no-var, vars-on-top
86
+ var memoryBytes: Uint8Array | undefined;
87
+
88
+ /** The realm's own decoder, over a latin1 view: HTTP's header bytes are latin1. */
89
+ // eslint-disable-next-line no-var, vars-on-top
90
+ var latin1: TextDecoder | undefined;
91
+
92
+ function decode(at: number, length: number): string {
93
+ latin1 ??= new TextDecoder('latin1');
94
+ return latin1.decode(bytes().subarray(at, at + length));
95
+ }
96
+
97
+ function bytes(): Uint8Array {
98
+ // A wasm memory can grow, and a view over the old buffer is detached when
99
+ // it does; the view is taken again whenever the buffer is not the one it
100
+ // was made from.
101
+ const memory = llhttp().memory;
102
+ if (memoryBytes === undefined || memoryBytes.buffer !== memory.buffer) {
103
+ memoryBytes = new Uint8Array(memory.buffer);
104
+ }
105
+ return memoryBytes;
106
+ }
107
+
108
+ function llhttp(): LlhttpExports {
109
+ if (wasm !== undefined) return wasm;
110
+ let module: WebAssembly.Module;
111
+ try {
112
+ const binary = Uint8Array.from(atob(LLHTTP_WASM_BASE64), (character) => character.charCodeAt(0));
113
+ module = new WebAssembly.Module(binary);
114
+ } catch (error) {
115
+ throw Object.assign(new Error(
116
+ 'http: llhttp could not be compiled in this realm. A browser refuses a synchronous ' +
117
+ 'WebAssembly compile of more than 4 KB on the main thread; the engine parses HTTP ' +
118
+ 'where it runs a guest, which is a worker.',
119
+ ), { cause: error, code: 'ERR_HTTP_PARSER_UNAVAILABLE' });
120
+ }
121
+ const instance = new WebAssembly.Instance(module, {
122
+ env: {
123
+ wasm_on_message_begin: (): number => current!.onMessageBegin(),
124
+ wasm_on_url: (_p: number, at: number, length: number): number => current!.onUrl(at, length),
125
+ wasm_on_status: (_p: number, at: number, length: number): number => current!.onStatus(at, length),
126
+ wasm_on_header_field: (_p: number, at: number, length: number): number => current!.onHeaderField(at, length),
127
+ wasm_on_header_value: (_p: number, at: number, length: number): number => current!.onHeaderValue(at, length),
128
+ wasm_on_headers_complete: (_p: number, statusCode: number, upgrade: number, shouldKeepAlive: number): number =>
129
+ current!.onHeadersComplete(statusCode, Boolean(upgrade), Boolean(shouldKeepAlive)),
130
+ wasm_on_body: (_p: number, at: number, length: number): number => current!.onBody(at, length),
131
+ wasm_on_message_complete: (): number => current!.onMessageComplete(),
132
+ },
133
+ });
134
+ wasm = instance.exports as unknown as LlhttpExports;
135
+ wasm._initialize();
136
+ return wasm;
137
+ }
138
+
139
+ /** A C string out of the module's memory, for llhttp's own error text. */
140
+ function cstring(ptr: number): string {
141
+ if (ptr === 0) return '';
142
+ const view = bytes();
143
+ let end = ptr;
144
+ while (view[end] !== 0) end += 1;
145
+ return decode(ptr, end - ptr);
146
+ }
147
+
148
+ /**
149
+ * Every method llhttp knows, by its own number, asked of llhttp rather than
150
+ * written down here: `allMethods[method]` is what `_http_common.js` reads to
151
+ * name a request's method, and a table written twice is a table that drifts.
152
+ */
153
+ // eslint-disable-next-line no-var, vars-on-top
154
+ var allMethodsCache: string[] | undefined;
155
+ function allMethodsOf(): string[] {
156
+ if (allMethodsCache) return allMethodsCache;
157
+ const exports = llhttp();
158
+ const names: string[] = [];
159
+ for (let method = 0; ; method += 1) {
160
+ let name: string;
161
+ // llhttp traps on a method it does not have rather than answering an
162
+ // empty name, so the end of its table is the first call that traps.
163
+ try { name = cstring(exports.llhttp_method_name(method)); } catch { break; }
164
+ if (name === '') break;
165
+ names.push(name);
166
+ }
167
+ allMethodsCache = names;
168
+ return names;
169
+ }
170
+
171
+ type ParserCallback = ((...args: never[]) => unknown) | null;
172
+
173
+ export class HTTPParser {
174
+ static readonly REQUEST = TYPE_REQUEST;
175
+ static readonly RESPONSE = TYPE_RESPONSE;
176
+ static readonly kOnMessageBegin = kOnMessageBegin;
177
+ static readonly kOnHeaders = kOnHeaders;
178
+ static readonly kOnHeadersComplete = kOnHeadersComplete;
179
+ static readonly kOnBody = kOnBody;
180
+ static readonly kOnMessageComplete = kOnMessageComplete;
181
+ static readonly kOnExecute = kOnExecute;
182
+ static readonly kOnTimeout = kOnTimeout;
183
+ /** Node's lenient flags. Each one llhttp itself can be told about is passed on. */
184
+ static readonly kLenientNone = 0;
185
+ static readonly kLenientHeaders = 1;
186
+ static readonly kLenientChunkedLength = 2;
187
+ static readonly kLenientKeepAlive = 4;
188
+ static readonly kLenientTransferEncoding = 8;
189
+ static readonly kLenientVersion = 16;
190
+ static readonly kLenientDataAfterClose = 32;
191
+ static readonly kLenientOptionalLFAfterCR = 64;
192
+ static readonly kLenientOptionalCRLFAfterChunk = 128;
193
+ static readonly kLenientOptionalCRBeforeLF = 256;
194
+ static readonly kLenientSpacesAfterChunkSize = 512;
195
+ static readonly kLenientAll = 1023;
196
+
197
+ [kOnMessageBegin]: ParserCallback = null;
198
+ [kOnHeaders]: ParserCallback = null;
199
+ [kOnHeadersComplete]: ParserCallback = null;
200
+ [kOnBody]: ParserCallback = null;
201
+ [kOnMessageComplete]: ParserCallback = null;
202
+ [kOnExecute]: ParserCallback = null;
203
+ [kOnTimeout]: ParserCallback = null;
204
+
205
+ #ptr = 0;
206
+ #type = TYPE_REQUEST;
207
+ #maxHeaderSize = 16 * 1024;
208
+ #headerBytes = 0;
209
+ #headers: string[] = [];
210
+ #field = '';
211
+ #value = '';
212
+ #readingValue = false;
213
+ #url = '';
214
+ #statusMessage = '';
215
+ #headersSent = false;
216
+ #paused = false;
217
+ /** The buffer `execute` is walking, which `getCurrentBuffer` answers with. */
218
+ #buffer: Uint8Array | null = null;
219
+ #bufferPtr = 0;
220
+ #bufferSize = 0;
221
+ #connections: ConnectionsList | undefined;
222
+ /** The socket `_http_server.js` hangs on a parser, and reads off one here. */
223
+ socket?: { destroy(): void } | null;
224
+ /** When this connection's current head and current message began, in ms. */
225
+ headersStart = 0;
226
+ messageStart = 0;
227
+ /** Whether a message is in flight, which is what `idle()` is the absence of. */
228
+ active = false;
229
+
230
+ /**
231
+ * `parser.initialize(type, resource, maxHeaderSize, lenient, headersTimeout)`,
232
+ * which Node calls for every parser it takes off its free list.
233
+ */
234
+ initialize(type: number, _resource?: unknown, maxHeaderSize?: number, lenient?: number, connections?: ConnectionsList): void {
235
+ const exports = llhttp();
236
+ if (this.#ptr !== 0) exports.llhttp_free(this.#ptr);
237
+ this.#type = type;
238
+ this.#ptr = exports.llhttp_alloc(type);
239
+ this.#maxHeaderSize = maxHeaderSize && maxHeaderSize > 0 ? maxHeaderSize : 16 * 1024;
240
+ const flags = lenient ?? 0;
241
+ exports.llhttp_set_lenient_headers(this.#ptr, flags & HTTPParser.kLenientHeaders ? 1 : 0);
242
+ exports.llhttp_set_lenient_chunked_length(this.#ptr, flags & HTTPParser.kLenientChunkedLength ? 1 : 0);
243
+ exports.llhttp_set_lenient_keep_alive(this.#ptr, flags & HTTPParser.kLenientKeepAlive ? 1 : 0);
244
+ exports.llhttp_set_lenient_transfer_encoding(this.#ptr, flags & HTTPParser.kLenientTransferEncoding ? 1 : 0);
245
+ this.#reset();
246
+ this.#connections?.remove(this);
247
+ this.#connections = connections;
248
+ connections?.add(this);
249
+ this.headersStart = 0;
250
+ this.messageStart = 0;
251
+ }
252
+
253
+ #reset(): void {
254
+ this.#headers = [];
255
+ this.#headerBytes = 0;
256
+ this.#field = '';
257
+ this.#value = '';
258
+ this.#readingValue = false;
259
+ this.#url = '';
260
+ this.#statusMessage = '';
261
+ this.#headersSent = false;
262
+ this.#paused = false;
263
+ }
264
+
265
+ /** Node's `parser.free()`: back on the free list, holding no llhttp state. */
266
+ free(): void {
267
+ if (this.#ptr !== 0) { llhttp().llhttp_free(this.#ptr); this.#ptr = 0; }
268
+ this.#connections?.remove(this);
269
+ this.#connections = undefined;
270
+ this.active = false;
271
+ this.#reset();
272
+ }
273
+
274
+ /** Node's `parser.remove()`, which only matters for a consumed stream. */
275
+ remove(): void {}
276
+
277
+ close(): void { this.free(); }
278
+
279
+ pause(): void { if (this.#ptr !== 0) llhttp().llhttp_pause(this.#ptr); }
280
+ resume(): void { if (this.#ptr !== 0) llhttp().llhttp_resume(this.#ptr); }
281
+
282
+ /** The engine's handles are not stream bases, so Node never consumes one. */
283
+ consume(): void {}
284
+ unconsume(): void {}
285
+
286
+ getCurrentBuffer(): Uint8Array {
287
+ return this.#buffer ?? new Uint8Array(0);
288
+ }
289
+
290
+ /**
291
+ * `parser.execute(buffer)`: the bytes through llhttp, answering how many it
292
+ * took, or an `Error` carrying `bytesParsed`, the llhttp code and llhttp's
293
+ * own reason -- which is the shape `_http_server.js` reads to decide
294
+ * between a 400 and a destroyed socket.
295
+ */
296
+ execute(buffer: Uint8Array): number | Error {
297
+ const exports = llhttp();
298
+ if (this.#ptr === 0) this.initialize(this.#type);
299
+ const length = buffer.length;
300
+ const data = this.#copyIn(buffer);
301
+ const previous = current;
302
+ current = this;
303
+ this.#buffer = buffer;
304
+ let ret: number;
305
+ try {
306
+ ret = exports.llhttp_execute(this.#ptr, data, length);
307
+ } finally {
308
+ current = previous;
309
+ }
310
+ if (ret === ERROR_PAUSED_UPGRADE) {
311
+ // The bytes after the header of an upgraded message are the caller's,
312
+ // not llhttp's: it stops where they begin and says where that was.
313
+ const consumed = exports.llhttp_get_error_pos(this.#ptr) - data;
314
+ exports.llhttp_resume_after_upgrade(this.#ptr);
315
+ this.#buffer = null;
316
+ return consumed;
317
+ }
318
+ if (ret === ERROR_PAUSED) {
319
+ this.#paused = true;
320
+ const consumed = exports.llhttp_get_error_pos(this.#ptr) - data;
321
+ this.#buffer = null;
322
+ return consumed;
323
+ }
324
+ if (ret !== ERROR_OK) {
325
+ const consumed = exports.llhttp_get_error_pos(this.#ptr) - data;
326
+ const error = new Error(cstring(exports.llhttp_get_error_reason(this.#ptr))) as Error & {
327
+ bytesParsed?: number; code?: string; reason?: string;
328
+ };
329
+ error.bytesParsed = consumed < 0 ? 0 : consumed;
330
+ // llhttp's own name already carries the prefix: `HPE_INVALID_METHOD`.
331
+ error.code = cstring(exports.llhttp_errno_name(ret));
332
+ error.reason = error.message;
333
+ this.#buffer = null;
334
+ return error;
335
+ }
336
+ this.#buffer = null;
337
+ return length;
338
+ }
339
+
340
+ /** `parser.finish()`: the stream ended; llhttp says whether that was legal. */
341
+ finish(): number | Error | undefined {
342
+ const exports = llhttp();
343
+ if (this.#ptr === 0) return undefined;
344
+ const previous = current;
345
+ current = this;
346
+ let ret: number;
347
+ try { ret = exports.llhttp_finish(this.#ptr); } finally { current = previous; }
348
+ if (ret === ERROR_OK || ret === ERROR_PAUSED || ret === ERROR_PAUSED_UPGRADE) return undefined;
349
+ const error = new Error(cstring(exports.llhttp_get_error_reason(this.#ptr))) as Error & {
350
+ bytesParsed?: number; code?: string;
351
+ };
352
+ error.bytesParsed = 0;
353
+ // llhttp's own name already carries the prefix: `HPE_INVALID_METHOD`.
354
+ error.code = cstring(exports.llhttp_errno_name(ret));
355
+ return error;
356
+ }
357
+
358
+ /** Bytes into the module's own memory, in one scratch buffer that grows. */
359
+ #copyIn(buffer: Uint8Array): number {
360
+ const exports = llhttp();
361
+ if (buffer.length > this.#bufferSize) {
362
+ if (this.#bufferPtr !== 0) exports.free(this.#bufferPtr);
363
+ this.#bufferPtr = exports.malloc(buffer.length);
364
+ this.#bufferSize = buffer.length;
365
+ memoryBytes = undefined;
366
+ }
367
+ bytes().set(buffer, this.#bufferPtr);
368
+ return this.#bufferPtr;
369
+ }
370
+
371
+ // ---- llhttp's callbacks, each answering 0 for "carry on" -----------------
372
+
373
+ onMessageBegin(): number {
374
+ this.#reset();
375
+ this.headersStart = Date.now();
376
+ this.messageStart = this.headersStart;
377
+ this.active = true;
378
+ const callback = this[kOnMessageBegin];
379
+ if (callback) callback.call(this as never);
380
+ return 0;
381
+ }
382
+
383
+ onUrl(at: number, length: number): number {
384
+ this.#url += decode(at, length);
385
+ return this.#countHeaderBytes(length);
386
+ }
387
+
388
+ onStatus(at: number, length: number): number {
389
+ this.#statusMessage += decode(at, length);
390
+ return this.#countHeaderBytes(length);
391
+ }
392
+
393
+ onHeaderField(at: number, length: number): number {
394
+ if (this.#readingValue) { this.#pushHeader(); }
395
+ this.#field += decode(at, length);
396
+ return this.#countHeaderBytes(length);
397
+ }
398
+
399
+ onHeaderValue(at: number, length: number): number {
400
+ this.#readingValue = true;
401
+ this.#value += decode(at, length);
402
+ return this.#countHeaderBytes(length);
403
+ }
404
+
405
+ #pushHeader(): void {
406
+ this.#headers.push(this.#field, this.#value);
407
+ this.#field = '';
408
+ this.#value = '';
409
+ this.#readingValue = false;
410
+ }
411
+
412
+ /**
413
+ * Node refuses a message whose head is longer than `maxHeaderSize`. A
414
+ * callback that answers anything but 0 stops llhttp with `HPE_USER`, which
415
+ * is the code `_http_server.js` reads to answer 431.
416
+ */
417
+ #countHeaderBytes(length: number): number {
418
+ if (this.#headersSent) return 0;
419
+ this.#headerBytes += length;
420
+ if (this.#headerBytes > this.#maxHeaderSize) {
421
+ return -1;
422
+ }
423
+ return 0;
424
+ }
425
+
426
+ onHeadersComplete(statusCode: number, upgrade: boolean, shouldKeepAlive: boolean): number {
427
+ if (this.#readingValue || this.#field !== '') this.#pushHeader();
428
+ const exports = llhttp();
429
+ const headers = this.#headers;
430
+ this.#headers = [];
431
+ this.#headersSent = true;
432
+ this.headersStart = 0;
433
+ const callback = this[kOnHeadersComplete];
434
+ if (!callback) return 0;
435
+ const major = exports.llhttp_get_http_major(this.#ptr);
436
+ const minor = exports.llhttp_get_http_minor(this.#ptr);
437
+ const method = this.#type === TYPE_REQUEST ? exports.llhttp_get_method(this.#ptr) : undefined;
438
+ const url = this.#type === TYPE_REQUEST ? this.#url : undefined;
439
+ const answer = (callback as (...args: unknown[]) => unknown).call(
440
+ this, major, minor, headers, method, url, statusCode, this.#statusMessage, upgrade, shouldKeepAlive,
441
+ );
442
+ this.#url = '';
443
+ this.#statusMessage = '';
444
+ // Node's own answer: a number means "this message has no body to read" --
445
+ // a HEAD's response, a 204, a 304 -- which is llhttp's 1.
446
+ if (typeof answer === 'number' && answer > 0) return 1;
447
+ return 0;
448
+ }
449
+
450
+ onBody(at: number, length: number): number {
451
+ const callback = this[kOnBody];
452
+ if (callback) {
453
+ const chunk = bytes().slice(at, at + length);
454
+ (callback as (...args: unknown[]) => unknown).call(this, chunk);
455
+ }
456
+ return 0;
457
+ }
458
+
459
+ onMessageComplete(): number {
460
+ // A trailer arrives after the head is done; Node takes those through
461
+ // `kOnHeaders`, which is also how it takes a head too large to batch.
462
+ if (this.#readingValue || this.#field !== '') this.#pushHeader();
463
+ if (this.#headers.length > 0) {
464
+ const trailers = this.#headers;
465
+ this.#headers = [];
466
+ const onHeaders = this[kOnHeaders];
467
+ if (onHeaders) (onHeaders as (...args: unknown[]) => unknown).call(this, trailers, '');
468
+ }
469
+ const callback = this[kOnMessageComplete];
470
+ const returned = callback ? (callback as () => unknown).call(this as never) : 0;
471
+ this.active = false;
472
+ this.messageStart = 0;
473
+ // A client that has its message may return non-zero to stop llhttp
474
+ // before the next message on this connection; Node's own callbacks
475
+ // return nothing, which is 0 as before.
476
+ return typeof returned === 'number' ? returned : 0;
477
+ }
478
+
479
+ /** Off the list it was initialized onto; `free` is where Node lets one go. */
480
+ detach(): void { this.#connections?.remove(this); this.#connections = undefined; }
481
+ }
482
+
483
+ /**
484
+ * `internalBinding('http_parser')`'s `ConnectionsList`: the parsers a server
485
+ * has open, which is how `_http_server.js` closes its connections and
486
+ * enforces `headersTimeout` and `requestTimeout`. Node keeps the list in C++
487
+ * beside the parsers themselves; here it is a set of the same parsers, and
488
+ * each answers from the timestamps llhttp's own callbacks set on it.
489
+ */
490
+ export class ConnectionsList {
491
+ #parsers = new Set<HTTPParser>();
492
+
493
+ add(parser: HTTPParser): void { this.#parsers.add(parser); }
494
+ remove(parser: HTTPParser): void { this.#parsers.delete(parser); }
495
+
496
+ all(): HTTPParser[] { return [...this.#parsers]; }
497
+
498
+ /** A connection with no message in flight. */
499
+ idle(): HTTPParser[] { return [...this.#parsers].filter((parser) => !parser.active); }
500
+
501
+ /** A connection with one. */
502
+ active(): HTTPParser[] { return [...this.#parsers].filter((parser) => parser.active); }
503
+
504
+ /**
505
+ * The connections that have taken too long: one whose head is still
506
+ * arriving after `headersTimeout`, or whose message has been in flight past
507
+ * `requestTimeout`. A timeout of 0 is off, as it is in Node.
508
+ */
509
+ expired(headersTimeout: number, requestTimeout: number): HTTPParser[] {
510
+ const now = Date.now();
511
+ return [...this.#parsers].filter((parser) => {
512
+ if (headersTimeout > 0 && parser.headersStart > 0 && now - parser.headersStart > headersTimeout) return true;
513
+ if (requestTimeout > 0 && parser.messageStart > 0 && now - parser.messageStart > requestTimeout) return true;
514
+ return false;
515
+ });
516
+ }
517
+ }
518
+
519
+ /** The binding object, built on the first ask. */
520
+ export const httpParserBinding = {
521
+ HTTPParser,
522
+ ConnectionsList,
523
+ /**
524
+ * `http.METHODS`: the HTTP methods, which are the ones llhttp lists before
525
+ * `PRI` -- that is where its RTSP block begins, and RTSP's verbs are not
526
+ * HTTP's. Read off the same table as `allMethods`, so the two cannot drift.
527
+ */
528
+ get methods(): string[] {
529
+ const all = allMethodsOf();
530
+ const rtsp = all.indexOf('PRI');
531
+ return [...new Set(rtsp === -1 ? all : all.slice(0, rtsp))].sort();
532
+ },
533
+ get allMethods(): string[] { return allMethodsOf(); },
534
+ };
535
+
536
+ export default httpParserBinding;
@@ -0,0 +1,77 @@
1
+ /**
2
+ * The binding: one entry per `internalBinding` name Node's `net` and
3
+ * `child_process` ask for.
4
+ *
5
+ * The rule for every file under this directory is the one the contract sets:
6
+ * the binding implements nothing Node's own files implement. It is the libuv
7
+ * surface and the engine's own doors behind it — the loopback pairing, the
8
+ * port and path registries, the run's count of open handles — and nothing
9
+ * about sockets, servers, half-open, timeouts or buffering, nor about
10
+ * `ChildProcess`, `fork`'s IPC protocol or `exec`'s buffering: all of those
11
+ * are `net.js`'s and `child_process.js`'s, and both are vendored.
12
+ */
13
+ import uvBinding from './uv';
14
+ import streamWrapBinding from './stream_wrap';
15
+ import tcpWrapBinding from './tcp_wrap';
16
+ import pipeWrapBinding from './pipe_wrap';
17
+ import caresWrapBinding from './cares_wrap';
18
+ import processWrapBinding from './process_wrap';
19
+ import spawnSyncBinding from './spawn_sync';
20
+ import ttyWrapBinding from './tty_wrap';
21
+ import { udpWrapBinding } from './stubs';
22
+ import httpParserBinding from './http_parser';
23
+ import bufferBinding from './buffer';
24
+ import { constantsBinding, osBinding, configBinding, errorsBinding, credentialsBinding, encodingBinding, typesBinding, stringDecoderBinding, traceEventsBinding, messagingBinding } from './misc';
25
+ import utilBinding from './util';
26
+ import fsBinding, { fsDirBinding, fsEventWrapBinding } from './fs';
27
+ import blobBinding from './blob';
28
+ import zlibBinding from './zlib';
29
+ import { AsyncResource } from '../internals/runtime';
30
+
31
+ /**
32
+ * The table, built on the first ask rather than when this module is
33
+ * evaluated. `buffer` is a vendored file and the engine's own shims want
34
+ * Node's `Buffer`, so the loader is asked for one from inside the import
35
+ * graph that builds it; a module-scope table left this in its own temporal
36
+ * dead zone and the engine failed to load. A hoisted function reading
37
+ * already-evaluated leaf modules answers whatever order a bundler settles on.
38
+ */
39
+ // eslint-disable-next-line no-var, vars-on-top
40
+ var __table: Record<string, () => unknown> | undefined;
41
+ export function nodeLibBinding(name: string): (() => unknown) | undefined {
42
+ __table ??= {
43
+ uv: () => uvBinding,
44
+ stream_wrap: () => streamWrapBinding,
45
+ tcp_wrap: () => tcpWrapBinding,
46
+ pipe_wrap: () => pipeWrapBinding,
47
+ cares_wrap: () => caresWrapBinding,
48
+ process_wrap: () => processWrapBinding,
49
+ spawn_sync: () => spawnSyncBinding,
50
+ tty_wrap: () => ttyWrapBinding,
51
+ udp_wrap: () => udpWrapBinding,
52
+ http_parser: () => httpParserBinding,
53
+ buffer: () => bufferBinding,
54
+ config: () => configBinding,
55
+ constants: () => constantsBinding,
56
+ util: () => utilBinding,
57
+ errors: () => errorsBinding,
58
+ types: () => typesBinding,
59
+ string_decoder: () => stringDecoderBinding,
60
+ trace_events: () => traceEventsBinding,
61
+ messaging: () => messagingBinding,
62
+ os: () => osBinding,
63
+ credentials: () => credentialsBinding,
64
+ encoding_binding: () => encodingBinding,
65
+ fs: () => fsBinding,
66
+ blob: () => blobBinding,
67
+ async_wrap: () => ({ AsyncResource }),
68
+ zlib: () => zlibBinding,
69
+ fs_dir: () => fsDirBinding,
70
+ fs_event_wrap: () => fsEventWrapBinding,
71
+ };;
72
+ return __table[name];
73
+ }
74
+
75
+ export {
76
+ __ownedHandleCount, __releaseOwnedHandles, __adoptHandle, currentOwner,
77
+ } from './handles';