StorableRequest.d.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { MapLikeObject } from 'workbox-core/types.js';
  2. import '../_version.js';
  3. export interface RequestData extends MapLikeObject {
  4. url: string;
  5. headers: MapLikeObject;
  6. body?: ArrayBuffer;
  7. }
  8. /**
  9. * A class to make it easier to serialize and de-serialize requests so they
  10. * can be stored in IndexedDB.
  11. *
  12. * Most developers will not need to access this class directly;
  13. * it is exposed for advanced use cases.
  14. */
  15. declare class StorableRequest {
  16. private readonly _requestData;
  17. /**
  18. * Converts a Request object to a plain object that can be structured
  19. * cloned or JSON-stringified.
  20. *
  21. * @param {Request} request
  22. * @return {Promise<StorableRequest>}
  23. */
  24. static fromRequest(request: Request): Promise<StorableRequest>;
  25. /**
  26. * Accepts an object of request data that can be used to construct a
  27. * `Request` but can also be stored in IndexedDB.
  28. *
  29. * @param {Object} requestData An object of request data that includes the
  30. * `url` plus any relevant properties of
  31. * [requestInit]{@link https://fetch.spec.whatwg.org/#requestinit}.
  32. */
  33. constructor(requestData: RequestData);
  34. /**
  35. * Returns a deep clone of the instances `_requestData` object.
  36. *
  37. * @return {Object}
  38. */
  39. toObject(): RequestData;
  40. /**
  41. * Converts this instance to a Request.
  42. *
  43. * @return {Request}
  44. */
  45. toRequest(): Request;
  46. /**
  47. * Creates and returns a deep clone of the instance.
  48. *
  49. * @return {StorableRequest}
  50. */
  51. clone(): StorableRequest;
  52. }
  53. export { StorableRequest };