Route.d.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { HTTPMethod } from './utils/constants.js';
  2. import { RouteHandler, RouteHandlerObject, RouteMatchCallback } from 'workbox-core/types.js';
  3. import './_version.js';
  4. /**
  5. * A `Route` consists of a pair of callback functions, "match" and "handler".
  6. * The "match" callback determine if a route should be used to "handle" a
  7. * request by returning a non-falsy value if it can. The "handler" callback
  8. * is called when there is a match and should return a Promise that resolves
  9. * to a `Response`.
  10. *
  11. * @memberof workbox-routing
  12. */
  13. declare class Route {
  14. handler: RouteHandlerObject;
  15. match: RouteMatchCallback;
  16. method: HTTPMethod;
  17. catchHandler?: RouteHandlerObject;
  18. /**
  19. * Constructor for Route class.
  20. *
  21. * @param {workbox-routing~matchCallback} match
  22. * A callback function that determines whether the route matches a given
  23. * `fetch` event by returning a non-falsy value.
  24. * @param {workbox-routing~handlerCallback} handler A callback
  25. * function that returns a Promise resolving to a Response.
  26. * @param {string} [method='GET'] The HTTP method to match the Route
  27. * against.
  28. */
  29. constructor(match: RouteMatchCallback, handler: RouteHandler, method?: HTTPMethod);
  30. /**
  31. *
  32. * @param {workbox-routing-handlerCallback} handler A callback
  33. * function that returns a Promise resolving to a Response
  34. */
  35. setCatchHandler(handler: RouteHandler): void;
  36. }
  37. export { Route };