@yanglaofish/fishtools 0.5.2 → 0.5.3

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 (826) hide show
  1. package/README.md +23 -11
  2. package/manual/README.md +23 -11
  3. package/manual/docs/deployment.md +3 -3
  4. package/manual/docs/examples/action-plugin/package.json +1 -1
  5. package/manual/docs/plugin-development.md +15 -4
  6. package/manual/docs/releases.md +24 -0
  7. package/manual/docs/superpowers/plans/2026-10-13-command-shortcuts.md +3 -2
  8. package/manual/docs/superpowers/plans/2026-10-13-global-plugins.md +56 -0
  9. package/manual/docs/superpowers/plans/2026-10-13-tui-readable-sessions.md +21 -0
  10. package/manual/docs/superpowers/reviews/2026-10-13-0.5.3-review.md +28 -0
  11. package/manual/docs/superpowers/reviews/2026-10-13-command-shortcuts-review.md +7 -0
  12. package/manual/docs/superpowers/reviews/2026-10-13-tui-sessions-review.md +55 -0
  13. package/manual/docs/superpowers/specs/2026-10-13-issue-4-workflow-menu.md +23 -0
  14. package/manual/docs/superpowers/specs/2026-10-13-issue-5-results-and-history.md +20 -0
  15. package/manual/docs/terminal-commands.md +8 -0
  16. package/manual/docs/verification.md +30 -0
  17. package/manual/packages/core/README.md +2 -0
  18. package/manual/packages/core/package.json +1 -1
  19. package/manual/packages/core/src/application.js +100 -51
  20. package/manual/packages/core/src/development-watch-worker.js +10 -1
  21. package/manual/packages/core/src/development.js +1 -1
  22. package/manual/packages/core/src/plugin-catalog.js +42 -0
  23. package/manual/packages/core/src/version.js +1 -1
  24. package/manual/packages/fst-cli/README.md +4 -0
  25. package/manual/packages/fst-cli/bin/fst.js +7 -6
  26. package/manual/packages/fst-cli/package.json +1 -1
  27. package/manual/packages/fst-cli/src/development.js +6 -1
  28. package/manual/packages/fst-cli/src/terminal/command-menu.js +8 -3
  29. package/manual/packages/fst-cli/src/terminal/navigation.js +2 -0
  30. package/manual/packages/fst-cli/src/terminal/presentation.js +4 -3
  31. package/manual/packages/fst-cli/src/terminal/run-feed.js +69 -13
  32. package/manual/packages/fst-cli/src/terminal/run-presentation.js +55 -12
  33. package/manual/packages/fst-cli/src/terminal/run-viewer.js +26 -10
  34. package/manual/packages/fst-cli/src/terminal/session-history.js +82 -0
  35. package/manual/packages/fst-cli/src/terminal/session.js +119 -40
  36. package/manual/packages/fst-cli/src/terminal/view.js +31 -8
  37. package/manual/packages/fst-cli/src/terminal/workflow-menu.js +14 -9
  38. package/manual/packages/fst-devtools/package.json +2 -2
  39. package/manual/packages/fst-devtools/src/plugin-tools.js +1 -1
  40. package/manual/packages/fst-logs/README.md +23 -2
  41. package/manual/packages/fst-logs/package.json +2 -1
  42. package/manual/packages/fst-logs/src/file-identity.js +23 -0
  43. package/manual/packages/fst-logs/src/markdown-log.js +4 -3
  44. package/manual/packages/fst-logs/src/run-logs.js +3 -2
  45. package/manual/packages/fst-logs/src/session-history.js +180 -0
  46. package/manual/packages/fst-platform/README.md +4 -0
  47. package/manual/packages/fst-platform/package.json +3 -3
  48. package/manual/packages/fst-platform/src/process.js +4 -1
  49. package/manual/packages/fst-platform/src/shell.js +46 -1
  50. package/manual/packages/fst-plugin/package.json +1 -1
  51. package/manual/packages/fst-plugin/src/host.js +31 -23
  52. package/manual/packages/fst-workflow/package.json +1 -1
  53. package/manual/packages/fst-workflow/src/engine.js +1 -1
  54. package/manual/packages/fst-workspace/README.md +2 -0
  55. package/manual/packages/fst-workspace/package.json +2 -1
  56. package/manual/packages/fst-workspace/src/plugin-registry.js +58 -0
  57. package/manual/packages/fst-workspace/src/plugins.js +7 -4
  58. package/manual/packages/fst-workspace/src/workflows.js +5 -3
  59. package/manual/packages/pack/package.json +3 -3
  60. package/manual/packages/pack/runtime-cache.js +26 -0
  61. package/manual/packages/pack/runtime.js +6 -10
  62. package/manual/plugins/commands/package.json +1 -1
  63. package/node_modules/@mytools/commands/package.json +1 -1
  64. package/node_modules/@mytools/core/README.md +2 -0
  65. package/node_modules/@mytools/core/package.json +1 -1
  66. package/node_modules/@mytools/core/src/application.js +100 -51
  67. package/node_modules/@mytools/core/src/development-watch-worker.js +10 -1
  68. package/node_modules/@mytools/core/src/development.js +1 -1
  69. package/node_modules/@mytools/core/src/plugin-catalog.js +42 -0
  70. package/node_modules/@mytools/core/src/version.js +1 -1
  71. package/node_modules/@mytools/fst-cli/README.md +4 -0
  72. package/node_modules/@mytools/fst-cli/bin/fst.js +7 -6
  73. package/node_modules/@mytools/fst-cli/package.json +1 -1
  74. package/node_modules/@mytools/fst-cli/src/development.js +6 -1
  75. package/node_modules/@mytools/fst-cli/src/terminal/command-menu.js +8 -3
  76. package/node_modules/@mytools/fst-cli/src/terminal/navigation.js +2 -0
  77. package/node_modules/@mytools/fst-cli/src/terminal/presentation.js +4 -3
  78. package/node_modules/@mytools/fst-cli/src/terminal/run-feed.js +69 -13
  79. package/node_modules/@mytools/fst-cli/src/terminal/run-presentation.js +55 -12
  80. package/node_modules/@mytools/fst-cli/src/terminal/run-viewer.js +26 -10
  81. package/node_modules/@mytools/fst-cli/src/terminal/session-history.js +82 -0
  82. package/node_modules/@mytools/fst-cli/src/terminal/session.js +119 -40
  83. package/node_modules/@mytools/fst-cli/src/terminal/view.js +31 -8
  84. package/node_modules/@mytools/fst-cli/src/terminal/workflow-menu.js +14 -9
  85. package/node_modules/@mytools/fst-devtools/package.json +2 -2
  86. package/node_modules/@mytools/fst-devtools/src/plugin-tools.js +1 -1
  87. package/node_modules/@mytools/fst-logs/README.md +23 -2
  88. package/node_modules/@mytools/fst-logs/package.json +2 -1
  89. package/node_modules/@mytools/fst-logs/src/file-identity.js +23 -0
  90. package/node_modules/@mytools/fst-logs/src/markdown-log.js +4 -3
  91. package/node_modules/@mytools/fst-logs/src/run-logs.js +3 -2
  92. package/node_modules/@mytools/fst-logs/src/session-history.js +180 -0
  93. package/node_modules/@mytools/fst-platform/README.md +4 -0
  94. package/node_modules/@mytools/fst-platform/node_modules/undici/LICENSE +21 -0
  95. package/node_modules/{undici/docs/docs/index.md → @mytools/fst-platform/node_modules/undici/README.md} +85 -137
  96. package/node_modules/@mytools/fst-platform/node_modules/undici/docs/docs/api/Agent.md +84 -0
  97. package/node_modules/@mytools/fst-platform/node_modules/undici/docs/docs/api/BalancedPool.md +99 -0
  98. package/node_modules/@mytools/fst-platform/node_modules/undici/docs/docs/api/CacheStorage.md +30 -0
  99. package/node_modules/@mytools/fst-platform/node_modules/undici/docs/docs/api/CacheStore.md +164 -0
  100. package/node_modules/@mytools/fst-platform/node_modules/undici/docs/docs/api/Client.md +288 -0
  101. package/node_modules/@mytools/fst-platform/node_modules/undici/docs/docs/api/ClientStats.md +27 -0
  102. package/node_modules/@mytools/fst-platform/node_modules/undici/docs/docs/api/Connector.md +115 -0
  103. package/node_modules/@mytools/fst-platform/node_modules/undici/docs/docs/api/ContentType.md +57 -0
  104. package/node_modules/@mytools/fst-platform/node_modules/undici/docs/docs/api/Cookies.md +128 -0
  105. package/node_modules/@mytools/fst-platform/node_modules/undici/docs/docs/api/Debug.md +62 -0
  106. package/node_modules/@mytools/fst-platform/node_modules/undici/docs/docs/api/DiagnosticsChannel.md +317 -0
  107. package/node_modules/@mytools/fst-platform/node_modules/undici/docs/docs/api/Dispatcher.md +1393 -0
  108. package/node_modules/@mytools/fst-platform/node_modules/undici/docs/docs/api/EnvHttpProxyAgent.md +159 -0
  109. package/node_modules/@mytools/fst-platform/node_modules/undici/docs/docs/api/Errors.md +49 -0
  110. package/node_modules/@mytools/fst-platform/node_modules/undici/docs/docs/api/EventSource.md +45 -0
  111. package/node_modules/@mytools/fst-platform/node_modules/undici/docs/docs/api/Fetch.md +60 -0
  112. package/node_modules/@mytools/fst-platform/node_modules/undici/docs/docs/api/GlobalInstallation.md +139 -0
  113. package/node_modules/@mytools/fst-platform/node_modules/undici/docs/docs/api/H2CClient.md +263 -0
  114. package/node_modules/@mytools/fst-platform/node_modules/undici/docs/docs/api/MockAgent.md +603 -0
  115. package/node_modules/@mytools/fst-platform/node_modules/undici/docs/docs/api/MockCallHistory.md +197 -0
  116. package/node_modules/@mytools/fst-platform/node_modules/undici/docs/docs/api/MockCallHistoryLog.md +43 -0
  117. package/node_modules/@mytools/fst-platform/node_modules/undici/docs/docs/api/MockClient.md +81 -0
  118. package/node_modules/@mytools/fst-platform/node_modules/undici/docs/docs/api/MockErrors.md +12 -0
  119. package/node_modules/@mytools/fst-platform/node_modules/undici/docs/docs/api/MockPool.md +555 -0
  120. package/node_modules/@mytools/fst-platform/node_modules/undici/docs/docs/api/Pool.md +84 -0
  121. package/node_modules/@mytools/fst-platform/node_modules/undici/docs/docs/api/PoolStats.md +35 -0
  122. package/node_modules/@mytools/fst-platform/node_modules/undici/docs/docs/api/ProxyAgent.md +229 -0
  123. package/node_modules/@mytools/fst-platform/node_modules/undici/docs/docs/api/RedirectHandler.md +93 -0
  124. package/node_modules/@mytools/fst-platform/node_modules/undici/docs/docs/api/RetryAgent.md +50 -0
  125. package/node_modules/@mytools/fst-platform/node_modules/undici/docs/docs/api/RetryHandler.md +118 -0
  126. package/node_modules/@mytools/fst-platform/node_modules/undici/docs/docs/api/RoundRobinPool.md +145 -0
  127. package/node_modules/@mytools/fst-platform/node_modules/undici/docs/docs/api/SnapshotAgent.md +616 -0
  128. package/node_modules/@mytools/fst-platform/node_modules/undici/docs/docs/api/Socks5ProxyAgent.md +275 -0
  129. package/node_modules/@mytools/fst-platform/node_modules/undici/docs/docs/api/Util.md +25 -0
  130. package/node_modules/@mytools/fst-platform/node_modules/undici/docs/docs/api/WebSocket.md +141 -0
  131. package/node_modules/@mytools/fst-platform/node_modules/undici/docs/docs/api/api-lifecycle.md +91 -0
  132. package/node_modules/@mytools/fst-platform/node_modules/undici/docs/docs/best-practices/client-certificate.md +64 -0
  133. package/node_modules/{undici → @mytools/fst-platform/node_modules/undici}/docs/docs/best-practices/crawling.md +1 -3
  134. package/node_modules/@mytools/fst-platform/node_modules/undici/docs/docs/best-practices/mocking-request.md +190 -0
  135. package/node_modules/@mytools/fst-platform/node_modules/undici/docs/docs/best-practices/proxy.md +127 -0
  136. package/node_modules/{undici → @mytools/fst-platform/node_modules/undici}/docs/docs/best-practices/undici-vs-builtin-fetch.md +8 -10
  137. package/node_modules/@mytools/fst-platform/node_modules/undici/docs/docs/best-practices/writing-tests.md +63 -0
  138. package/node_modules/@mytools/fst-platform/node_modules/undici/index-fetch.js +65 -0
  139. package/node_modules/@mytools/fst-platform/node_modules/undici/index.d.ts +3 -0
  140. package/node_modules/@mytools/fst-platform/node_modules/undici/index.js +234 -0
  141. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/api/abort-signal.js +59 -0
  142. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/api/api-connect.js +110 -0
  143. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/api/api-pipeline.js +252 -0
  144. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/api/api-request.js +214 -0
  145. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/api/api-stream.js +209 -0
  146. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/api/api-upgrade.js +111 -0
  147. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/api/index.js +7 -0
  148. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/api/readable.js +580 -0
  149. package/node_modules/{undici → @mytools/fst-platform/node_modules/undici}/lib/cache/memory-cache-store.js +3 -3
  150. package/node_modules/{undici → @mytools/fst-platform/node_modules/undici}/lib/cache/sqlite-cache-store.js +1 -3
  151. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/core/connect.js +153 -0
  152. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/core/constants.js +143 -0
  153. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/core/diagnostics.js +227 -0
  154. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/core/errors.js +477 -0
  155. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/core/request.js +485 -0
  156. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/core/symbols.js +75 -0
  157. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/core/tree.js +160 -0
  158. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/core/util.js +992 -0
  159. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/dispatcher/agent.js +158 -0
  160. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/dispatcher/balanced-pool.js +221 -0
  161. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/dispatcher/client-h1.js +1746 -0
  162. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/dispatcher/client-h2.js +1060 -0
  163. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/dispatcher/client.js +668 -0
  164. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/dispatcher/dispatcher-base.js +184 -0
  165. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/dispatcher/dispatcher.js +48 -0
  166. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/dispatcher/env-http-proxy-agent.js +146 -0
  167. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/dispatcher/fixed-queue.js +135 -0
  168. package/node_modules/{undici → @mytools/fst-platform/node_modules/undici}/lib/dispatcher/h2c-client.js +4 -4
  169. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/dispatcher/pool-base.js +214 -0
  170. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/dispatcher/pool.js +118 -0
  171. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/dispatcher/proxy-agent.js +319 -0
  172. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/dispatcher/retry-agent.js +35 -0
  173. package/node_modules/{undici → @mytools/fst-platform/node_modules/undici}/lib/dispatcher/round-robin-pool.js +10 -32
  174. package/node_modules/{undici → @mytools/fst-platform/node_modules/undici}/lib/dispatcher/socks5-proxy-agent.js +63 -153
  175. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/global.js +59 -0
  176. package/node_modules/{undici → @mytools/fst-platform/node_modules/undici}/lib/handler/cache-handler.js +7 -49
  177. package/node_modules/{undici → @mytools/fst-platform/node_modules/undici}/lib/handler/cache-revalidation-handler.js +0 -10
  178. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/handler/decorator-handler.js +67 -0
  179. package/node_modules/{undici → @mytools/fst-platform/node_modules/undici}/lib/handler/deduplication-handler.js +10 -29
  180. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/handler/redirect-handler.js +238 -0
  181. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/handler/retry-handler.js +504 -0
  182. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/handler/unwrap-handler.js +106 -0
  183. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/handler/wrap-handler.js +105 -0
  184. package/node_modules/{undici → @mytools/fst-platform/node_modules/undici}/lib/interceptor/cache.js +26 -79
  185. package/node_modules/{undici → @mytools/fst-platform/node_modules/undici}/lib/interceptor/decompress.js +3 -13
  186. package/node_modules/{undici → @mytools/fst-platform/node_modules/undici}/lib/interceptor/deduplicate.js +4 -5
  187. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/interceptor/dns.js +571 -0
  188. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/interceptor/dump.js +99 -0
  189. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/interceptor/redirect.js +21 -0
  190. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/interceptor/response-error.js +95 -0
  191. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/interceptor/retry.js +19 -0
  192. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/llhttp/.gitkeep +0 -0
  193. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/llhttp/constants.js +531 -0
  194. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/llhttp/llhttp-wasm.js +15 -0
  195. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/llhttp/llhttp_simd-wasm.js +15 -0
  196. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/llhttp/utils.js +12 -0
  197. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/mock/mock-agent.js +232 -0
  198. package/node_modules/{undici → @mytools/fst-platform/node_modules/undici}/lib/mock/mock-call-history.js +1 -1
  199. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/mock/mock-client.js +68 -0
  200. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/mock/mock-errors.js +29 -0
  201. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/mock/mock-interceptor.js +209 -0
  202. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/mock/mock-pool.js +68 -0
  203. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/mock/mock-symbols.js +32 -0
  204. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/mock/mock-utils.js +486 -0
  205. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/mock/pending-interceptors-formatter.js +43 -0
  206. package/node_modules/{undici → @mytools/fst-platform/node_modules/undici}/lib/mock/snapshot-agent.js +7 -25
  207. package/node_modules/{undici → @mytools/fst-platform/node_modules/undici}/lib/mock/snapshot-recorder.js +3 -38
  208. package/node_modules/{undici → @mytools/fst-platform/node_modules/undici}/lib/util/cache.js +10 -92
  209. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/util/promise.js +28 -0
  210. package/node_modules/{undici → @mytools/fst-platform/node_modules/undici}/lib/util/runtime-features.js +34 -3
  211. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/util/timers.js +425 -0
  212. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/web/cache/cache.js +864 -0
  213. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/web/cache/cachestorage.js +152 -0
  214. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/web/cache/util.js +45 -0
  215. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/web/cookies/constants.js +12 -0
  216. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/web/cookies/index.js +199 -0
  217. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/web/cookies/parse.js +314 -0
  218. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/web/cookies/util.js +352 -0
  219. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/web/eventsource/eventsource-stream.js +494 -0
  220. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/web/eventsource/eventsource.js +501 -0
  221. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/web/eventsource/util.js +29 -0
  222. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/web/fetch/LICENSE +21 -0
  223. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/web/fetch/body.js +509 -0
  224. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/web/fetch/constants.js +131 -0
  225. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/web/fetch/data-url.js +596 -0
  226. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/web/fetch/formdata-parser.js +586 -0
  227. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/web/fetch/formdata.js +259 -0
  228. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/web/fetch/global.js +40 -0
  229. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/web/fetch/headers.js +719 -0
  230. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/web/fetch/index.js +2413 -0
  231. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/web/fetch/request.js +1115 -0
  232. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/web/fetch/response.js +641 -0
  233. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/web/fetch/util.js +1522 -0
  234. package/node_modules/{undici → @mytools/fst-platform/node_modules/undici}/lib/web/infra/index.js +1 -16
  235. package/node_modules/{undici → @mytools/fst-platform/node_modules/undici}/lib/web/webidl/index.js +21 -7
  236. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/web/websocket/connection.js +339 -0
  237. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/web/websocket/constants.js +126 -0
  238. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/web/websocket/events.js +331 -0
  239. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/web/websocket/frame.js +133 -0
  240. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/web/websocket/permessage-deflate.js +105 -0
  241. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/web/websocket/receiver.js +507 -0
  242. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/web/websocket/sender.js +109 -0
  243. package/node_modules/{undici → @mytools/fst-platform/node_modules/undici}/lib/web/websocket/stream/websocketerror.js +10 -13
  244. package/node_modules/{undici → @mytools/fst-platform/node_modules/undici}/lib/web/websocket/stream/websocketstream.js +14 -29
  245. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/web/websocket/util.js +347 -0
  246. package/node_modules/@mytools/fst-platform/node_modules/undici/lib/web/websocket/websocket.js +758 -0
  247. package/node_modules/@mytools/fst-platform/node_modules/undici/package.json +152 -0
  248. package/node_modules/@mytools/fst-platform/node_modules/undici/scripts/strip-comments.js +10 -0
  249. package/node_modules/@mytools/fst-platform/node_modules/undici/types/README.md +6 -0
  250. package/node_modules/@mytools/fst-platform/node_modules/undici/types/agent.d.ts +32 -0
  251. package/node_modules/@mytools/fst-platform/node_modules/undici/types/api.d.ts +43 -0
  252. package/node_modules/@mytools/fst-platform/node_modules/undici/types/balanced-pool.d.ts +30 -0
  253. package/node_modules/@mytools/fst-platform/node_modules/undici/types/cache.d.ts +36 -0
  254. package/node_modules/@mytools/fst-platform/node_modules/undici/types/client.d.ts +139 -0
  255. package/node_modules/@mytools/fst-platform/node_modules/undici/types/connector.d.ts +36 -0
  256. package/node_modules/@mytools/fst-platform/node_modules/undici/types/content-type.d.ts +21 -0
  257. package/node_modules/@mytools/fst-platform/node_modules/undici/types/cookies.d.ts +30 -0
  258. package/node_modules/@mytools/fst-platform/node_modules/undici/types/diagnostics-channel.d.ts +74 -0
  259. package/node_modules/@mytools/fst-platform/node_modules/undici/types/dispatcher.d.ts +275 -0
  260. package/node_modules/@mytools/fst-platform/node_modules/undici/types/env-http-proxy-agent.d.ts +22 -0
  261. package/node_modules/@mytools/fst-platform/node_modules/undici/types/errors.d.ts +177 -0
  262. package/node_modules/@mytools/fst-platform/node_modules/undici/types/eventsource.d.ts +66 -0
  263. package/node_modules/@mytools/fst-platform/node_modules/undici/types/fetch.d.ts +231 -0
  264. package/node_modules/@mytools/fst-platform/node_modules/undici/types/formdata.d.ts +114 -0
  265. package/node_modules/@mytools/fst-platform/node_modules/undici/types/global-dispatcher.d.ts +9 -0
  266. package/node_modules/@mytools/fst-platform/node_modules/undici/types/global-origin.d.ts +7 -0
  267. package/node_modules/{undici → @mytools/fst-platform/node_modules/undici}/types/h2c-client.d.ts +6 -6
  268. package/node_modules/@mytools/fst-platform/node_modules/undici/types/handlers.d.ts +14 -0
  269. package/node_modules/@mytools/fst-platform/node_modules/undici/types/header.d.ts +160 -0
  270. package/node_modules/@mytools/fst-platform/node_modules/undici/types/index.d.ts +91 -0
  271. package/node_modules/@mytools/fst-platform/node_modules/undici/types/interceptors.d.ts +82 -0
  272. package/node_modules/@mytools/fst-platform/node_modules/undici/types/mock-agent.d.ts +68 -0
  273. package/node_modules/@mytools/fst-platform/node_modules/undici/types/mock-client.d.ts +27 -0
  274. package/node_modules/@mytools/fst-platform/node_modules/undici/types/mock-errors.d.ts +12 -0
  275. package/node_modules/@mytools/fst-platform/node_modules/undici/types/mock-interceptor.d.ts +94 -0
  276. package/node_modules/@mytools/fst-platform/node_modules/undici/types/mock-pool.d.ts +27 -0
  277. package/node_modules/@mytools/fst-platform/node_modules/undici/types/patch.d.ts +29 -0
  278. package/node_modules/@mytools/fst-platform/node_modules/undici/types/pool-stats.d.ts +19 -0
  279. package/node_modules/@mytools/fst-platform/node_modules/undici/types/pool.d.ts +41 -0
  280. package/node_modules/@mytools/fst-platform/node_modules/undici/types/proxy-agent.d.ts +29 -0
  281. package/node_modules/@mytools/fst-platform/node_modules/undici/types/readable.d.ts +68 -0
  282. package/node_modules/@mytools/fst-platform/node_modules/undici/types/retry-agent.d.ts +8 -0
  283. package/node_modules/@mytools/fst-platform/node_modules/undici/types/retry-handler.d.ts +125 -0
  284. package/node_modules/{undici → @mytools/fst-platform/node_modules/undici}/types/round-robin-pool.d.ts +2 -0
  285. package/node_modules/{undici → @mytools/fst-platform/node_modules/undici}/types/snapshot-agent.d.ts +0 -4
  286. package/node_modules/{undici → @mytools/fst-platform/node_modules/undici}/types/socks5-proxy-agent.d.ts +2 -4
  287. package/node_modules/@mytools/fst-platform/node_modules/undici/types/util.d.ts +18 -0
  288. package/node_modules/@mytools/fst-platform/node_modules/undici/types/webidl.d.ts +347 -0
  289. package/node_modules/@mytools/fst-platform/node_modules/undici/types/websocket.d.ts +188 -0
  290. package/node_modules/@mytools/fst-platform/package.json +3 -3
  291. package/node_modules/@mytools/fst-platform/src/process.js +4 -1
  292. package/node_modules/@mytools/fst-platform/src/shell.js +46 -1
  293. package/node_modules/@mytools/fst-plugin/package.json +1 -1
  294. package/node_modules/@mytools/fst-plugin/src/host.js +31 -23
  295. package/node_modules/@mytools/fst-workflow/package.json +1 -1
  296. package/node_modules/@mytools/fst-workflow/src/engine.js +1 -1
  297. package/node_modules/@mytools/fst-workspace/README.md +2 -0
  298. package/node_modules/@mytools/fst-workspace/package.json +2 -1
  299. package/node_modules/@mytools/fst-workspace/src/plugin-registry.js +58 -0
  300. package/node_modules/@mytools/fst-workspace/src/plugins.js +7 -4
  301. package/node_modules/@mytools/fst-workspace/src/workflows.js +5 -3
  302. package/node_modules/@mytools/pack/package.json +3 -3
  303. package/node_modules/@mytools/pack/runtime-cache.js +26 -0
  304. package/node_modules/@mytools/pack/runtime.js +6 -10
  305. package/node_modules/@mytools/web/public/THIRD_PARTY_NOTICES.txt +953 -963
  306. package/node_modules/@npmcli/agent/lib/agents.js +0 -10
  307. package/node_modules/@npmcli/agent/package.json +12 -11
  308. package/node_modules/@npmcli/arborist/README.md +2 -2
  309. package/node_modules/@npmcli/arborist/bin/index.js +2 -1
  310. package/node_modules/@npmcli/arborist/bin/shrinkwrap.js +7 -0
  311. package/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js +25 -159
  312. package/node_modules/@npmcli/arborist/lib/arborist/isolated-reifier.js +49 -11
  313. package/node_modules/@npmcli/arborist/lib/arborist/load-actual.js +0 -67
  314. package/node_modules/@npmcli/arborist/lib/arborist/load-virtual.js +37 -5
  315. package/node_modules/@npmcli/arborist/lib/arborist/rebuild.js +8 -15
  316. package/node_modules/@npmcli/arborist/lib/arborist/reify.js +42 -59
  317. package/node_modules/@npmcli/arborist/lib/consistent-resolve.js +1 -1
  318. package/node_modules/@npmcli/arborist/lib/diff.js +22 -17
  319. package/node_modules/@npmcli/arborist/lib/edge.js +2 -22
  320. package/node_modules/@npmcli/arborist/lib/index.js +0 -2
  321. package/node_modules/@npmcli/arborist/lib/isolated-classes.js +1 -4
  322. package/node_modules/@npmcli/arborist/lib/node.js +9 -13
  323. package/node_modules/@npmcli/arborist/lib/place-dep.js +0 -6
  324. package/node_modules/@npmcli/arborist/lib/printable.js +5 -0
  325. package/node_modules/@npmcli/arborist/lib/shrinkwrap.js +32 -55
  326. package/node_modules/@npmcli/arborist/package.json +26 -32
  327. package/node_modules/@npmcli/fs/lib/move-file.js +5 -5
  328. package/node_modules/@npmcli/fs/package.json +5 -5
  329. package/node_modules/@npmcli/git/package.json +12 -13
  330. package/node_modules/@npmcli/installed-package-contents/package.json +7 -7
  331. package/node_modules/@npmcli/map-workspaces/package.json +7 -7
  332. package/node_modules/@npmcli/metavuln-calculator/package.json +16 -10
  333. package/node_modules/@npmcli/name-from-folder/package.json +16 -13
  334. package/node_modules/@npmcli/node-gyp/package.json +5 -5
  335. package/node_modules/@npmcli/package-json/lib/index.js +1 -2
  336. package/node_modules/@npmcli/package-json/lib/normalize.js +22 -23
  337. package/node_modules/@npmcli/package-json/package.json +10 -11
  338. package/node_modules/@npmcli/promise-spawn/README.md +2 -1
  339. package/node_modules/@npmcli/promise-spawn/package.json +5 -5
  340. package/node_modules/@npmcli/redact/package.json +4 -4
  341. package/node_modules/@npmcli/run-script/lib/is-server-package.js +11 -0
  342. package/node_modules/@npmcli/run-script/lib/make-spawn-args.js +6 -5
  343. package/node_modules/@npmcli/run-script/lib/run-script-pkg.js +13 -4
  344. package/node_modules/@npmcli/run-script/lib/run-script.js +2 -1
  345. package/node_modules/@npmcli/run-script/package.json +11 -12
  346. package/node_modules/@sigstore/bundle/README.md +1 -1
  347. package/node_modules/@sigstore/bundle/dist/error.js +0 -1
  348. package/node_modules/@sigstore/bundle/package.json +2 -2
  349. package/node_modules/@sigstore/core/README.md +1 -1
  350. package/node_modules/@sigstore/core/dist/asn1/length.js +1 -12
  351. package/node_modules/@sigstore/core/dist/asn1/obj.js +7 -25
  352. package/node_modules/@sigstore/core/dist/asn1/parse.js +5 -24
  353. package/node_modules/@sigstore/core/package.json +2 -2
  354. package/node_modules/@sigstore/sign/README.md +1 -1
  355. package/node_modules/@sigstore/sign/dist/signer/fulcio/ephemeral.js +1 -1
  356. package/node_modules/@sigstore/sign/package.json +9 -9
  357. package/node_modules/@sigstore/tuf/README.md +1 -1
  358. package/node_modules/@sigstore/tuf/package.json +4 -4
  359. package/node_modules/@sigstore/tuf/seeds.json +1 -1
  360. package/node_modules/@sigstore/verify/README.md +1 -1
  361. package/node_modules/@sigstore/verify/dist/bundle/dsse.d.ts +0 -1
  362. package/node_modules/@sigstore/verify/dist/bundle/dsse.js +0 -6
  363. package/node_modules/@sigstore/verify/dist/bundle/message.d.ts +0 -1
  364. package/node_modules/@sigstore/verify/dist/bundle/message.js +0 -5
  365. package/node_modules/@sigstore/verify/dist/policy.d.ts +1 -1
  366. package/node_modules/@sigstore/verify/dist/policy.js +2 -0
  367. package/node_modules/@sigstore/verify/dist/shared.types.d.ts +1 -6
  368. package/node_modules/@sigstore/verify/dist/tlog/checkpoint.js +3 -17
  369. package/node_modules/@sigstore/verify/dist/tlog/hashedrekord.js +4 -4
  370. package/node_modules/@sigstore/verify/dist/tlog/index.js +1 -13
  371. package/node_modules/@sigstore/verify/dist/tlog/merkle.js +1 -12
  372. package/node_modules/@sigstore/verify/dist/verifier.js +5 -13
  373. package/node_modules/@sigstore/verify/package.json +5 -5
  374. package/node_modules/@tufjs/models/package.json +3 -3
  375. package/node_modules/abbrev/package.json +8 -9
  376. package/node_modules/agent-base/dist/helpers.d.ts +5 -0
  377. package/node_modules/agent-base/dist/helpers.d.ts.map +1 -1
  378. package/node_modules/agent-base/dist/helpers.js +34 -5
  379. package/node_modules/agent-base/dist/helpers.js.map +1 -1
  380. package/node_modules/agent-base/dist/index.d.ts +5 -1
  381. package/node_modules/agent-base/dist/index.d.ts.map +1 -1
  382. package/node_modules/agent-base/dist/index.js +40 -8
  383. package/node_modules/agent-base/dist/index.js.map +1 -1
  384. package/node_modules/agent-base/package.json +12 -12
  385. package/node_modules/bin-links/README.md +4 -5
  386. package/node_modules/bin-links/lib/fix-bin.js +1 -3
  387. package/node_modules/bin-links/lib/index.js +16 -8
  388. package/node_modules/bin-links/lib/link-mans.js +53 -0
  389. package/node_modules/bin-links/package.json +12 -11
  390. package/node_modules/cacache/lib/content/write.js +0 -2
  391. package/node_modules/cacache/lib/entry-index.js +0 -3
  392. package/node_modules/cacache/lib/rm.js +0 -1
  393. package/node_modules/cacache/lib/util/tmp.js +1 -5
  394. package/node_modules/cacache/lib/verify.js +2 -2
  395. package/node_modules/cacache/package.json +7 -7
  396. package/node_modules/cmd-shim/lib/index.js +32 -67
  397. package/node_modules/cmd-shim/package.json +5 -5
  398. package/node_modules/hosted-git-info/README.md +1 -1
  399. package/node_modules/hosted-git-info/lib/parse-url.js +3 -1
  400. package/node_modules/hosted-git-info/package.json +4 -4
  401. package/node_modules/http-proxy-agent/dist/index.d.ts +5 -8
  402. package/node_modules/http-proxy-agent/dist/index.d.ts.map +1 -1
  403. package/node_modules/http-proxy-agent/dist/index.js +42 -26
  404. package/node_modules/http-proxy-agent/dist/index.js.map +1 -1
  405. package/node_modules/http-proxy-agent/package.json +14 -15
  406. package/node_modules/https-proxy-agent/dist/index.d.ts +5 -9
  407. package/node_modules/https-proxy-agent/dist/index.d.ts.map +1 -1
  408. package/node_modules/https-proxy-agent/dist/index.js +44 -98
  409. package/node_modules/https-proxy-agent/dist/index.js.map +1 -1
  410. package/node_modules/https-proxy-agent/dist/parse-proxy-response.d.ts +3 -0
  411. package/node_modules/https-proxy-agent/dist/parse-proxy-response.d.ts.map +1 -1
  412. package/node_modules/https-proxy-agent/dist/parse-proxy-response.js +10 -3
  413. package/node_modules/https-proxy-agent/dist/parse-proxy-response.js.map +1 -1
  414. package/node_modules/https-proxy-agent/package.json +15 -16
  415. package/node_modules/ignore-walk/package.json +4 -4
  416. package/node_modules/ini/package.json +5 -5
  417. package/node_modules/ip-address/README.md +70 -70
  418. package/node_modules/ip-address/dist/ipv6.js +7 -4
  419. package/node_modules/ip-address/dist/ipv6.js.map +1 -1
  420. package/node_modules/ip-address/dist/v6/constants.d.ts +3 -0
  421. package/node_modules/ip-address/dist/v6/constants.js +3 -0
  422. package/node_modules/ip-address/dist/v6/constants.js.map +1 -1
  423. package/node_modules/ip-address/package.json +2 -1
  424. package/node_modules/json-parse-even-better-errors/lib/index.js +1 -3
  425. package/node_modules/json-parse-even-better-errors/package.json +17 -13
  426. package/node_modules/make-fetch-happen/package.json +11 -11
  427. package/node_modules/minipass-fetch/package.json +4 -4
  428. package/node_modules/node-gyp/.release-please-manifest.json +1 -1
  429. package/node_modules/node-gyp/CHANGELOG.md +0 -102
  430. package/node_modules/node-gyp/README.md +2 -3
  431. package/node_modules/node-gyp/eslint.config.js +1 -4
  432. package/node_modules/node-gyp/gyp/.release-please-manifest.json +1 -1
  433. package/node_modules/node-gyp/gyp/pylib/gyp/generator/cmake.py +19 -14
  434. package/node_modules/node-gyp/gyp/pylib/gyp/msvs_emulation.py +2 -7
  435. package/node_modules/node-gyp/gyp/pyproject.toml +1 -1
  436. package/node_modules/node-gyp/lib/build.js +6 -18
  437. package/node_modules/node-gyp/lib/create-config-gypi.js +0 -5
  438. package/node_modules/node-gyp/lib/node-gyp.js +2 -9
  439. package/node_modules/node-gyp/lib/rebuild.js +3 -3
  440. package/node_modules/node-gyp/package.json +9 -11
  441. package/node_modules/nopt/README.md +4 -2
  442. package/node_modules/nopt/lib/debug.js +5 -0
  443. package/node_modules/nopt/lib/nopt-lib.js +43 -7
  444. package/node_modules/nopt/lib/nopt.js +4 -2
  445. package/node_modules/nopt/lib/type-defs.js +13 -8
  446. package/node_modules/nopt/package.json +17 -15
  447. package/node_modules/npm-bundled/package.json +6 -6
  448. package/node_modules/npm-install-checks/package.json +5 -5
  449. package/node_modules/npm-normalize-package-bin/package.json +16 -13
  450. package/node_modules/npm-package-arg/package.json +7 -7
  451. package/node_modules/npm-packlist/README.md +30 -45
  452. package/node_modules/npm-packlist/lib/index.js +47 -115
  453. package/node_modules/npm-packlist/package.json +8 -10
  454. package/node_modules/npm-pick-manifest/package.json +19 -15
  455. package/node_modules/npm-registry-fetch/lib/errors.js +3 -8
  456. package/node_modules/npm-registry-fetch/package.json +12 -12
  457. package/node_modules/pacote/lib/dir.js +5 -60
  458. package/node_modules/pacote/lib/fetcher.js +0 -4
  459. package/node_modules/pacote/lib/git.js +3 -11
  460. package/node_modules/pacote/lib/util/add-git-sha.js +1 -1
  461. package/node_modules/pacote/package.json +18 -19
  462. package/node_modules/parse-conflict-json/package.json +6 -6
  463. package/node_modules/proc-log/package.json +4 -4
  464. package/node_modules/read-cmd-shim/lib/index.js +1 -1
  465. package/node_modules/read-cmd-shim/package.json +18 -14
  466. package/node_modules/sigstore/README.md +1 -1
  467. package/node_modules/sigstore/package.json +10 -10
  468. package/node_modules/socks-proxy-agent/dist/index.d.ts +3 -1
  469. package/node_modules/socks-proxy-agent/dist/index.d.ts.map +1 -1
  470. package/node_modules/socks-proxy-agent/dist/index.js +43 -17
  471. package/node_modules/socks-proxy-agent/dist/index.js.map +1 -1
  472. package/node_modules/socks-proxy-agent/package.json +15 -15
  473. package/node_modules/ssri/package.json +4 -4
  474. package/node_modules/tuf-js/dist/config.d.ts +2 -2
  475. package/node_modules/tuf-js/dist/fetcher.d.ts +4 -4
  476. package/node_modules/tuf-js/dist/fetcher.js +16 -55
  477. package/node_modules/tuf-js/dist/updater.js +2 -2
  478. package/node_modules/tuf-js/package.json +8 -8
  479. package/node_modules/undici/README.md +72 -405
  480. package/node_modules/undici/docs/docs/api/Agent.md +41 -252
  481. package/node_modules/undici/docs/docs/api/BalancedPool.md +48 -246
  482. package/node_modules/undici/docs/docs/api/CacheStorage.md +13 -171
  483. package/node_modules/undici/docs/docs/api/Client.md +139 -395
  484. package/node_modules/undici/docs/docs/api/Connector.md +35 -118
  485. package/node_modules/undici/docs/docs/api/ContentType.md +25 -65
  486. package/node_modules/undici/docs/docs/api/Cookies.md +47 -125
  487. package/node_modules/undici/docs/docs/api/Debug.md +31 -47
  488. package/node_modules/undici/docs/docs/api/DiagnosticsChannel.md +97 -409
  489. package/node_modules/undici/docs/docs/api/DispatchInterceptor.md +60 -0
  490. package/node_modules/undici/docs/docs/api/Dispatcher.md +1011 -500
  491. package/node_modules/undici/docs/docs/api/EnvHttpProxyAgent.md +96 -105
  492. package/node_modules/undici/docs/docs/api/Errors.md +28 -528
  493. package/node_modules/undici/docs/docs/api/EventSource.md +13 -326
  494. package/node_modules/undici/docs/docs/api/Fetch.md +24 -693
  495. package/node_modules/undici/docs/docs/api/MockAgent.md +264 -346
  496. package/node_modules/undici/docs/docs/api/MockClient.md +31 -153
  497. package/node_modules/undici/docs/docs/api/MockErrors.md +5 -56
  498. package/node_modules/undici/docs/docs/api/MockPool.md +253 -324
  499. package/node_modules/undici/docs/docs/api/Pool.md +41 -235
  500. package/node_modules/undici/docs/docs/api/PoolStats.md +13 -119
  501. package/node_modules/undici/docs/docs/api/ProxyAgent.md +81 -198
  502. package/node_modules/undici/docs/docs/api/RedirectHandler.md +58 -238
  503. package/node_modules/undici/docs/docs/api/RetryAgent.md +28 -119
  504. package/node_modules/undici/docs/docs/api/RetryHandler.md +78 -161
  505. package/node_modules/undici/docs/docs/api/Util.md +11 -68
  506. package/node_modules/undici/docs/docs/api/WebSocket.md +24 -509
  507. package/node_modules/undici/docs/docs/api/api-lifecycle.md +33 -101
  508. package/node_modules/undici/docs/docs/best-practices/client-certificate.md +0 -2
  509. package/node_modules/undici/docs/docs/best-practices/mocking-request.md +2 -58
  510. package/node_modules/undici/docs/docs/best-practices/proxy.md +1 -3
  511. package/node_modules/undici/docs/docs/best-practices/writing-tests.md +0 -45
  512. package/node_modules/undici/index-fetch.js +4 -34
  513. package/node_modules/undici/index.d.ts +1 -1
  514. package/node_modules/undici/index.js +20 -87
  515. package/node_modules/undici/lib/api/abort-signal.js +0 -2
  516. package/node_modules/undici/lib/api/api-connect.js +11 -15
  517. package/node_modules/undici/lib/api/api-pipeline.js +19 -33
  518. package/node_modules/undici/lib/api/api-request.js +59 -89
  519. package/node_modules/undici/lib/api/api-stream.js +64 -114
  520. package/node_modules/undici/lib/api/api-upgrade.js +13 -26
  521. package/node_modules/undici/lib/api/readable.js +87 -317
  522. package/node_modules/undici/lib/api/util.js +93 -0
  523. package/node_modules/undici/lib/core/connect.js +125 -77
  524. package/node_modules/undici/lib/core/constants.js +9 -11
  525. package/node_modules/undici/lib/core/diagnostics.js +129 -154
  526. package/node_modules/undici/lib/core/errors.js +50 -122
  527. package/node_modules/undici/lib/core/request.js +87 -172
  528. package/node_modules/undici/lib/core/symbols.js +2 -14
  529. package/node_modules/undici/lib/core/tree.js +2 -10
  530. package/node_modules/undici/lib/core/util.js +190 -481
  531. package/node_modules/undici/lib/dispatcher/agent.js +35 -83
  532. package/node_modules/undici/lib/dispatcher/balanced-pool.js +38 -46
  533. package/node_modules/undici/lib/dispatcher/client-h1.js +199 -492
  534. package/node_modules/undici/lib/dispatcher/client-h2.js +380 -1409
  535. package/node_modules/undici/lib/dispatcher/client.js +130 -253
  536. package/node_modules/undici/lib/dispatcher/dispatcher-base.js +52 -50
  537. package/node_modules/undici/lib/dispatcher/dispatcher.js +24 -17
  538. package/node_modules/undici/lib/dispatcher/env-http-proxy-agent.js +45 -75
  539. package/node_modules/undici/lib/dispatcher/fixed-queue.js +50 -68
  540. package/node_modules/undici/lib/dispatcher/pool-base.js +54 -153
  541. package/node_modules/undici/lib/dispatcher/pool-stats.js +34 -0
  542. package/node_modules/undici/lib/dispatcher/pool.js +16 -135
  543. package/node_modules/undici/lib/dispatcher/proxy-agent.js +41 -175
  544. package/node_modules/undici/lib/dispatcher/retry-agent.js +0 -3
  545. package/node_modules/undici/lib/global.js +9 -59
  546. package/node_modules/undici/lib/handler/decorator-handler.js +15 -43
  547. package/node_modules/undici/lib/handler/redirect-handler.js +116 -127
  548. package/node_modules/undici/lib/handler/retry-handler.js +182 -398
  549. package/node_modules/undici/lib/interceptor/dns.js +47 -254
  550. package/node_modules/undici/lib/interceptor/dump.js +56 -32
  551. package/node_modules/undici/lib/interceptor/redirect-interceptor.js +21 -0
  552. package/node_modules/undici/lib/interceptor/redirect.js +14 -11
  553. package/node_modules/undici/lib/interceptor/response-error.js +22 -31
  554. package/node_modules/undici/lib/llhttp/.gitkeep +0 -0
  555. package/node_modules/undici/lib/llhttp/constants.js +193 -446
  556. package/node_modules/undici/lib/llhttp/llhttp-wasm.js +1 -11
  557. package/node_modules/undici/lib/llhttp/llhttp_simd-wasm.js +1 -11
  558. package/node_modules/undici/lib/llhttp/utils.js +12 -9
  559. package/node_modules/undici/lib/mock/mock-agent.js +22 -106
  560. package/node_modules/undici/lib/mock/mock-client.js +4 -13
  561. package/node_modules/undici/lib/mock/mock-errors.js +2 -3
  562. package/node_modules/undici/lib/mock/mock-interceptor.js +13 -33
  563. package/node_modules/undici/lib/mock/mock-pool.js +4 -13
  564. package/node_modules/undici/lib/mock/mock-symbols.js +1 -10
  565. package/node_modules/undici/lib/mock/mock-utils.js +51 -404
  566. package/node_modules/undici/lib/mock/pluralizer.js +29 -0
  567. package/node_modules/undici/lib/util/timers.js +9 -11
  568. package/node_modules/undici/lib/web/cache/cache.js +51 -63
  569. package/node_modules/undici/lib/web/cache/cachestorage.js +7 -13
  570. package/node_modules/undici/lib/web/cache/symbols.js +5 -0
  571. package/node_modules/undici/lib/web/cookies/index.js +18 -45
  572. package/node_modules/undici/lib/web/cookies/parse.js +149 -157
  573. package/node_modules/undici/lib/web/cookies/util.js +2 -4
  574. package/node_modules/undici/lib/web/eventsource/eventsource-stream.js +9 -37
  575. package/node_modules/undici/lib/web/eventsource/eventsource.js +64 -108
  576. package/node_modules/undici/lib/web/eventsource/util.js +5 -28
  577. package/node_modules/undici/lib/web/fetch/body.js +148 -173
  578. package/node_modules/undici/lib/web/fetch/constants.js +6 -13
  579. package/node_modules/undici/lib/web/fetch/data-url.js +167 -19
  580. package/node_modules/undici/lib/web/fetch/dispatcher-weakref.js +46 -0
  581. package/node_modules/undici/lib/web/fetch/file.js +126 -0
  582. package/node_modules/undici/lib/web/fetch/formdata-parser.js +117 -229
  583. package/node_modules/undici/lib/web/fetch/formdata.js +65 -85
  584. package/node_modules/undici/lib/web/fetch/headers.js +108 -143
  585. package/node_modules/undici/lib/web/fetch/index.js +446 -627
  586. package/node_modules/undici/lib/web/fetch/request.js +115 -217
  587. package/node_modules/undici/lib/web/fetch/response.js +82 -110
  588. package/node_modules/undici/lib/web/fetch/symbols.js +9 -0
  589. package/node_modules/undici/lib/web/fetch/util.js +393 -291
  590. package/node_modules/undici/lib/web/fetch/webidl.js +695 -0
  591. package/node_modules/undici/lib/web/fileapi/encoding.js +290 -0
  592. package/node_modules/undici/lib/web/fileapi/filereader.js +344 -0
  593. package/node_modules/undici/lib/web/fileapi/progressevent.js +78 -0
  594. package/node_modules/undici/lib/web/fileapi/symbols.js +10 -0
  595. package/node_modules/undici/lib/web/fileapi/util.js +391 -0
  596. package/node_modules/undici/lib/web/websocket/connection.js +160 -139
  597. package/node_modules/undici/lib/web/websocket/constants.js +10 -70
  598. package/node_modules/undici/lib/web/websocket/events.js +30 -49
  599. package/node_modules/undici/lib/web/websocket/frame.js +20 -51
  600. package/node_modules/undici/lib/web/websocket/receiver.js +87 -83
  601. package/node_modules/undici/lib/web/websocket/sender.js +13 -18
  602. package/node_modules/undici/lib/web/websocket/symbols.js +12 -0
  603. package/node_modules/undici/lib/web/websocket/util.js +90 -115
  604. package/node_modules/undici/lib/web/websocket/websocket.js +171 -359
  605. package/node_modules/undici/package.json +57 -49
  606. package/node_modules/undici/scripts/strip-comments.js +1 -3
  607. package/node_modules/undici/types/agent.d.ts +13 -12
  608. package/node_modules/undici/types/api.d.ts +26 -26
  609. package/node_modules/undici/types/balanced-pool.d.ts +12 -13
  610. package/node_modules/undici/types/client.d.ts +39 -98
  611. package/node_modules/undici/types/connector.d.ts +2 -5
  612. package/node_modules/undici/types/cookies.d.ts +1 -3
  613. package/node_modules/undici/types/diagnostics-channel.d.ts +11 -20
  614. package/node_modules/undici/types/dispatcher.d.ts +139 -136
  615. package/node_modules/undici/types/env-http-proxy-agent.d.ts +3 -4
  616. package/node_modules/undici/types/errors.d.ts +54 -86
  617. package/node_modules/undici/types/eventsource.d.ts +4 -9
  618. package/node_modules/undici/types/fetch.d.ts +25 -51
  619. package/node_modules/undici/types/file.d.ts +39 -0
  620. package/node_modules/undici/types/filereader.d.ts +54 -0
  621. package/node_modules/undici/types/formdata.d.ts +7 -7
  622. package/node_modules/undici/types/global-dispatcher.d.ts +4 -4
  623. package/node_modules/undici/types/global-origin.d.ts +5 -5
  624. package/node_modules/undici/types/handlers.d.ts +9 -10
  625. package/node_modules/undici/types/header.d.ts +1 -162
  626. package/node_modules/undici/types/index.d.ts +47 -69
  627. package/node_modules/undici/types/interceptors.d.ts +12 -62
  628. package/node_modules/undici/types/mock-agent.d.ts +27 -46
  629. package/node_modules/undici/types/mock-client.d.ts +4 -6
  630. package/node_modules/undici/types/mock-errors.d.ts +3 -3
  631. package/node_modules/undici/types/mock-interceptor.d.ts +21 -26
  632. package/node_modules/undici/types/mock-pool.d.ts +4 -6
  633. package/node_modules/undici/types/patch.d.ts +4 -0
  634. package/node_modules/undici/types/pool-stats.d.ts +8 -8
  635. package/node_modules/undici/types/pool.d.ts +14 -14
  636. package/node_modules/undici/types/proxy-agent.d.ts +6 -13
  637. package/node_modules/undici/types/readable.d.ts +16 -19
  638. package/node_modules/undici/types/retry-agent.d.ts +1 -1
  639. package/node_modules/undici/types/retry-handler.d.ts +9 -18
  640. package/node_modules/undici/types/util.d.ts +3 -3
  641. package/node_modules/undici/types/webidl.d.ts +32 -156
  642. package/node_modules/undici/types/websocket.d.ts +10 -48
  643. package/node_modules/validate-npm-package-name/package.json +4 -4
  644. package/node_modules/which/package.json +4 -4
  645. package/node_modules/write-file-atomic/package.json +4 -4
  646. package/package.json +56 -60
  647. package/node_modules/@npmcli/arborist/lib/npm-extension.js +0 -237
  648. package/node_modules/@npmcli/arborist/lib/package-extensions.js +0 -236
  649. package/node_modules/@npmcli/arborist/lib/patch.js +0 -111
  650. package/node_modules/@npmcli/arborist/lib/patched-dependencies.js +0 -168
  651. package/node_modules/cacache/lib/util/cache-dir.js +0 -29
  652. package/node_modules/diff/CONTRIBUTING.md +0 -28
  653. package/node_modules/diff/LICENSE +0 -29
  654. package/node_modules/diff/README.md +0 -388
  655. package/node_modules/diff/dist/diff.js +0 -1782
  656. package/node_modules/diff/dist/diff.min.js +0 -1
  657. package/node_modules/diff/eslint.config.mjs +0 -182
  658. package/node_modules/diff/libcjs/convert/dmp.d.ts +0 -8
  659. package/node_modules/diff/libcjs/convert/dmp.d.ts.map +0 -1
  660. package/node_modules/diff/libcjs/convert/dmp.js +0 -24
  661. package/node_modules/diff/libcjs/convert/xml.d.ts +0 -6
  662. package/node_modules/diff/libcjs/convert/xml.d.ts.map +0 -1
  663. package/node_modules/diff/libcjs/convert/xml.js +0 -34
  664. package/node_modules/diff/libcjs/diff/array.d.ts +0 -19
  665. package/node_modules/diff/libcjs/diff/array.d.ts.map +0 -1
  666. package/node_modules/diff/libcjs/diff/array.js +0 -40
  667. package/node_modules/diff/libcjs/diff/base.d.ts +0 -20
  668. package/node_modules/diff/libcjs/diff/base.d.ts.map +0 -1
  669. package/node_modules/diff/libcjs/diff/base.js +0 -265
  670. package/node_modules/diff/libcjs/diff/character.d.ts +0 -19
  671. package/node_modules/diff/libcjs/diff/character.d.ts.map +0 -1
  672. package/node_modules/diff/libcjs/diff/character.js +0 -31
  673. package/node_modules/diff/libcjs/diff/css.d.ts +0 -18
  674. package/node_modules/diff/libcjs/diff/css.d.ts.map +0 -1
  675. package/node_modules/diff/libcjs/diff/css.js +0 -34
  676. package/node_modules/diff/libcjs/diff/json.d.ts +0 -24
  677. package/node_modules/diff/libcjs/diff/json.d.ts.map +0 -1
  678. package/node_modules/diff/libcjs/diff/json.js +0 -105
  679. package/node_modules/diff/libcjs/diff/line.d.ts +0 -24
  680. package/node_modules/diff/libcjs/diff/line.d.ts.map +0 -1
  681. package/node_modules/diff/libcjs/diff/line.js +0 -89
  682. package/node_modules/diff/libcjs/diff/sentence.d.ts +0 -21
  683. package/node_modules/diff/libcjs/diff/sentence.d.ts.map +0 -1
  684. package/node_modules/diff/libcjs/diff/sentence.js +0 -67
  685. package/node_modules/diff/libcjs/diff/word.d.ts +0 -35
  686. package/node_modules/diff/libcjs/diff/word.d.ts.map +0 -1
  687. package/node_modules/diff/libcjs/diff/word.js +0 -312
  688. package/node_modules/diff/libcjs/index.d.ts +0 -20
  689. package/node_modules/diff/libcjs/index.d.ts.map +0 -1
  690. package/node_modules/diff/libcjs/index.js +0 -64
  691. package/node_modules/diff/libcjs/package.json +0 -1
  692. package/node_modules/diff/libcjs/patch/apply.d.ts +0 -62
  693. package/node_modules/diff/libcjs/patch/apply.d.ts.map +0 -1
  694. package/node_modules/diff/libcjs/patch/apply.js +0 -267
  695. package/node_modules/diff/libcjs/patch/create.d.ts +0 -122
  696. package/node_modules/diff/libcjs/patch/create.d.ts.map +0 -1
  697. package/node_modules/diff/libcjs/patch/create.js +0 -251
  698. package/node_modules/diff/libcjs/patch/line-endings.d.ts +0 -17
  699. package/node_modules/diff/libcjs/patch/line-endings.d.ts.map +0 -1
  700. package/node_modules/diff/libcjs/patch/line-endings.js +0 -61
  701. package/node_modules/diff/libcjs/patch/parse.d.ts +0 -8
  702. package/node_modules/diff/libcjs/patch/parse.d.ts.map +0 -1
  703. package/node_modules/diff/libcjs/patch/parse.js +0 -150
  704. package/node_modules/diff/libcjs/patch/reverse.d.ts +0 -9
  705. package/node_modules/diff/libcjs/patch/reverse.d.ts.map +0 -1
  706. package/node_modules/diff/libcjs/patch/reverse.js +0 -37
  707. package/node_modules/diff/libcjs/types.d.ts +0 -213
  708. package/node_modules/diff/libcjs/types.d.ts.map +0 -1
  709. package/node_modules/diff/libcjs/types.js +0 -2
  710. package/node_modules/diff/libcjs/util/array.d.ts +0 -3
  711. package/node_modules/diff/libcjs/util/array.d.ts.map +0 -1
  712. package/node_modules/diff/libcjs/util/array.js +0 -21
  713. package/node_modules/diff/libcjs/util/distance-iterator.d.ts +0 -2
  714. package/node_modules/diff/libcjs/util/distance-iterator.d.ts.map +0 -1
  715. package/node_modules/diff/libcjs/util/distance-iterator.js +0 -40
  716. package/node_modules/diff/libcjs/util/params.d.ts +0 -4
  717. package/node_modules/diff/libcjs/util/params.d.ts.map +0 -1
  718. package/node_modules/diff/libcjs/util/params.js +0 -17
  719. package/node_modules/diff/libcjs/util/string.d.ts +0 -30
  720. package/node_modules/diff/libcjs/util/string.d.ts.map +0 -1
  721. package/node_modules/diff/libcjs/util/string.js +0 -200
  722. package/node_modules/diff/libesm/convert/dmp.d.ts +0 -8
  723. package/node_modules/diff/libesm/convert/dmp.d.ts.map +0 -1
  724. package/node_modules/diff/libesm/convert/dmp.js +0 -21
  725. package/node_modules/diff/libesm/convert/xml.d.ts +0 -6
  726. package/node_modules/diff/libesm/convert/xml.d.ts.map +0 -1
  727. package/node_modules/diff/libesm/convert/xml.js +0 -31
  728. package/node_modules/diff/libesm/diff/array.d.ts +0 -19
  729. package/node_modules/diff/libesm/diff/array.d.ts.map +0 -1
  730. package/node_modules/diff/libesm/diff/array.js +0 -16
  731. package/node_modules/diff/libesm/diff/base.d.ts +0 -20
  732. package/node_modules/diff/libesm/diff/base.d.ts.map +0 -1
  733. package/node_modules/diff/libesm/diff/base.js +0 -253
  734. package/node_modules/diff/libesm/diff/character.d.ts +0 -19
  735. package/node_modules/diff/libesm/diff/character.d.ts.map +0 -1
  736. package/node_modules/diff/libesm/diff/character.js +0 -7
  737. package/node_modules/diff/libesm/diff/css.d.ts +0 -18
  738. package/node_modules/diff/libesm/diff/css.d.ts.map +0 -1
  739. package/node_modules/diff/libesm/diff/css.js +0 -10
  740. package/node_modules/diff/libesm/diff/json.d.ts +0 -24
  741. package/node_modules/diff/libesm/diff/json.d.ts.map +0 -1
  742. package/node_modules/diff/libesm/diff/json.js +0 -78
  743. package/node_modules/diff/libesm/diff/line.d.ts +0 -24
  744. package/node_modules/diff/libesm/diff/line.d.ts.map +0 -1
  745. package/node_modules/diff/libesm/diff/line.js +0 -65
  746. package/node_modules/diff/libesm/diff/sentence.d.ts +0 -21
  747. package/node_modules/diff/libesm/diff/sentence.d.ts.map +0 -1
  748. package/node_modules/diff/libesm/diff/sentence.js +0 -43
  749. package/node_modules/diff/libesm/diff/word.d.ts +0 -35
  750. package/node_modules/diff/libesm/diff/word.d.ts.map +0 -1
  751. package/node_modules/diff/libesm/diff/word.js +0 -281
  752. package/node_modules/diff/libesm/index.d.ts +0 -20
  753. package/node_modules/diff/libesm/index.d.ts.map +0 -1
  754. package/node_modules/diff/libesm/index.js +0 -30
  755. package/node_modules/diff/libesm/package.json +0 -1
  756. package/node_modules/diff/libesm/patch/apply.d.ts +0 -62
  757. package/node_modules/diff/libesm/patch/apply.d.ts.map +0 -1
  758. package/node_modules/diff/libesm/patch/apply.js +0 -257
  759. package/node_modules/diff/libesm/patch/create.d.ts +0 -122
  760. package/node_modules/diff/libesm/patch/create.d.ts.map +0 -1
  761. package/node_modules/diff/libesm/patch/create.js +0 -228
  762. package/node_modules/diff/libesm/patch/line-endings.d.ts +0 -17
  763. package/node_modules/diff/libesm/patch/line-endings.d.ts.map +0 -1
  764. package/node_modules/diff/libesm/patch/line-endings.js +0 -44
  765. package/node_modules/diff/libesm/patch/parse.d.ts +0 -8
  766. package/node_modules/diff/libesm/patch/parse.d.ts.map +0 -1
  767. package/node_modules/diff/libesm/patch/parse.js +0 -147
  768. package/node_modules/diff/libesm/patch/reverse.d.ts +0 -9
  769. package/node_modules/diff/libesm/patch/reverse.d.ts.map +0 -1
  770. package/node_modules/diff/libesm/patch/reverse.js +0 -23
  771. package/node_modules/diff/libesm/types.d.ts +0 -213
  772. package/node_modules/diff/libesm/types.d.ts.map +0 -1
  773. package/node_modules/diff/libesm/types.js +0 -1
  774. package/node_modules/diff/libesm/util/array.d.ts +0 -3
  775. package/node_modules/diff/libesm/util/array.d.ts.map +0 -1
  776. package/node_modules/diff/libesm/util/array.js +0 -17
  777. package/node_modules/diff/libesm/util/distance-iterator.d.ts +0 -2
  778. package/node_modules/diff/libesm/util/distance-iterator.d.ts.map +0 -1
  779. package/node_modules/diff/libesm/util/distance-iterator.js +0 -37
  780. package/node_modules/diff/libesm/util/params.d.ts +0 -4
  781. package/node_modules/diff/libesm/util/params.d.ts.map +0 -1
  782. package/node_modules/diff/libesm/util/params.js +0 -14
  783. package/node_modules/diff/libesm/util/string.d.ts +0 -30
  784. package/node_modules/diff/libesm/util/string.d.ts.map +0 -1
  785. package/node_modules/diff/libesm/util/string.js +0 -184
  786. package/node_modules/diff/package.json +0 -130
  787. package/node_modules/diff/release-notes.md +0 -432
  788. package/node_modules/node-gyp/commitlint.config.mjs +0 -3
  789. package/node_modules/node-gyp/gyp/commitlint.config.js +0 -6
  790. package/node_modules/node-gyp/gyp/pylib/gyp/generator/cmake_test.py +0 -105
  791. package/node_modules/node-gyp/zizmor.yml +0 -5
  792. package/node_modules/proxy-agent-negotiate/dist/index.d.ts +0 -14
  793. package/node_modules/proxy-agent-negotiate/dist/index.d.ts.map +0 -1
  794. package/node_modules/proxy-agent-negotiate/dist/index.js +0 -35
  795. package/node_modules/proxy-agent-negotiate/dist/index.js.map +0 -1
  796. package/node_modules/proxy-agent-negotiate/package.json +0 -47
  797. package/node_modules/undici/docs/docs/api/CacheStore.md +0 -360
  798. package/node_modules/undici/docs/docs/api/ClientStats.md +0 -93
  799. package/node_modules/undici/docs/docs/api/GlobalInstallation.md +0 -121
  800. package/node_modules/undici/docs/docs/api/H2CClient.md +0 -385
  801. package/node_modules/undici/docs/docs/api/Interceptors.md +0 -419
  802. package/node_modules/undici/docs/docs/api/MockCallHistory.md +0 -371
  803. package/node_modules/undici/docs/docs/api/MockCallHistoryLog.md +0 -206
  804. package/node_modules/undici/docs/docs/api/RoundRobinPool.md +0 -239
  805. package/node_modules/undici/docs/docs/api/SnapshotAgent.md +0 -361
  806. package/node_modules/undici/docs/docs/api/Socks5ProxyAgent.md +0 -256
  807. package/node_modules/undici/docs/docs/best-practices/migrating-from-v7-to-v8.md +0 -233
  808. package/node_modules/undici/docs/docs/getting-started.md +0 -281
  809. package/node_modules/undici/docs/docs/site.json +0 -125
  810. package/node_modules/undici/docs/docs/type-map.json +0 -79
  811. package/node_modules/undici/lib/dispatcher/dispatcher1-wrapper.js +0 -110
  812. package/node_modules/undici/types/dispatcher1-wrapper.d.ts +0 -7
  813. /package/node_modules/{undici → @mytools/fst-platform/node_modules/undici}/lib/core/socks5-client.js +0 -0
  814. /package/node_modules/{undici → @mytools/fst-platform/node_modules/undici}/lib/core/socks5-utils.js +0 -0
  815. /package/node_modules/{undici → @mytools/fst-platform/node_modules/undici}/lib/encoding/index.js +0 -0
  816. /package/node_modules/{undici → @mytools/fst-platform/node_modules/undici}/lib/llhttp/constants.d.ts +0 -0
  817. /package/node_modules/{undici → @mytools/fst-platform/node_modules/undici}/lib/llhttp/utils.d.ts +0 -0
  818. /package/node_modules/{undici → @mytools/fst-platform/node_modules/undici}/lib/mock/snapshot-utils.js +0 -0
  819. /package/node_modules/{undici → @mytools/fst-platform/node_modules/undici}/lib/util/date.js +0 -0
  820. /package/node_modules/{undici → @mytools/fst-platform/node_modules/undici}/lib/util/stats.js +0 -0
  821. /package/node_modules/{undici → @mytools/fst-platform/node_modules/undici}/lib/web/subresource-integrity/Readme.md +0 -0
  822. /package/node_modules/{undici → @mytools/fst-platform/node_modules/undici}/lib/web/subresource-integrity/subresource-integrity.js +0 -0
  823. /package/node_modules/{undici → @mytools/fst-platform/node_modules/undici}/types/cache-interceptor.d.ts +0 -0
  824. /package/node_modules/{undici → @mytools/fst-platform/node_modules/undici}/types/client-stats.d.ts +0 -0
  825. /package/node_modules/{undici → @mytools/fst-platform/node_modules/undici}/types/mock-call-history.d.ts +0 -0
  826. /package/node_modules/{undici → @mytools/fst-platform/node_modules/undici}/types/utility.d.ts +0 -0
@@ -1,61 +1,34 @@
1
1
  # Dispatcher
2
2
 
3
- <!--introduced_in=v4.0.0-->
3
+ Extends: `events.EventEmitter`
4
4
 
5
- <!--type=module-->
5
+ Dispatcher is the core API used to dispatch requests.
6
6
 
7
- <!-- source_link=lib/dispatcher/dispatcher.js -->
7
+ Requests are not guaranteed to be dispatched in order of invocation.
8
8
 
9
- > Stability: 2 - Stable
9
+ ## Instance Methods
10
10
 
11
- `Dispatcher` is the core abstraction used to dispatch HTTP requests in undici.
12
- It extends [`EventEmitter`][] and defines the low-level [`dispatch()`][] contract
13
- along with the higher-level [`request()`][], [`stream()`][], [`pipeline()`][],
14
- [`connect()`][], and [`upgrade()`][] methods that every concrete dispatcher
15
- provides.
11
+ ### `Dispatcher.close([callback]): Promise`
16
12
 
17
- `Dispatcher` itself is abstract: its [`dispatch()`][], [`close()`][], and
18
- [`destroy()`][] methods throw `Error: not implemented`. Concrete dispatchers such
19
- as [`Client`][], [`Pool`][], [`BalancedPool`][], and [`Agent`][] implement the
20
- contract and are what application code instantiates. Requests are not guaranteed
21
- to be dispatched in the order in which they are invoked.
13
+ Closes the dispatcher and gracefully waits for enqueued requests to complete before resolving.
22
14
 
23
- ```mjs
24
- import { Dispatcher, Agent } from 'undici'
15
+ Arguments:
25
16
 
26
- const dispatcher = new Agent()
27
- console.log(dispatcher instanceof Dispatcher) // true
28
- ```
29
-
30
- ## Class: `Dispatcher`
31
-
32
- <!-- YAML
33
- added: v4.0.0
34
- -->
35
-
36
- * Extends: {EventEmitter}
37
-
38
- Base dispatcher class. Concrete dispatchers extend it and implement the
39
- [`dispatch()`][] method on which the other request helpers are built.
40
-
41
- ### `dispatcher.close([callback])`
17
+ * **callback** `(error: Error | null, data: null) => void` (optional)
42
18
 
43
- <!-- YAML
44
- added: v4.0.0
45
- -->
19
+ Returns: `void | Promise<null>` - Only returns a `Promise` if no `callback` argument was passed
46
20
 
47
- * `callback` {Function} (optional) Invoked once the dispatcher is closed.
48
- * `error` {Error|null}
49
- * Returns: {Promise} A `Promise` is returned only when `callback` is omitted. It
50
- resolves with `void` once the dispatcher is closed.
21
+ ```js
22
+ dispatcher.close() // -> Promise
23
+ dispatcher.close(() => {}) // -> void
24
+ ```
51
25
 
52
- Closes the dispatcher and gracefully waits for enqueued requests to complete
53
- before resolving or invoking `callback`.
26
+ #### Example - Request resolves before Client closes
54
27
 
55
- ```mjs
56
- import { createServer } from 'node:http'
28
+ ```js
29
+ import { createServer } from 'http'
57
30
  import { Client } from 'undici'
58
- import { once } from 'node:events'
31
+ import { once } from 'events'
59
32
 
60
33
  const server = createServer((request, response) => {
61
34
  response.end('undici')
@@ -66,7 +39,10 @@ await once(server, 'listening')
66
39
  const client = new Client(`http://localhost:${server.address().port}`)
67
40
 
68
41
  try {
69
- const { body } = await client.request({ path: '/', method: 'GET' })
42
+ const { body } = await client.request({
43
+ path: '/',
44
+ method: 'GET'
45
+ })
70
46
  body.setEncoding('utf8')
71
47
  body.on('data', console.log)
72
48
  } catch (error) {}
@@ -77,41 +53,40 @@ console.log('Client closed')
77
53
  server.close()
78
54
  ```
79
55
 
80
- ### `dispatcher.connect(options[, callback])`
81
-
82
- <!-- YAML
83
- added: v4.0.0
84
- -->
85
-
86
- * `options` {Object}
87
- * `origin` {string|URL} The origin to connect to.
88
- * `path` {string} The request path.
89
- * `headers` {UndiciHeaders} Request headers. **Default:** `null`.
90
- * `signal` {AbortSignal|EventEmitter|null} A signal used to abort the request.
91
- **Default:** `null`.
92
- * `opaque` {any} An opaque value passed through to the returned `ConnectData`.
93
- * `responseHeaders` {string|null} Set to `'raw'` to return the response headers
94
- as a raw array instead of an object. **Default:** `null`.
95
- * `callback` {Function} (optional) Invoked when the connection is established.
96
- * `error` {Error|null}
97
- * `data` {Object}
98
- * `statusCode` {number}
99
- * `headers` {Object} The response headers.
100
- * `socket` {Duplex} The established socket.
101
- * `opaque` {any} The `opaque` value passed in `options`.
102
- * Returns: {Promise} A `Promise` is returned only when `callback` is omitted. It
103
- resolves with the `data` object described above.
104
-
105
- Starts two-way communications with the requested resource using the
106
- [HTTP `CONNECT`][] method.
107
-
108
- ```mjs
109
- import { createServer } from 'node:http'
56
+ ### `Dispatcher.connect(options[, callback])`
57
+
58
+ Starts two-way communications with the requested resource using [HTTP CONNECT](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/CONNECT).
59
+
60
+ Arguments:
61
+
62
+ * **options** `ConnectOptions`
63
+ * **callback** `(err: Error | null, data: ConnectData | null) => void` (optional)
64
+
65
+ Returns: `void | Promise<ConnectData>` - Only returns a `Promise` if no `callback` argument was passed
66
+
67
+ #### Parameter: `ConnectOptions`
68
+
69
+ * **path** `string`
70
+ * **headers** `UndiciHeaders` (optional) - Default: `null`
71
+ * **signal** `AbortSignal | events.EventEmitter | null` (optional) - Default: `null`
72
+ * **opaque** `unknown` (optional) - This argument parameter is passed through to `ConnectData`
73
+
74
+ #### Parameter: `ConnectData`
75
+
76
+ * **statusCode** `number`
77
+ * **headers** `Record<string, string | string[] | undefined>`
78
+ * **socket** `stream.Duplex`
79
+ * **opaque** `unknown`
80
+
81
+ #### Example - Connect request with echo
82
+
83
+ ```js
84
+ import { createServer } from 'http'
110
85
  import { Client } from 'undici'
111
- import { once } from 'node:events'
86
+ import { once } from 'events'
112
87
 
113
88
  const server = createServer((request, response) => {
114
- throw new Error('should never get here')
89
+ throw Error('should never get here')
115
90
  }).listen()
116
91
 
117
92
  server.on('connect', (req, socket, head) => {
@@ -132,7 +107,9 @@ await once(server, 'listening')
132
107
  const client = new Client(`http://localhost:${server.address().port}`)
133
108
 
134
109
  try {
135
- const { socket } = await client.connect({ path: '/' })
110
+ const { socket } = await client.connect({
111
+ path: '/'
112
+ })
136
113
  const wanted = 'Body'
137
114
  let data = ''
138
115
  socket.on('data', d => { data += d })
@@ -143,39 +120,35 @@ try {
143
120
  })
144
121
  socket.write(wanted)
145
122
  socket.end()
146
- } catch (error) {}
123
+ } catch (error) { }
147
124
  ```
148
125
 
149
- ### `dispatcher.destroy([error[, callback]])`
126
+ ### `Dispatcher.destroy([error, callback]): Promise`
127
+
128
+ Destroy the dispatcher abruptly with the given error. All the pending and running requests will be asynchronously aborted and error. Since this operation is asynchronously dispatched there might still be some progress on dispatched requests.
150
129
 
151
- <!-- YAML
152
- added: v4.0.0
153
- -->
130
+ Both arguments are optional; the method can be called in four different ways:
154
131
 
155
- * `error` {Error|null} (optional) The error with which pending requests are
156
- rejected. **Default:** `null`.
157
- * `callback` {Function} (optional) Invoked once the socket is closed.
158
- * Returns: {Promise} A `Promise` is returned only when `callback` is omitted. It
159
- resolves with `void` once the dispatcher is destroyed.
132
+ Arguments:
160
133
 
161
- Destroys the dispatcher abruptly with the given `error`. All pending and running
162
- requests are asynchronously aborted and rejected. Because the operation is
163
- dispatched asynchronously, dispatched requests may still make some progress
164
- before being aborted.
134
+ * **error** `Error | null` (optional)
135
+ * **callback** `(error: Error | null, data: null) => void` (optional)
165
136
 
166
- Both arguments are optional, so the method can be called in four ways:
137
+ Returns: `void | Promise<void>` - Only returns a `Promise` if no `callback` argument was passed
167
138
 
168
- ```mjs
139
+ ```js
169
140
  dispatcher.destroy() // -> Promise
170
141
  dispatcher.destroy(new Error()) // -> Promise
171
142
  dispatcher.destroy(() => {}) // -> void
172
143
  dispatcher.destroy(new Error(), () => {}) // -> void
173
144
  ```
174
145
 
175
- ```mjs
176
- import { createServer } from 'node:http'
146
+ #### Example - Request is aborted when Client is destroyed
147
+
148
+ ```js
149
+ import { createServer } from 'http'
177
150
  import { Client } from 'undici'
178
- import { once } from 'node:events'
151
+ import { once } from 'events'
179
152
 
180
153
  const server = createServer((request, response) => {
181
154
  response.end()
@@ -186,7 +159,10 @@ await once(server, 'listening')
186
159
  const client = new Client(`http://localhost:${server.address().port}`)
187
160
 
188
161
  try {
189
- const request = client.request({ path: '/', method: 'GET' })
162
+ const request = client.request({
163
+ path: '/',
164
+ method: 'GET'
165
+ })
190
166
  client.destroy()
191
167
  .then(() => {
192
168
  console.log('Client destroyed')
@@ -198,111 +174,53 @@ try {
198
174
  }
199
175
  ```
200
176
 
201
- ### `dispatcher.dispatch(options, handler)`
202
-
203
- <!-- YAML
204
- added: v4.0.0
205
- -->
206
-
207
- * `options` {Object}
208
- * `origin` {string|URL} (optional) The origin to dispatch the request to.
209
- * `path` {string} The request path.
210
- * `method` {string} The HTTP method, e.g. `'GET'` or `'POST'`.
211
- * `body` {string|Buffer|Uint8Array|Readable|FormData|null} The request body.
212
- **Default:** `null`.
213
- * `headers` {UndiciHeaders} Request headers. **Default:** `null`.
214
- * `query` {Object} Query string parameters embedded into the request URL. Both
215
- keys and values are encoded with `encodeURIComponent`. **Default:** `null`.
216
- * `idempotent` {boolean} Whether the request can be safely retried. If `false`,
217
- the request is not sent until all preceding requests in the pipeline have
218
- completed. **Default:** `true` when `method` is `'HEAD'` or `'GET'`.
219
- * `blocking` {boolean} Whether the response is expected to block the pipeline.
220
- When `true`, further pipelining on the same connection is avoided until
221
- headers have been received. **Default:** `method !== 'HEAD'`.
222
- * `typeOfService` {number|null} The IP Type of Service (ToS) value for the
223
- request socket. Must be an integer between `0` and `255`. **Default:** `0`.
224
- * `upgrade` {boolean|string|null} Upgrades the request, e.g. to `'Websocket'`.
225
- **Default:** `null`, or the request method when it is `'CONNECT'`.
226
- * `headersTimeout` {number|null} The time, in milliseconds, the parser waits to
227
- receive the complete HTTP headers. Defaults to 300 seconds.
228
- * `bodyTimeout` {number|null} The time, in milliseconds, after which the request
229
- times out while receiving body data. Monitors the time between body chunks.
230
- Use `0` to disable it entirely. Defaults to 300 seconds.
231
- HTTP/1.1 headers/body parser timeouts are not guaranteed to fire with exact
232
- millisecond precision: delays up to 1000ms use native timers, while larger
233
- delays use undici's lower-overhead fast timers with a target resolution
234
- around 500ms.
235
- * `reset` {boolean} Whether the request should establish a keep-alive
236
- connection. **Default:** `false`.
237
- * `expectContinue` {boolean} For HTTP/2, appends the `expect: 100-continue`
238
- header and halts the request body until a `100 Continue` is received from the
239
- remote server. **Default:** `false`.
240
- * `handler` {Object} A set of callbacks invoked over the request lifecycle.
241
- * `onRequestStart` {Function} Invoked before the request is dispatched on the
242
- socket. May be invoked multiple times when the request is retried.
243
- * `controller` {DispatchController}
244
- * `context` {any}
245
- * `onRequestUpgrade` {Function} (optional) Invoked when the request is upgraded.
246
- Required when `options.upgrade` is set or `options.method` is `'CONNECT'`.
247
- * `controller` {DispatchController}
248
- * `statusCode` {number}
249
- * `headers` {Object}
250
- * `socket` {Duplex}
251
- * `onResponseStart` {Function} (optional) Invoked when the status code and
252
- headers have been received. May be invoked multiple times for 1xx
253
- informational responses. Not used for `upgrade` requests.
254
- * `controller` {DispatchController}
255
- * `statusCode` {number}
256
- * `headers` {Object}
257
- * `statusMessage` {string} (optional)
258
- * `onResponseData` {Function} (optional) Invoked when response payload data is
259
- received. Not used for `upgrade` requests.
260
- * `controller` {DispatchController}
261
- * `chunk` {Buffer}
262
- * `onResponseEnd` {Function} (optional) Invoked when the response payload and
263
- trailers have been received and the request has completed. Not used for
264
- `upgrade` requests.
265
- * `controller` {DispatchController}
266
- * `trailers` {Object}
267
- * `onResponseError` {Function} (optional) Invoked when an error occurs. Must not
268
- throw.
269
- * `controller` {DispatchController}
270
- * `error` {Error}
271
- * `onResponseStarted` {Function} (optional) Invoked when the response is
272
- received, before headers have been read.
273
- * `onBodySent` {Function} (optional) Invoked when a chunk of the request body is
274
- sent. May be invoked multiple times for chunked requests.
275
- * `chunk` {Buffer}
276
- * `onRequestSent` {Function} (optional) Invoked after the request body is fully
277
- sent.
278
- * Returns: {boolean} `false` when the dispatcher is busy and further `dispatch()`
279
- calls will make no progress until the [`'drain'`][] event is emitted.
280
-
281
- This is the low-level API on which all the higher-level methods are built. This
282
- API is expected to evolve through semver-major versions and is less stable than
283
- the higher-level methods. It is primarily intended for library developers who
284
- implement higher-level APIs on top of it.
285
-
286
- The `controller` passed to each handler is a `DispatchController` with the
287
- following shape:
288
-
289
- * `aborted` {boolean} Whether the request has been aborted.
290
- * `paused` {boolean} Whether the request is paused.
291
- * `reason` {Error|null} The reason the request was aborted, if any.
292
- * `rawHeaders` {Buffer[]|string[]|Object|null} The raw response headers,
293
- preserving duplicates and casing.
294
- * `rawTrailers` {Buffer[]|string[]|Object|null} The raw response trailers.
295
- * `abort(reason)` Aborts the request with the given `reason`.
296
- * `pause()` Pauses the response stream.
297
- * `resume()` Resumes the response stream.
298
-
299
- Call `controller.pause()` and `controller.resume()` to apply backpressure rather
300
- than returning `false` from a handler.
301
-
302
- ```mjs
303
- import { createServer } from 'node:http'
177
+ ### `Dispatcher.dispatch(options, handler)`
178
+
179
+ This is the low level API which all the preceding APIs are implemented on top of.
180
+ This API is expected to evolve through semver-major versions and is less stable than the preceding higher level APIs.
181
+ It is primarily intended for library developers who implement higher level APIs on top of this.
182
+
183
+ Arguments:
184
+
185
+ * **options** `DispatchOptions`
186
+ * **handler** `DispatchHandler`
187
+
188
+ Returns: `Boolean` - `false` if dispatcher is busy and further dispatch calls won't make any progress until the `'drain'` event has been emitted.
189
+
190
+ #### Parameter: `DispatchOptions`
191
+
192
+ * **origin** `string | URL`
193
+ * **path** `string`
194
+ * **method** `string`
195
+ * **reset** `boolean` (optional) - Default: `false` - If `false`, the request will attempt to create a long-living connection by sending the `connection: keep-alive` header,otherwise will attempt to close it immediately after response by sending `connection: close` within the request and closing the socket afterwards.
196
+ * **body** `string | Buffer | Uint8Array | stream.Readable | Iterable | AsyncIterable | null` (optional) - Default: `null`
197
+ * **headers** `UndiciHeaders | string[]` (optional) - Default: `null`.
198
+ * **query** `Record<string, any> | null` (optional) - Default: `null` - Query string params to be embedded in the request URL. Note that both keys and values of query are encoded using `encodeURIComponent`. If for some reason you need to send them unencoded, embed query params into path directly instead.
199
+ * **idempotent** `boolean` (optional) - Default: `true` if `method` is `'HEAD'` or `'GET'` - Whether the requests can be safely retried or not. If `false` the request won't be sent until all preceding requests in the pipeline has completed.
200
+ * **blocking** `boolean` (optional) - Default: `false` - Whether the response is expected to take a long time and would end up blocking the pipeline. When this is set to `true` further pipelining will be avoided on the same connection until headers have been received.
201
+ * **upgrade** `string | null` (optional) - Default: `null` - Upgrade the request. Should be used to specify the kind of upgrade i.e. `'Websocket'`.
202
+ * **bodyTimeout** `number | null` (optional) - The timeout after which a request will time out, in milliseconds. Monitors time between receiving body data. Use `0` to disable it entirely. Defaults to 300 seconds.
203
+ * **headersTimeout** `number | null` (optional) - The amount of time, in milliseconds, the parser will wait to receive the complete HTTP headers while not sending the request. Defaults to 300 seconds.
204
+ * **throwOnError** `boolean` (optional) - Default: `false` - Whether Undici should throw an error upon receiving a 4xx or 5xx response from the server.
205
+ * **expectContinue** `boolean` (optional) - Default: `false` - For H2, it appends the expect: 100-continue header, and halts the request body until a 100-continue is received from the remote server
206
+
207
+ #### Parameter: `DispatchHandler`
208
+
209
+ * **onConnect** `(abort: () => void, context: object) => void` - Invoked before request is dispatched on socket. May be invoked multiple times when a request is retried when the request at the head of the pipeline fails.
210
+ * **onError** `(error: Error) => void` - Invoked when an error has occurred. May not throw.
211
+ * **onUpgrade** `(statusCode: number, headers: Buffer[], socket: Duplex) => void` (optional) - Invoked when request is upgraded. Required if `DispatchOptions.upgrade` is defined or `DispatchOptions.method === 'CONNECT'`.
212
+ * **onResponseStarted** `() => void` (optional) - Invoked when response is received, before headers have been read.
213
+ * **onHeaders** `(statusCode: number, headers: Buffer[], resume: () => void, statusText: string) => boolean` - Invoked when statusCode and headers have been received. May be invoked multiple times due to 1xx informational headers. Not required for `upgrade` requests.
214
+ * **onData** `(chunk: Buffer) => boolean` - Invoked when response payload data is received. Not required for `upgrade` requests.
215
+ * **onComplete** `(trailers: Buffer[]) => void` - Invoked when response payload and trailers have been received and the request has completed. Not required for `upgrade` requests.
216
+ * **onBodySent** `(chunk: string | Buffer | Uint8Array) => void` - Invoked when a body chunk is sent to the server. Not required. For a stream or iterable body this will be invoked for every chunk. For other body types, it will be invoked once after the body is sent.
217
+
218
+ #### Example 1 - Dispatch GET request
219
+
220
+ ```js
221
+ import { createServer } from 'http'
304
222
  import { Client } from 'undici'
305
- import { once } from 'node:events'
223
+ import { once } from 'events'
306
224
 
307
225
  const server = createServer((request, response) => {
308
226
  response.end('Hello, World!')
@@ -317,61 +235,169 @@ const data = []
317
235
  client.dispatch({
318
236
  path: '/',
319
237
  method: 'GET',
320
- headers: { 'x-foo': 'bar' }
238
+ headers: {
239
+ 'x-foo': 'bar'
240
+ }
321
241
  }, {
322
- onRequestStart: () => {
242
+ onConnect: () => {
323
243
  console.log('Connected!')
324
244
  },
325
- onResponseError: (_controller, error) => {
245
+ onError: (error) => {
326
246
  console.error(error)
327
247
  },
328
- onResponseStart: (_controller, statusCode, headers) => {
329
- console.log(`statusCode: ${statusCode} | headers: ${JSON.stringify(headers)}`)
248
+ onHeaders: (statusCode, headers) => {
249
+ console.log(`onHeaders | statusCode: ${statusCode} | headers: ${headers}`)
330
250
  },
331
- onResponseData: (_controller, chunk) => {
251
+ onData: (chunk) => {
252
+ console.log('onData: chunk received')
332
253
  data.push(chunk)
333
254
  },
334
- onResponseEnd: (_controller, trailers) => {
335
- console.log(`trailers: ${JSON.stringify(trailers)}`)
336
- console.log(`Data: ${Buffer.concat(data).toString('utf8')}`)
255
+ onComplete: (trailers) => {
256
+ console.log(`onComplete | trailers: ${trailers}`)
257
+ const res = Buffer.concat(data).toString('utf8')
258
+ console.log(`Data: ${res}`)
337
259
  client.close()
338
260
  server.close()
339
261
  }
340
262
  })
341
263
  ```
342
264
 
343
- ### `dispatcher.pipeline(options, handler)`
344
-
345
- <!-- YAML
346
- added: v4.0.0
347
- -->
348
-
349
- * `options` {Object} Accepts every field of [`dispatcher.request()`][]'s
350
- `options`, plus:
351
- * `objectMode` {boolean} Set to `true` when `handler` returns an object stream.
352
- **Default:** `false`.
353
- * `handler` {Function} Returns a `Readable` from which the result is read.
354
- * `data` {Object}
355
- * `statusCode` {number}
356
- * `headers` {Object} The response headers.
357
- * `opaque` {any} The `opaque` value passed in `options`.
358
- * `body` {Readable} The response body.
359
- * `context` {Object}
360
- * Returns: {Readable}
361
- * Returns: {Duplex} A duplex stream that writes to the request and reads from the
362
- response.
363
-
364
- For easy use with [`stream.pipeline()`][]. The `handler` should return a
365
- `Readable` from which the result is read. Usually it returns the `body` directly,
366
- unless a transformation is needed based on, for example, `headers` or
367
- `statusCode`. The `handler` should validate the response and save any required
368
- state; if there is an error, it should be thrown.
369
-
370
- ```mjs
371
- import { Readable, Writable, PassThrough, pipeline } from 'node:stream'
372
- import { createServer } from 'node:http'
265
+ #### Example 2 - Dispatch Upgrade Request
266
+
267
+ ```js
268
+ import { createServer } from 'http'
269
+ import { Client } from 'undici'
270
+ import { once } from 'events'
271
+
272
+ const server = createServer((request, response) => {
273
+ response.end()
274
+ }).listen()
275
+
276
+ await once(server, 'listening')
277
+
278
+ server.on('upgrade', (request, socket, head) => {
279
+ console.log('Node.js Server - upgrade event')
280
+ socket.write('HTTP/1.1 101 Web Socket Protocol Handshake\r\n')
281
+ socket.write('Upgrade: WebSocket\r\n')
282
+ socket.write('Connection: Upgrade\r\n')
283
+ socket.write('\r\n')
284
+ socket.end()
285
+ })
286
+
287
+ const client = new Client(`http://localhost:${server.address().port}`)
288
+
289
+ client.dispatch({
290
+ path: '/',
291
+ method: 'GET',
292
+ upgrade: 'websocket'
293
+ }, {
294
+ onConnect: () => {
295
+ console.log('Undici Client - onConnect')
296
+ },
297
+ onError: (error) => {
298
+ console.log('onError') // shouldn't print
299
+ },
300
+ onUpgrade: (statusCode, headers, socket) => {
301
+ console.log('Undici Client - onUpgrade')
302
+ console.log(`onUpgrade Headers: ${headers}`)
303
+ socket.on('data', buffer => {
304
+ console.log(buffer.toString('utf8'))
305
+ })
306
+ socket.on('end', () => {
307
+ client.close()
308
+ server.close()
309
+ })
310
+ socket.end()
311
+ }
312
+ })
313
+ ```
314
+
315
+ #### Example 3 - Dispatch POST request
316
+
317
+ ```js
318
+ import { createServer } from 'http'
373
319
  import { Client } from 'undici'
374
- import { once } from 'node:events'
320
+ import { once } from 'events'
321
+
322
+ const server = createServer((request, response) => {
323
+ request.on('data', (data) => {
324
+ console.log(`Request Data: ${data.toString('utf8')}`)
325
+ const body = JSON.parse(data)
326
+ body.message = 'World'
327
+ response.end(JSON.stringify(body))
328
+ })
329
+ }).listen()
330
+
331
+ await once(server, 'listening')
332
+
333
+ const client = new Client(`http://localhost:${server.address().port}`)
334
+
335
+ const data = []
336
+
337
+ client.dispatch({
338
+ path: '/',
339
+ method: 'POST',
340
+ headers: {
341
+ 'content-type': 'application/json'
342
+ },
343
+ body: JSON.stringify({ message: 'Hello' })
344
+ }, {
345
+ onConnect: () => {
346
+ console.log('Connected!')
347
+ },
348
+ onError: (error) => {
349
+ console.error(error)
350
+ },
351
+ onHeaders: (statusCode, headers) => {
352
+ console.log(`onHeaders | statusCode: ${statusCode} | headers: ${headers}`)
353
+ },
354
+ onData: (chunk) => {
355
+ console.log('onData: chunk received')
356
+ data.push(chunk)
357
+ },
358
+ onComplete: (trailers) => {
359
+ console.log(`onComplete | trailers: ${trailers}`)
360
+ const res = Buffer.concat(data).toString('utf8')
361
+ console.log(`Response Data: ${res}`)
362
+ client.close()
363
+ server.close()
364
+ }
365
+ })
366
+ ```
367
+
368
+ ### `Dispatcher.pipeline(options, handler)`
369
+
370
+ For easy use with [stream.pipeline](https://nodejs.org/api/stream.html#stream_stream_pipeline_source_transforms_destination_callback). The `handler` argument should return a `Readable` from which the result will be read. Usually it should just return the `body` argument unless some kind of transformation needs to be performed based on e.g. `headers` or `statusCode`. The `handler` should validate the response and save any required state. If there is an error, it should be thrown. The function returns a `Duplex` which writes to the request and reads from the response.
371
+
372
+ Arguments:
373
+
374
+ * **options** `PipelineOptions`
375
+ * **handler** `(data: PipelineHandlerData) => stream.Readable`
376
+
377
+ Returns: `stream.Duplex`
378
+
379
+ #### Parameter: PipelineOptions
380
+
381
+ Extends: [`RequestOptions`](#parameter-requestoptions)
382
+
383
+ * **objectMode** `boolean` (optional) - Default: `false` - Set to `true` if the `handler` will return an object stream.
384
+
385
+ #### Parameter: PipelineHandlerData
386
+
387
+ * **statusCode** `number`
388
+ * **headers** `Record<string, string | string[] | undefined>`
389
+ * **opaque** `unknown`
390
+ * **body** `stream.Readable`
391
+ * **context** `object`
392
+ * **onInfo** `({statusCode: number, headers: Record<string, string | string[]>}) => void | null` (optional) - Default: `null` - Callback collecting all the info headers (HTTP 100-199) received.
393
+
394
+ #### Example 1 - Pipeline Echo
395
+
396
+ ```js
397
+ import { Readable, Writable, PassThrough, pipeline } from 'stream'
398
+ import { createServer } from 'http'
399
+ import { Client } from 'undici'
400
+ import { once } from 'events'
375
401
 
376
402
  const server = createServer((request, response) => {
377
403
  request.pipe(response)
@@ -390,7 +416,10 @@ pipeline(
390
416
  this.push(null)
391
417
  }
392
418
  }),
393
- client.pipeline({ path: '/', method: 'GET' }, ({ statusCode, headers, body }) => {
419
+ client.pipeline({
420
+ path: '/',
421
+ method: 'GET'
422
+ }, ({ statusCode, headers, body }) => {
394
423
  console.log(`response received ${statusCode}`)
395
424
  console.log('headers', headers)
396
425
  return pipeline(body, new PassThrough(), () => {})
@@ -409,81 +438,78 @@ pipeline(
409
438
  if (error) {
410
439
  console.error(error)
411
440
  }
441
+
412
442
  client.close()
413
443
  server.close()
414
444
  }
415
445
  )
416
446
  ```
417
447
 
418
- ### `dispatcher.request(options[, callback])`
419
-
420
- <!-- YAML
421
- added: v4.0.0
422
- -->
423
-
424
- * `options` {Object} Accepts every field of [`dispatcher.dispatch()`][]'s
425
- `options`, plus:
426
- * `opaque` {any} A value passed through to the returned response data.
427
- **Default:** `null`.
428
- * `signal` {AbortSignal|EventEmitter|null} A signal used to abort the request.
429
- **Default:** `null`.
430
- * `onInfo` {Function|null} Invoked for each informational (1xx) response
431
- received. **Default:** `null`.
432
- * `info` {Object}
433
- * `statusCode` {number}
434
- * `headers` {Object}
435
- * `responseHeaders` {string|null} Set to `'raw'` to return the response headers
436
- as a raw array. **Default:** `null`.
437
- * `highWaterMark` {number} The high water mark of the response body stream.
438
- **Default:** `65536` (64 KiB).
439
- * `callback` {Function} (optional) Invoked when the response is received.
440
- * `error` {Error|null}
441
- * `data` {Object}
442
- * `statusCode` {number}
443
- * `statusText` {string} The status message, e.g. `'OK'` or `'Not Found'`.
444
- * `headers` {Object} The response headers. All keys are lower-cased.
445
- * `body` {Readable} The response body, which also implements the
446
- [body mixin][] from the Fetch Standard.
447
- * `trailers` {Object} Starts out empty and is mutated to contain the trailers
448
- after `body` emits `'end'`.
449
- * `opaque` {any} The `opaque` value passed in `options`.
450
- * `context` {Object}
451
- * Returns: {Promise} A `Promise` is returned only when `callback` is omitted. It
452
- resolves with the `data` object described above.
453
-
454
- Performs an HTTP request. `options.method` must not be `'CONNECT'`.
455
-
456
- Non-idempotent requests are not pipelined, to avoid indirect failures. Idempotent
457
- requests are automatically retried if they fail due to an indirect failure from
458
- the request at the head of the pipeline; this does not apply to idempotent
459
- requests with a stream request body. All response bodies must always be fully
460
- consumed or destroyed.
461
-
462
- The `body` exposes the following [body mixin][] methods and properties:
463
- [`.arrayBuffer()`][], [`.blob()`][], [`.bytes()`][], [`.json()`][],
464
- [`.text()`][], `body`, and `bodyUsed`. A body cannot be consumed twice; for
465
- example, calling `text()` after `json()` throws a `TypeError`. The body also
466
- provides `dump({ limit })`, which discards up to `limit` bytes (default
467
- `131072`) without destroying the socket.
468
-
469
- > [!WARNING]
470
- > The `arrayBuffer()`, `blob()`, `bytes()`, `json()`, and `text()` methods buffer
471
- > the entire body in memory before returning. Where applicable, they also decode
472
- > or parse the payload and retain that representation in memory. Calling these
473
- > methods therefore means trusting that the body is small enough to fit in the
474
- > available memory. Do not use them for bodies received from untrusted or
475
- > user-controlled sources. Instead, process `body` as a `Readable` stream and
476
- > enforce an application-specific size limit.
477
-
478
- The body is always a `Readable`, even when empty. Deserializing an empty body
479
- with `json()` throws. To guard against this, verify the status code is not `204`
480
- and the `content-type` header starts with `application/json` before calling
481
- `json()`.
482
-
483
- ```mjs
484
- import { createServer } from 'node:http'
448
+ ### `Dispatcher.request(options[, callback])`
449
+
450
+ Performs a HTTP request.
451
+
452
+ Non-idempotent requests will not be pipelined in order
453
+ to avoid indirect failures.
454
+
455
+ Idempotent requests will be automatically retried if
456
+ they fail due to indirect failure from the request
457
+ at the head of the pipeline. This does not apply to
458
+ idempotent requests with a stream request body.
459
+
460
+ All response bodies must always be fully consumed or destroyed.
461
+
462
+ Arguments:
463
+
464
+ * **options** `RequestOptions`
465
+ * **callback** `(error: Error | null, data: ResponseData) => void` (optional)
466
+
467
+ Returns: `void | Promise<ResponseData>` - Only returns a `Promise` if no `callback` argument was passed.
468
+
469
+ #### Parameter: `RequestOptions`
470
+
471
+ Extends: [`DispatchOptions`](#parameter-dispatchoptions)
472
+
473
+ * **opaque** `unknown` (optional) - Default: `null` - Used for passing through context to `ResponseData`.
474
+ * **signal** `AbortSignal | events.EventEmitter | null` (optional) - Default: `null`.
475
+ * **onInfo** `({statusCode: number, headers: Record<string, string | string[]>}) => void | null` (optional) - Default: `null` - Callback collecting all the info headers (HTTP 100-199) received.
476
+
477
+ The `RequestOptions.method` property should not be value `'CONNECT'`.
478
+
479
+ #### Parameter: `ResponseData`
480
+
481
+ * **statusCode** `number`
482
+ * **headers** `Record<string, string | string[]>` - Note that all header keys are lower-cased, e. g. `content-type`.
483
+ * **body** `stream.Readable` which also implements [the body mixin from the Fetch Standard](https://fetch.spec.whatwg.org/#body-mixin).
484
+ * **trailers** `Record<string, string>` - This object starts out
485
+ as empty and will be mutated to contain trailers after `body` has emitted `'end'`.
486
+ * **opaque** `unknown`
487
+ * **context** `object`
488
+
489
+ `body` contains the following additional [body mixin](https://fetch.spec.whatwg.org/#body-mixin) methods and properties:
490
+
491
+ * [`.arrayBuffer()`](https://fetch.spec.whatwg.org/#dom-body-arraybuffer)
492
+ * [`.blob()`](https://fetch.spec.whatwg.org/#dom-body-blob)
493
+ * [`.bytes()`](https://fetch.spec.whatwg.org/#dom-body-bytes)
494
+ * [`.json()`](https://fetch.spec.whatwg.org/#dom-body-json)
495
+ * [`.text()`](https://fetch.spec.whatwg.org/#dom-body-text)
496
+ * `body`
497
+ * `bodyUsed`
498
+
499
+ `body` can not be consumed twice. For example, calling `text()` after `json()` throws `TypeError`.
500
+
501
+ `body` contains the following additional extensions:
502
+
503
+ - `dump({ limit: Integer })`, dump the response by reading up to `limit` bytes without killing the socket (optional) - Default: 262144.
504
+
505
+ Note that body will still be a `Readable` even if it is empty, but attempting to deserialize it with `json()` will result in an exception. Recommended way to ensure there is a body to deserialize is to check if status code is not 204, and `content-type` header starts with `application/json`.
506
+
507
+ #### Example 1 - Basic GET Request
508
+
509
+ ```js
510
+ import { createServer } from 'http'
485
511
  import { Client } from 'undici'
486
- import { once } from 'node:events'
512
+ import { once } from 'events'
487
513
 
488
514
  const server = createServer((request, response) => {
489
515
  response.end('Hello, World!')
@@ -494,7 +520,7 @@ await once(server, 'listening')
494
520
  const client = new Client(`http://localhost:${server.address().port}`)
495
521
 
496
522
  try {
497
- const { body, headers, statusCode, statusText, trailers } = await client.request({
523
+ const { body, headers, statusCode, trailers } = await client.request({
498
524
  path: '/',
499
525
  method: 'GET'
500
526
  })
@@ -502,7 +528,6 @@ try {
502
528
  console.log('headers', headers)
503
529
  body.setEncoding('utf8')
504
530
  body.on('data', console.log)
505
- body.on('error', console.error)
506
531
  body.on('end', () => {
507
532
  console.log('trailers', trailers)
508
533
  })
@@ -514,74 +539,132 @@ try {
514
539
  }
515
540
  ```
516
541
 
517
- A request can be aborted with an `AbortSignal`, with any `EventEmitter` that
518
- emits an `'abort'` event, or by destroying the response body:
542
+ #### Example 2 - Aborting a request
543
+
544
+ > Node.js v15+ is required to run this example
519
545
 
520
- ```mjs
546
+ ```js
547
+ import { createServer } from 'http'
521
548
  import { Client } from 'undici'
549
+ import { once } from 'events'
522
550
 
523
- const client = new Client('http://localhost:3000')
551
+ const server = createServer((request, response) => {
552
+ response.end('Hello, World!')
553
+ }).listen()
554
+
555
+ await once(server, 'listening')
556
+
557
+ const client = new Client(`http://localhost:${server.address().port}`)
524
558
  const abortController = new AbortController()
525
559
 
526
560
  try {
527
- client.request({ path: '/', method: 'GET', signal: abortController.signal })
561
+ client.request({
562
+ path: '/',
563
+ method: 'GET',
564
+ signal: abortController.signal
565
+ })
528
566
  } catch (error) {
529
- console.error(error) // RequestAbortedError
567
+ console.error(error) // should print an RequestAbortedError
568
+ client.close()
569
+ server.close()
530
570
  }
531
571
 
532
572
  abortController.abort()
533
573
  ```
534
574
 
535
- When the response body is conditionally read, always fully consume it otherwise:
575
+ Alternatively, any `EventEmitter` that emits an `'abort'` event may be used as an abort controller:
576
+
577
+ ```js
578
+ import { createServer } from 'http'
579
+ import { Client } from 'undici'
580
+ import EventEmitter, { once } from 'events'
581
+
582
+ const server = createServer((request, response) => {
583
+ response.end('Hello, World!')
584
+ }).listen()
536
585
 
537
- ```mjs
538
- const { body, statusCode } = await client.request({ path: '/', method: 'GET' })
586
+ await once(server, 'listening')
539
587
 
540
- if (statusCode === 200) {
541
- return await body.arrayBuffer()
588
+ const client = new Client(`http://localhost:${server.address().port}`)
589
+ const ee = new EventEmitter()
590
+
591
+ try {
592
+ client.request({
593
+ path: '/',
594
+ method: 'GET',
595
+ signal: ee
596
+ })
597
+ } catch (error) {
598
+ console.error(error) // should print an RequestAbortedError
599
+ client.close()
600
+ server.close()
542
601
  }
543
602
 
544
- await body.dump()
603
+ ee.emit('abort')
604
+ ```
545
605
 
546
- return null
606
+ Destroying the request or response body will have the same effect.
607
+
608
+ ```js
609
+ import { createServer } from 'http'
610
+ import { Client } from 'undici'
611
+ import { once } from 'events'
612
+
613
+ const server = createServer((request, response) => {
614
+ response.end('Hello, World!')
615
+ }).listen()
616
+
617
+ await once(server, 'listening')
618
+
619
+ const client = new Client(`http://localhost:${server.address().port}`)
620
+
621
+ try {
622
+ const { body } = await client.request({
623
+ path: '/',
624
+ method: 'GET'
625
+ })
626
+ body.destroy()
627
+ } catch (error) {
628
+ console.error(error) // should print an RequestAbortedError
629
+ client.close()
630
+ server.close()
631
+ }
547
632
  ```
548
633
 
549
- ### `dispatcher.stream(options, factory[, callback])`
634
+ ### `Dispatcher.stream(options, factory[, callback])`
635
+
636
+ A faster version of `Dispatcher.request`. This method expects the second argument `factory` to return a [`stream.Writable`](https://nodejs.org/api/stream.html#stream_class_stream_writable) stream which the response will be written to. This improves performance by avoiding creating an intermediate [`stream.Readable`](https://nodejs.org/api/stream.html#stream_readable_streams) stream when the user expects to directly pipe the response body to a [`stream.Writable`](https://nodejs.org/api/stream.html#stream_class_stream_writable) stream.
637
+
638
+ As demonstrated in [Example 1 - Basic GET stream request](#example-1---basic-get-stream-request), it is recommended to use the `option.opaque` property to avoid creating a closure for the `factory` method. This pattern works well with Node.js Web Frameworks such as [Fastify](https://fastify.io). See [Example 2 - Stream to Fastify Response](#example-2---stream-to-fastify-response) for more details.
639
+
640
+ Arguments:
641
+
642
+ * **options** `RequestOptions`
643
+ * **factory** `(data: StreamFactoryData) => stream.Writable`
644
+ * **callback** `(error: Error | null, data: StreamData) => void` (optional)
645
+
646
+ Returns: `void | Promise<StreamData>` - Only returns a `Promise` if no `callback` argument was passed
550
647
 
551
- <!-- YAML
552
- added: v4.0.0
553
- -->
648
+ #### Parameter: `StreamFactoryData`
554
649
 
555
- * `options` {Object} Accepts the same fields as [`dispatcher.request()`][]'s
556
- `options`.
557
- * `factory` {Function} Returns the `Writable` to which the response is written.
558
- * `data` {Object}
559
- * `statusCode` {number}
560
- * `headers` {Object} The response headers.
561
- * `opaque` {any} The `opaque` value passed in `options`.
562
- * `context` {Object}
563
- * Returns: {Writable}
564
- * `callback` {Function} (optional) Invoked when the request has completed.
565
- * `error` {Error|null}
566
- * `data` {Object}
567
- * `opaque` {any} The `opaque` value passed in `options`.
568
- * `trailers` {Object}
569
- * Returns: {Promise} A `Promise` is returned only when `callback` is omitted. It
570
- resolves with the `data` object described above.
650
+ * **statusCode** `number`
651
+ * **headers** `Record<string, string | string[] | undefined>`
652
+ * **opaque** `unknown`
653
+ * **onInfo** `({statusCode: number, headers: Record<string, string | string[]>}) => void | null` (optional) - Default: `null` - Callback collecting all the info headers (HTTP 100-199) received.
571
654
 
572
- A faster version of [`dispatcher.request()`][]. The `factory` returns a
573
- [`Writable`][] to which the response is written, which avoids creating an
574
- intermediate [`Readable`][] when the caller intends to pipe the response body
575
- directly to a `Writable`.
655
+ #### Parameter: `StreamData`
576
656
 
577
- Use `options.opaque` to avoid creating a closure for the `factory` method. This
578
- pattern works well with Node.js web frameworks such as [Fastify][].
657
+ * **opaque** `unknown`
658
+ * **trailers** `Record<string, string>`
659
+ * **context** `object`
579
660
 
580
- ```mjs
581
- import { createServer } from 'node:http'
661
+ #### Example 1 - Basic GET stream request
662
+
663
+ ```js
664
+ import { createServer } from 'http'
582
665
  import { Client } from 'undici'
583
- import { once } from 'node:events'
584
- import { Writable } from 'node:stream'
666
+ import { once } from 'events'
667
+ import { Writable } from 'stream'
585
668
 
586
669
  const server = createServer((request, response) => {
587
670
  response.end('Hello, World!')
@@ -618,38 +701,95 @@ try {
618
701
  }
619
702
  ```
620
703
 
621
- ### `dispatcher.upgrade(options[, callback])`
622
-
623
- <!-- YAML
624
- added: v4.0.0
625
- -->
626
-
627
- * `options` {Object}
628
- * `path` {string} The request path.
629
- * `method` {string} The HTTP method. **Default:** `'GET'`.
630
- * `headers` {UndiciHeaders} Request headers. **Default:** `null`.
631
- * `protocol` {string} A comma-separated list of protocols, in descending
632
- preference order. **Default:** `'Websocket'`.
633
- * `signal` {AbortSignal|EventEmitter|null} A signal used to abort the request.
634
- **Default:** `null`.
635
- * `responseHeaders` {string|null} Set to `'raw'` to return the response headers
636
- as a raw array. **Default:** `null`.
637
- * `callback` {Function} (optional) Invoked when the upgrade completes.
638
- * `error` {Error|null}
639
- * `data` {Object}
640
- * `headers` {Object} The response headers.
641
- * `socket` {Duplex} The upgraded socket.
642
- * `opaque` {any}
643
- * Returns: {Promise} A `Promise` is returned only when `callback` is omitted. It
644
- resolves with the `data` object described above.
645
-
646
- Upgrades to a different protocol. See
647
- [MDN: Protocol upgrade mechanism][] for more details.
648
-
649
- ```mjs
650
- import { createServer } from 'node:http'
704
+ #### Example 2 - Stream to Fastify Response
705
+
706
+ In this example, a (fake) request is made to the fastify server using `fastify.inject()`. This request then executes the fastify route handler which makes a subsequent request to the raw Node.js http server using `undici.dispatcher.stream()`. The fastify response is passed to the `opaque` option so that undici can tap into the underlying writable stream using `response.raw`. This methodology demonstrates how one could use undici and fastify together to create fast-as-possible requests from one backend server to another.
707
+
708
+ ```js
709
+ import { createServer } from 'http'
710
+ import { Client } from 'undici'
711
+ import { once } from 'events'
712
+ import fastify from 'fastify'
713
+
714
+ const nodeServer = createServer((request, response) => {
715
+ response.end('Hello, World! From Node.js HTTP Server')
716
+ }).listen()
717
+
718
+ await once(nodeServer, 'listening')
719
+
720
+ console.log('Node Server listening')
721
+
722
+ const nodeServerUndiciClient = new Client(`http://localhost:${nodeServer.address().port}`)
723
+
724
+ const fastifyServer = fastify()
725
+
726
+ fastifyServer.route({
727
+ url: '/',
728
+ method: 'GET',
729
+ handler: (request, response) => {
730
+ nodeServerUndiciClient.stream({
731
+ path: '/',
732
+ method: 'GET',
733
+ opaque: response
734
+ }, ({ opaque }) => opaque.raw)
735
+ }
736
+ })
737
+
738
+ await fastifyServer.listen()
739
+
740
+ console.log('Fastify Server listening')
741
+
742
+ const fastifyServerUndiciClient = new Client(`http://localhost:${fastifyServer.server.address().port}`)
743
+
744
+ try {
745
+ const { statusCode, body } = await fastifyServerUndiciClient.request({
746
+ path: '/',
747
+ method: 'GET'
748
+ })
749
+
750
+ console.log(`response received ${statusCode}`)
751
+ body.setEncoding('utf8')
752
+ body.on('data', console.log)
753
+
754
+ nodeServerUndiciClient.close()
755
+ fastifyServerUndiciClient.close()
756
+ fastifyServer.close()
757
+ nodeServer.close()
758
+ } catch (error) { }
759
+ ```
760
+
761
+ ### `Dispatcher.upgrade(options[, callback])`
762
+
763
+ Upgrade to a different protocol. Visit [MDN - HTTP - Protocol upgrade mechanism](https://developer.mozilla.org/en-US/docs/Web/HTTP/Protocol_upgrade_mechanism) for more details.
764
+
765
+ Arguments:
766
+
767
+ * **options** `UpgradeOptions`
768
+
769
+ * **callback** `(error: Error | null, data: UpgradeData) => void` (optional)
770
+
771
+ Returns: `void | Promise<UpgradeData>` - Only returns a `Promise` if no `callback` argument was passed
772
+
773
+ #### Parameter: `UpgradeOptions`
774
+
775
+ * **path** `string`
776
+ * **method** `string` (optional) - Default: `'GET'`
777
+ * **headers** `UndiciHeaders` (optional) - Default: `null`
778
+ * **protocol** `string` (optional) - Default: `'Websocket'` - A string of comma separated protocols, in descending preference order.
779
+ * **signal** `AbortSignal | EventEmitter | null` (optional) - Default: `null`
780
+
781
+ #### Parameter: `UpgradeData`
782
+
783
+ * **headers** `http.IncomingHeaders`
784
+ * **socket** `stream.Duplex`
785
+ * **opaque** `unknown`
786
+
787
+ #### Example 1 - Basic Upgrade Request
788
+
789
+ ```js
790
+ import { createServer } from 'http'
651
791
  import { Client } from 'undici'
652
- import { once } from 'node:events'
792
+ import { once } from 'events'
653
793
 
654
794
  const server = createServer((request, response) => {
655
795
  response.statusCode = 101
@@ -663,7 +803,9 @@ await once(server, 'listening')
663
803
  const client = new Client(`http://localhost:${server.address().port}`)
664
804
 
665
805
  try {
666
- const { headers, socket } = await client.upgrade({ path: '/' })
806
+ const { headers, socket } = await client.upgrade({
807
+ path: '/',
808
+ })
667
809
  socket.on('end', () => {
668
810
  console.log(`upgrade: ${headers.upgrade}`) // upgrade: Websocket
669
811
  client.close()
@@ -677,62 +819,90 @@ try {
677
819
  }
678
820
  ```
679
821
 
680
- ### `dispatcher.compose(interceptors[, interceptor])`
822
+ ### `Dispatcher.compose(interceptors[, interceptor])`
681
823
 
682
- <!-- YAML
683
- added: v6.9.0
684
- -->
824
+ Compose a new dispatcher from the current dispatcher and the given interceptors.
685
825
 
686
- * `interceptors` {Array|Function} An array of interceptor functions, or the first
687
- of several interceptors passed as separate arguments.
688
- * `...interceptor` {Function} Additional interceptors when passed as separate
689
- arguments.
690
- * Returns: {Dispatcher} A new dispatcher that applies the interceptors over the
691
- current dispatcher's [`dispatch()`][] method.
826
+ > _Notes_:
827
+ > - The order of the interceptors matters. The first interceptor will be the first to be called.
828
+ > - It is important to note that the `interceptor` function should return a function that follows the `Dispatcher.dispatch` signature.
829
+ > - Any fork of the chain of `interceptors` can lead to unexpected results.
692
830
 
693
- Composes a new dispatcher from the current dispatcher and the given
694
- interceptors. Each interceptor is a function that takes a `dispatch` method and
695
- returns a `dispatch`-like function with the same signature
696
- (`(options, handler)`).
831
+ Arguments:
697
832
 
698
- The order of the interceptors matters: the last interceptor in the chain is the
699
- first to be called. Forking the chain of interceptors can lead to unexpected
700
- results.
833
+ * **interceptors** `Interceptor[interceptor[]]`: It is an array of `Interceptor` functions passed as only argument, or several interceptors passed as separate arguments.
701
834
 
702
- ```text
703
- compose([interceptor1, interceptor2, interceptor3])
835
+ Returns: `Dispatcher`.
704
836
 
705
- Request flow:
706
- Request -> interceptor3 -> interceptor2 -> interceptor1 -> dispatcher.dispatch
707
- (called first) (called second) (called last)
708
- ```
837
+ #### Parameter: `Interceptor`
838
+
839
+ A function that takes a `dispatch` method and returns a `dispatch`-like function.
709
840
 
710
- ```mjs
711
- import { Client, RedirectHandler } from 'undici'
841
+ #### Example 1 - Basic Compose
842
+
843
+ ```js
844
+ const { Client, RedirectHandler } = require('undici')
712
845
 
713
846
  const redirectInterceptor = dispatch => {
714
- return (opts, handler) => {
715
- const { maxRedirections } = opts
847
+ return (opts, handler) => {
848
+ const { maxRedirections } = opts
716
849
 
717
- if (!maxRedirections) {
718
- return dispatch(opts, handler)
719
- }
850
+ if (!maxRedirections) {
851
+ return dispatch(opts, handler)
852
+ }
720
853
 
721
- const redirectHandler = new RedirectHandler(dispatch, maxRedirections, opts, handler)
722
- opts = { ...opts, maxRedirections: 0 } // Stop the sub-dispatcher from also redirecting.
723
- return dispatch(opts, redirectHandler)
724
- }
854
+ const redirectHandler = new RedirectHandler(
855
+ dispatch,
856
+ maxRedirections,
857
+ opts,
858
+ handler
859
+ )
860
+ opts = { ...opts, maxRedirections: 0 } // Stop sub dispatcher from also redirecting.
861
+ return dispatch(opts, redirectHandler)
862
+ }
725
863
  }
726
864
 
727
- const client = new Client('http://localhost:3000').compose(redirectInterceptor)
865
+ const client = new Client('http://localhost:3000')
866
+ .compose(redirectInterceptor)
728
867
 
729
868
  await client.request({ path: '/', method: 'GET' })
730
869
  ```
731
870
 
732
- Interceptors can be chained by calling `compose()` repeatedly:
871
+ #### Example 2 - Chained Compose
733
872
 
734
- ```mjs
735
- import { Client } from 'undici'
873
+ ```js
874
+ const { Client, RedirectHandler, RetryHandler } = require('undici')
875
+
876
+ const redirectInterceptor = dispatch => {
877
+ return (opts, handler) => {
878
+ const { maxRedirections } = opts
879
+
880
+ if (!maxRedirections) {
881
+ return dispatch(opts, handler)
882
+ }
883
+
884
+ const redirectHandler = new RedirectHandler(
885
+ dispatch,
886
+ maxRedirections,
887
+ opts,
888
+ handler
889
+ )
890
+ opts = { ...opts, maxRedirections: 0 }
891
+ return dispatch(opts, redirectHandler)
892
+ }
893
+ }
894
+
895
+ const retryInterceptor = dispatch => {
896
+ return function retryInterceptor (opts, handler) {
897
+ return dispatch(
898
+ opts,
899
+ new RetryHandler(opts, {
900
+ handler,
901
+ dispatch
902
+ })
903
+ )
904
+ }
905
+ }
736
906
 
737
907
  const client = new Client('http://localhost:3000')
738
908
  .compose(redirectInterceptor)
@@ -741,96 +911,437 @@ const client = new Client('http://localhost:3000')
741
911
  await client.request({ path: '/', method: 'GET' })
742
912
  ```
743
913
 
744
- For the full list of built-in interceptors provided by undici, see [Interceptors](Interceptors.md).
745
- For an example of a custom interceptor that wraps handler callbacks, see
746
- [Custom interceptors](Interceptors.md#custom-interceptors).
914
+ #### Pre-built interceptors
747
915
 
748
- ### Event: `'connect'`
916
+ ##### `redirect`
917
+
918
+ The `redirect` interceptor allows you to customize the way your dispatcher handles redirects.
919
+
920
+ It accepts the same arguments as the [`RedirectHandler` constructor](./RedirectHandler.md).
921
+
922
+ **Example - Basic Redirect Interceptor**
923
+
924
+ ```js
925
+ const { Client, interceptors } = require("undici");
926
+ const { redirect } = interceptors;
927
+
928
+ const client = new Client("http://example.com").compose(
929
+ redirect({ maxRedirections: 3, throwOnMaxRedirects: true })
930
+ );
931
+ client.request({ path: "/" })
932
+ ```
933
+
934
+ ##### `retry`
935
+
936
+ The `retry` interceptor allows you to customize the way your dispatcher handles retries.
937
+
938
+ It accepts the same arguments as the [`RetryHandler` constructor](./RetryHandler.md).
939
+
940
+ **Example - Basic Redirect Interceptor**
941
+
942
+ ```js
943
+ const { Client, interceptors } = require("undici");
944
+ const { retry } = interceptors;
945
+
946
+ const client = new Client("http://example.com").compose(
947
+ retry({
948
+ maxRetries: 3,
949
+ minTimeout: 1000,
950
+ maxTimeout: 10000,
951
+ timeoutFactor: 2,
952
+ retryAfter: true,
953
+ })
954
+ );
955
+ ```
956
+
957
+ ##### `dump`
958
+
959
+ The `dump` interceptor enables you to dump the response body from a request upon a given limit.
960
+
961
+ **Options**
962
+ - `maxSize` - The maximum size (in bytes) of the response body to dump. If the size of the request's body exceeds this value then the connection will be closed. Default: `1048576`.
963
+
964
+ > The `Dispatcher#options` also gets extended with the options `dumpMaxSize`, `abortOnDumped`, and `waitForTrailers` which can be used to configure the interceptor at a request-per-request basis.
965
+
966
+ **Example - Basic Dump Interceptor**
967
+
968
+ ```js
969
+ const { Client, interceptors } = require("undici");
970
+ const { dump } = interceptors;
971
+
972
+ const client = new Client("http://example.com").compose(
973
+ dump({
974
+ maxSize: 1024,
975
+ })
976
+ );
977
+
978
+ // or
979
+ client.dispatch(
980
+ {
981
+ path: "/",
982
+ method: "GET",
983
+ dumpMaxSize: 1024,
984
+ },
985
+ handler
986
+ );
987
+ ```
988
+
989
+ ##### `dns`
990
+
991
+ The `dns` interceptor enables you to cache DNS lookups for a given duration, per origin.
992
+
993
+ >It is well suited for scenarios where you want to cache DNS lookups to avoid the overhead of resolving the same domain multiple times
994
+
995
+ **Options**
996
+ - `maxTTL` - The maximum time-to-live (in milliseconds) of the DNS cache. It should be a positive integer. Default: `10000`.
997
+ - Set `0` to disable TTL.
998
+ - `maxItems` - The maximum number of items to cache. It should be a positive integer. Default: `Infinity`.
999
+ - `dualStack` - Whether to resolve both IPv4 and IPv6 addresses. Default: `true`.
1000
+ - It will also attempt a happy-eyeballs-like approach to connect to the available addresses in case of a connection failure.
1001
+ - `affinity` - Whether to use IPv4 or IPv6 addresses. Default: `4`.
1002
+ - It can be either `'4` or `6`.
1003
+ - It will only take effect if `dualStack` is `false`.
1004
+ - `lookup: (hostname: string, options: LookupOptions, callback: (err: NodeJS.ErrnoException | null, addresses: DNSInterceptorRecord[]) => void) => void` - Custom lookup function. Default: `dns.lookup`.
1005
+ - For more info see [dns.lookup](https://nodejs.org/api/dns.html#dns_dns_lookup_hostname_options_callback).
1006
+ - `pick: (origin: URL, records: DNSInterceptorRecords, affinity: 4 | 6) => DNSInterceptorRecord` - Custom pick function. Default: `RoundRobin`.
1007
+ - The function should return a single record from the records array.
1008
+ - By default a simplified version of Round Robin is used.
1009
+ - The `records` property can be mutated to store the state of the balancing algorithm.
1010
+
1011
+ > The `Dispatcher#options` also gets extended with the options `dns.affinity`, `dns.dualStack`, `dns.lookup` and `dns.pick` which can be used to configure the interceptor at a request-per-request basis.
749
1012
 
750
- <!-- YAML
751
- added: v4.0.0
752
- -->
753
1013
 
754
- * `origin` {URL}
755
- * `targets` {Array<Dispatcher>}
1014
+ **DNSInterceptorRecord**
1015
+ It represents a DNS record.
1016
+ - `family` - (`number`) The IP family of the address. It can be either `4` or `6`.
1017
+ - `address` - (`string`) The IP address.
756
1018
 
757
- Emitted when the dispatcher has connected to the origin.
1019
+ **DNSInterceptorOriginRecords**
1020
+ It represents a map of DNS IP addresses records for a single origin.
1021
+ - `4.ips` - (`DNSInterceptorRecord[] | null`) The IPv4 addresses.
1022
+ - `6.ips` - (`DNSInterceptorRecord[] | null`) The IPv6 addresses.
1023
+
1024
+ **Example - Basic DNS Interceptor**
1025
+
1026
+ ```js
1027
+ const { Client, interceptors } = require("undici");
1028
+ const { dns } = interceptors;
1029
+
1030
+ const client = new Agent().compose([
1031
+ dns({ ...opts })
1032
+ ])
1033
+
1034
+ const response = await client.request({
1035
+ origin: `http://localhost:3030`,
1036
+ ...requestOpts
1037
+ })
1038
+ ```
1039
+
1040
+ ##### `Response Error Interceptor`
1041
+
1042
+ **Introduction**
1043
+
1044
+ The Response Error Interceptor is designed to handle HTTP response errors efficiently. It intercepts responses and throws detailed errors for responses with status codes indicating failure (4xx, 5xx). This interceptor enhances error handling by providing structured error information, including response headers, data, and status codes.
1045
+
1046
+ **ResponseError Class**
1047
+
1048
+ The `ResponseError` class extends the `UndiciError` class and encapsulates detailed error information. It captures the response status code, headers, and data, providing a structured way to handle errors.
1049
+
1050
+ **Definition**
1051
+
1052
+ ```js
1053
+ class ResponseError extends UndiciError {
1054
+ constructor (message, code, { headers, data }) {
1055
+ super(message);
1056
+ this.name = 'ResponseError';
1057
+ this.message = message || 'Response error';
1058
+ this.code = 'UND_ERR_RESPONSE';
1059
+ this.statusCode = code;
1060
+ this.data = data;
1061
+ this.headers = headers;
1062
+ }
1063
+ }
1064
+ ```
1065
+
1066
+ **Interceptor Handler**
1067
+
1068
+ The interceptor's handler class extends `DecoratorHandler` and overrides methods to capture response details and handle errors based on the response status code.
1069
+
1070
+ **Methods**
1071
+
1072
+ - **onConnect**: Initializes response properties.
1073
+ - **onHeaders**: Captures headers and status code. Decodes body if content type is `application/json` or `text/plain`.
1074
+ - **onData**: Appends chunks to the body if status code indicates an error.
1075
+ - **onComplete**: Finalizes error handling, constructs a `ResponseError`, and invokes the `onError` method.
1076
+ - **onError**: Propagates errors to the handler.
1077
+
1078
+ **Definition**
1079
+
1080
+ ```js
1081
+ class Handler extends DecoratorHandler {
1082
+ // Private properties
1083
+ #handler;
1084
+ #statusCode;
1085
+ #contentType;
1086
+ #decoder;
1087
+ #headers;
1088
+ #body;
1089
+
1090
+ constructor (opts, { handler }) {
1091
+ super(handler);
1092
+ this.#handler = handler;
1093
+ }
1094
+
1095
+ onConnect (abort) {
1096
+ this.#statusCode = 0;
1097
+ this.#contentType = null;
1098
+ this.#decoder = null;
1099
+ this.#headers = null;
1100
+ this.#body = '';
1101
+ return this.#handler.onConnect(abort);
1102
+ }
1103
+
1104
+ onHeaders (statusCode, rawHeaders, resume, statusMessage, headers = parseHeaders(rawHeaders)) {
1105
+ this.#statusCode = statusCode;
1106
+ this.#headers = headers;
1107
+ this.#contentType = headers['content-type'];
1108
+
1109
+ if (this.#statusCode < 400) {
1110
+ return this.#handler.onHeaders(statusCode, rawHeaders, resume, statusMessage, headers);
1111
+ }
1112
+
1113
+ if (this.#contentType === 'application/json' || this.#contentType === 'text/plain') {
1114
+ this.#decoder = new TextDecoder('utf-8');
1115
+ }
1116
+ }
1117
+
1118
+ onData (chunk) {
1119
+ if (this.#statusCode < 400) {
1120
+ return this.#handler.onData(chunk);
1121
+ }
1122
+ this.#body += this.#decoder?.decode(chunk, { stream: true }) ?? '';
1123
+ }
1124
+
1125
+ onComplete (rawTrailers) {
1126
+ if (this.#statusCode >= 400) {
1127
+ this.#body += this.#decoder?.decode(undefined, { stream: false }) ?? '';
1128
+ if (this.#contentType === 'application/json') {
1129
+ try {
1130
+ this.#body = JSON.parse(this.#body);
1131
+ } catch {
1132
+ // Do nothing...
1133
+ }
1134
+ }
1135
+
1136
+ let err;
1137
+ const stackTraceLimit = Error.stackTraceLimit;
1138
+ Error.stackTraceLimit = 0;
1139
+ try {
1140
+ err = new ResponseError('Response Error', this.#statusCode, this.#headers, this.#body);
1141
+ } finally {
1142
+ Error.stackTraceLimit = stackTraceLimit;
1143
+ }
1144
+
1145
+ this.#handler.onError(err);
1146
+ } else {
1147
+ this.#handler.onComplete(rawTrailers);
1148
+ }
1149
+ }
1150
+
1151
+ onError (err) {
1152
+ this.#handler.onError(err);
1153
+ }
1154
+ }
1155
+
1156
+ module.exports = (dispatch) => (opts, handler) => opts.throwOnError
1157
+ ? dispatch(opts, new Handler(opts, { handler }))
1158
+ : dispatch(opts, handler);
1159
+ ```
1160
+
1161
+ **Tests**
1162
+
1163
+ Unit tests ensure the interceptor functions correctly, handling both error and non-error responses appropriately.
1164
+
1165
+ **Example Tests**
1166
+
1167
+ - **No Error if `throwOnError` is False**:
1168
+
1169
+ ```js
1170
+ test('should not error if request is not meant to throw error', async (t) => {
1171
+ const opts = { throwOnError: false };
1172
+ const handler = { onError: () => {}, onData: () => {}, onComplete: () => {} };
1173
+ const interceptor = createResponseErrorInterceptor((opts, handler) => handler.onComplete());
1174
+ assert.doesNotThrow(() => interceptor(opts, handler));
1175
+ });
1176
+ ```
1177
+
1178
+ - **Error if Status Code is in Specified Error Codes**:
1179
+
1180
+ ```js
1181
+ test('should error if request status code is in the specified error codes', async (t) => {
1182
+ const opts = { throwOnError: true, statusCodes: [500] };
1183
+ const response = { statusCode: 500 };
1184
+ let capturedError;
1185
+ const handler = {
1186
+ onError: (err) => { capturedError = err; },
1187
+ onData: () => {},
1188
+ onComplete: () => {}
1189
+ };
1190
+
1191
+ const interceptor = createResponseErrorInterceptor((opts, handler) => {
1192
+ if (opts.throwOnError && opts.statusCodes.includes(response.statusCode)) {
1193
+ handler.onError(new Error('Response Error'));
1194
+ } else {
1195
+ handler.onComplete();
1196
+ }
1197
+ });
1198
+
1199
+ interceptor({ ...opts, response }, handler);
1200
+
1201
+ await new Promise(resolve => setImmediate(resolve));
1202
+
1203
+ assert(capturedError, 'Expected error to be captured but it was not.');
1204
+ assert.strictEqual(capturedError.message, 'Response Error');
1205
+ assert.strictEqual(response.statusCode, 500);
1206
+ });
1207
+ ```
1208
+
1209
+ - **No Error if Status Code is Not in Specified Error Codes**:
1210
+
1211
+ ```js
1212
+ test('should not error if request status code is not in the specified error codes', async (t) => {
1213
+ const opts = { throwOnError: true, statusCodes: [500] };
1214
+ const response = { statusCode: 404 };
1215
+ const handler = {
1216
+ onError: () => {},
1217
+ onData: () => {},
1218
+ onComplete: () => {}
1219
+ };
1220
+
1221
+ const interceptor = createResponseErrorInterceptor((opts, handler) => {
1222
+ if (opts.throwOnError && opts.statusCodes.includes(response.statusCode)) {
1223
+ handler.onError(new Error('Response Error'));
1224
+ } else {
1225
+ handler.onComplete();
1226
+ }
1227
+ });
1228
+
1229
+ assert.doesNotThrow(() => interceptor({ ...opts, response }, handler));
1230
+ });
1231
+ ```
1232
+
1233
+ **Conclusion**
1234
+
1235
+ The Response Error Interceptor provides a robust mechanism for handling HTTP response errors by capturing detailed error information and propagating it through a structured `ResponseError` class. This enhancement improves error handling and debugging capabilities in applications using the interceptor.
1236
+
1237
+ ## Instance Events
1238
+
1239
+ ### Event: `'connect'`
1240
+
1241
+ Parameters:
1242
+
1243
+ * **origin** `URL`
1244
+ * **targets** `Array<Dispatcher>`
758
1245
 
759
1246
  ### Event: `'disconnect'`
760
1247
 
761
- <!-- YAML
762
- added: v4.0.0
763
- -->
1248
+ Parameters:
764
1249
 
765
- * `origin` {URL}
766
- * `targets` {Array<Dispatcher>}
767
- * `error` {Error}
1250
+ * **origin** `URL`
1251
+ * **targets** `Array<Dispatcher>`
1252
+ * **error** `Error`
768
1253
 
769
1254
  Emitted when the dispatcher has been disconnected from the origin.
770
1255
 
771
- For HTTP/2, this event is also emitted when the dispatcher receives a
772
- [GOAWAY frame][], with an error whose message is `HTTP/2: "GOAWAY" frame received`
773
- and whose code is `UND_ERR_INFO`. Because of the binary-framing nature of the
774
- protocol, a request may hang if a frame is received between the `HEADER` and
775
- `DATA` frames. It is recommended to handle this event and close the dispatcher to
776
- create a new HTTP/2 session.
1256
+ > **Note**: For HTTP/2, this event is also emitted when the dispatcher has received the [GOAWAY Frame](https://webconcepts.info/concepts/http2-frame-type/0x7) with an Error with the message `HTTP/2: "GOAWAY" frame received` and the code `UND_ERR_INFO`.
1257
+ > Due to nature of the protocol of using binary frames, it is possible that requests gets hanging as a frame can be received between the `HEADER` and `DATA` frames.
1258
+ > It is recommended to handle this event and close the dispatcher to create a new HTTP/2 session.
777
1259
 
778
1260
  ### Event: `'connectionError'`
779
1261
 
780
- <!-- YAML
781
- added: v4.0.0
782
- -->
1262
+ Parameters:
783
1263
 
784
- * `origin` {URL}
785
- * `targets` {Array<Dispatcher>}
786
- * `error` {Error}
1264
+ * **origin** `URL`
1265
+ * **targets** `Array<Dispatcher>`
1266
+ * **error** `Error`
787
1267
 
788
- Emitted when the dispatcher fails to connect to the origin.
1268
+ Emitted when dispatcher fails to connect to
1269
+ origin.
789
1270
 
790
1271
  ### Event: `'drain'`
791
1272
 
792
- <!-- YAML
793
- added: v4.0.0
794
- -->
795
-
796
- * `origin` {URL}
797
-
798
- Emitted when the dispatcher is no longer busy and further [`dispatch()`][] calls
799
- can make progress.
800
-
801
- ## Pre-built interceptors
802
-
803
- For the full reference of built-in interceptors (`dump`, `retry`, `redirect`,
804
- `decompress`, `responseError`, `dns`, `cache`, `deduplicate`) and their options,
805
- see [Interceptors](Interceptors.md).
806
-
807
- [Fastify]: https://fastify.dev
808
- [GOAWAY frame]: https://webconcepts.info/concepts/http2-frame-type/0x7
809
- [HTTP `CONNECT`]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/CONNECT
810
- [MDN: Protocol upgrade mechanism]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Protocol_upgrade_mechanism
811
- [`.arrayBuffer()`]: https://fetch.spec.whatwg.org/#dom-body-arraybuffer
812
- [`.blob()`]: https://fetch.spec.whatwg.org/#dom-body-blob
813
- [`.bytes()`]: https://fetch.spec.whatwg.org/#dom-body-bytes
814
- [`.json()`]: https://fetch.spec.whatwg.org/#dom-body-json
815
- [`.text()`]: https://fetch.spec.whatwg.org/#dom-body-text
816
- [`'drain'`]: #event-drain
817
- [`Agent`]: Agent.md#class-agent
818
- [`BalancedPool`]: BalancedPool.md#class-balancedpool
819
- [`Client`]: Client.md#class-client
820
- [`EventEmitter`]: https://nodejs.org/api/events.html#class-eventemitter
821
- [`Pool`]: Pool.md#class-pool
822
- [`Readable`]: https://nodejs.org/api/stream.html#class-streamreadable
823
- [`Writable`]: https://nodejs.org/api/stream.html#class-streamwritable
824
- [`close()`]: #dispatcherclosecallback
825
- [`connect()`]: #dispatcherconnectoptions-callback
826
- [`destroy()`]: #dispatcherdestroyerror-callback
827
- [`dispatch()`]: #dispatcherdispatchoptions-handler
828
- [`dispatcher.compose()`]: #dispatchercomposeinterceptors-interceptor
829
- [`dispatcher.dispatch()`]: #dispatcherdispatchoptions-handler
830
- [`dispatcher.request()`]: #dispatcherrequestoptions-callback
831
- [`pipeline()`]: #dispatcherpipelineoptions-handler
832
- [`request()`]: #dispatcherrequestoptions-callback
833
- [`stream()`]: #dispatcherstreamoptions-factory-callback
834
- [`stream.pipeline()`]: https://nodejs.org/api/stream.html#streampipelinesource-transforms-destination-options
835
- [`upgrade()`]: #dispatcherupgradeoptions-callback
836
- [body mixin]: https://fetch.spec.whatwg.org/#body-mixin
1273
+ Parameters:
1274
+
1275
+ * **origin** `URL`
1276
+
1277
+ Emitted when dispatcher is no longer busy.
1278
+
1279
+ ## Parameter: `UndiciHeaders`
1280
+
1281
+ * `Record<string, string | string[] | undefined> | string[] | Iterable<[string, string | string[] | undefined]> | null`
1282
+
1283
+ Header arguments such as `options.headers` in [`Client.dispatch`](Client.md#clientdispatchoptions-handlers) can be specified in three forms:
1284
+ * As an object specified by the `Record<string, string | string[] | undefined>` (`IncomingHttpHeaders`) type.
1285
+ * As an array of strings. An array representation of a header list must have an even length, or an `InvalidArgumentError` will be thrown.
1286
+ * As an iterable that can encompass `Headers`, `Map`, or a custom iterator returning key-value pairs.
1287
+ Keys are lowercase and values are not modified.
1288
+
1289
+ Response headers will derive a `host` from the `url` of the [Client](Client.md#class-client) instance if no `host` header was previously specified.
1290
+
1291
+ ### Example 1 - Object
1292
+
1293
+ ```js
1294
+ {
1295
+ 'content-length': '123',
1296
+ 'content-type': 'text/plain',
1297
+ connection: 'keep-alive',
1298
+ host: 'mysite.com',
1299
+ accept: '*/*'
1300
+ }
1301
+ ```
1302
+
1303
+ ### Example 2 - Array
1304
+
1305
+ ```js
1306
+ [
1307
+ 'content-length', '123',
1308
+ 'content-type', 'text/plain',
1309
+ 'connection', 'keep-alive',
1310
+ 'host', 'mysite.com',
1311
+ 'accept', '*/*'
1312
+ ]
1313
+ ```
1314
+
1315
+ ### Example 3 - Iterable
1316
+
1317
+ ```js
1318
+ new Headers({
1319
+ 'content-length': '123',
1320
+ 'content-type': 'text/plain',
1321
+ connection: 'keep-alive',
1322
+ host: 'mysite.com',
1323
+ accept: '*/*'
1324
+ })
1325
+ ```
1326
+ or
1327
+ ```js
1328
+ new Map([
1329
+ ['content-length', '123'],
1330
+ ['content-type', 'text/plain'],
1331
+ ['connection', 'keep-alive'],
1332
+ ['host', 'mysite.com'],
1333
+ ['accept', '*/*']
1334
+ ])
1335
+ ```
1336
+ or
1337
+ ```js
1338
+ {
1339
+ *[Symbol.iterator] () {
1340
+ yield ['content-length', '123']
1341
+ yield ['content-type', 'text/plain']
1342
+ yield ['connection', 'keep-alive']
1343
+ yield ['host', 'mysite.com']
1344
+ yield ['accept', '*/*']
1345
+ }
1346
+ }
1347
+ ```