index.d.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /// <reference types="node" />
  2. /// <reference types="node" />
  3. import { Readable } from 'stream';
  4. type Protocol<T> = T extends `${infer Protocol}:${infer _}` ? Protocol : never;
  5. export type GetUriProtocol<T> = (parsed: URL, opts?: T) => Promise<Readable>;
  6. export declare const protocols: {
  7. data: GetUriProtocol<import("./data").DataOptions>;
  8. file: GetUriProtocol<import("./file").FileOptions>;
  9. ftp: GetUriProtocol<import("./ftp").FTPOptions>;
  10. http: GetUriProtocol<import("./http").HttpOptions>;
  11. https: GetUriProtocol<import("./http").HttpOptions>;
  12. };
  13. export type Protocols = typeof protocols;
  14. export type ProtocolsOptions = {
  15. [P in keyof Protocols]: NonNullable<Parameters<Protocols[P]>[1]>;
  16. };
  17. export type ProtocolOpts<T> = {
  18. [P in keyof ProtocolsOptions]: Protocol<T> extends P ? ProtocolsOptions[P] : never;
  19. }[keyof Protocols];
  20. export declare function isValidProtocol(p: string): p is keyof Protocols;
  21. /**
  22. * Async function that returns a `stream.Readable` instance that will output
  23. * the contents of the given URI.
  24. *
  25. * For caching purposes, you can pass in a `stream` instance from a previous
  26. * `getUri()` call as a `cache: stream` option, and if the destination has
  27. * not changed since the last time the endpoint was retreived then the callback
  28. * will be invoked with an Error object with `code` set to "ENOTMODIFIED" and
  29. * `null` for the "stream" instance argument. In this case, you can skip
  30. * retreiving the file again and continue to use the previous payload.
  31. *
  32. * @param {String} uri URI to retrieve
  33. * @param {Object} opts optional "options" object
  34. * @api public
  35. */
  36. export declare function getUri<Uri extends string>(uri: Uri | URL, opts?: ProtocolOpts<Uri>): Promise<Readable>;
  37. export {};