NetworkOnly.d.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { RouteHandlerObject, RouteHandlerCallbackOptions, WorkboxPlugin } from 'workbox-core/types.js';
  2. import './_version.js';
  3. interface NetworkFirstOptions {
  4. plugins?: WorkboxPlugin[];
  5. fetchOptions?: RequestInit;
  6. }
  7. /**
  8. * An implementation of a
  9. * [network-only]{@link https://developers.google.com/web/fundamentals/instant-and-offline/offline-cookbook/#network-only}
  10. * request strategy.
  11. *
  12. * This class is useful if you want to take advantage of any
  13. * [Workbox plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}.
  14. *
  15. * If the network request fails, this will throw a `WorkboxError` exception.
  16. *
  17. * @memberof module:workbox-strategies
  18. */
  19. declare class NetworkOnly implements RouteHandlerObject {
  20. private readonly _plugins;
  21. private readonly _fetchOptions?;
  22. /**
  23. * @param {Object} options
  24. * @param {string} options.cacheName Cache name to store and retrieve
  25. * requests. Defaults to cache names provided by
  26. * [workbox-core]{@link module:workbox-core.cacheNames}.
  27. * @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}
  28. * to use in conjunction with this caching strategy.
  29. * @param {Object} options.fetchOptions Values passed along to the
  30. * [`init`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)
  31. * of all fetch() requests made by this strategy.
  32. */
  33. constructor(options?: NetworkFirstOptions);
  34. /**
  35. * This method will perform a request strategy and follows an API that
  36. * will work with the
  37. * [Workbox Router]{@link module:workbox-routing.Router}.
  38. *
  39. * @param {Object} options
  40. * @param {Request|string} options.request The request to run this strategy for.
  41. * @param {Event} [options.event] The event that triggered the request.
  42. * @return {Promise<Response>}
  43. */
  44. handle({ event, request }: RouteHandlerCallbackOptions): Promise<Response>;
  45. }
  46. export { NetworkOnly };