api.d.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { URL, UrlObject } from 'url'
  2. import { Duplex } from 'stream'
  3. import Dispatcher from './dispatcher'
  4. /** Performs an HTTP request. */
  5. declare function request<TOpaque = null> (
  6. url: string | URL | UrlObject,
  7. options?: { dispatcher?: Dispatcher } & Omit<Dispatcher.RequestOptions<TOpaque>, 'origin' | 'path' | 'method'> & Partial<Pick<Dispatcher.RequestOptions, 'method'>>,
  8. ): Promise<Dispatcher.ResponseData<TOpaque>>
  9. /** A faster version of `request`. */
  10. declare function stream<TOpaque = null> (
  11. url: string | URL | UrlObject,
  12. options: { dispatcher?: Dispatcher } & Omit<Dispatcher.RequestOptions<TOpaque>, 'origin' | 'path'>,
  13. factory: Dispatcher.StreamFactory<TOpaque>
  14. ): Promise<Dispatcher.StreamData<TOpaque>>
  15. /** For easy use with `stream.pipeline`. */
  16. declare function pipeline<TOpaque = null> (
  17. url: string | URL | UrlObject,
  18. options: { dispatcher?: Dispatcher } & Omit<Dispatcher.PipelineOptions<TOpaque>, 'origin' | 'path'>,
  19. handler: Dispatcher.PipelineHandler<TOpaque>
  20. ): Duplex
  21. /** Starts two-way communications with the requested resource. */
  22. declare function connect<TOpaque = null> (
  23. url: string | URL | UrlObject,
  24. options?: { dispatcher?: Dispatcher } & Omit<Dispatcher.ConnectOptions<TOpaque>, 'origin' | 'path'>
  25. ): Promise<Dispatcher.ConnectData<TOpaque>>
  26. /** Upgrade to a different protocol. */
  27. declare function upgrade (
  28. url: string | URL | UrlObject,
  29. options?: { dispatcher?: Dispatcher } & Omit<Dispatcher.UpgradeOptions, 'origin' | 'path'>
  30. ): Promise<Dispatcher.UpgradeData>
  31. export {
  32. request,
  33. stream,
  34. pipeline,
  35. connect,
  36. upgrade
  37. }