strategy.d.ts 1.2 KB

123456789101112131415161718192021222324
  1. import { RouteHandlerCallback, RouteHandlerCallbackOptions } from 'workbox-core/types.js';
  2. import { StreamSource } from './_types.js';
  3. import './_version.js';
  4. interface StreamsHandlerCallback {
  5. ({ url, request, event, params }: RouteHandlerCallbackOptions): Promise<StreamSource> | StreamSource;
  6. }
  7. /**
  8. * A shortcut to create a strategy that could be dropped-in to Workbox's router.
  9. *
  10. * On browsers that do not support constructing new `ReadableStream`s, this
  11. * strategy will automatically wait for all the `sourceFunctions` to complete,
  12. * and create a final response that concatenates their values together.
  13. *
  14. * @param {Array<function({event, request, url, params})>} sourceFunctions
  15. * An array of functions similar to {@link module:workbox-routing~handlerCallback}
  16. * but that instead return a {@link module:workbox-streams.StreamSource} (or a
  17. * Promise which resolves to one).
  18. * @param {HeadersInit} [headersInit] If there's no `Content-Type` specified,
  19. * `'text/html'` will be used by default.
  20. * @return {module:workbox-routing~handlerCallback}
  21. * @memberof module:workbox-streams
  22. */
  23. declare function strategy(sourceFunctions: StreamsHandlerCallback[], headersInit: HeadersInit): RouteHandlerCallback;
  24. export { strategy };