UNPKG

854 BTypeScriptView Raw
1/// <reference lib="webworker" />
2
3import type { FetchHandler } from 'worktop';
4
5export const Cache: Cache;
6export function save(event: FetchEvent, res: Response, request?: Request | string): Response;
7export function lookup(event: FetchEvent, request?: Request | string): Promise<Response | void>;
8export function isCacheable(res: Response): boolean;
9
10export type ResponseHandler = (event: FetchEvent) => Promise<Response>;
11
12/**
13 * Attempt to `lookup` the `event.request`, otherwise run the `handler` and attempt to `save` the Response.
14 * @param {ResponseHandler} handler
15 */
16export function reply(handler: ResponseHandler): FetchHandler;
17
18/**
19 * Assign the `handler` to the "fetch" event.
20 * @note Your `handler` will be wrapped by `reply` automatically.
21 * @param {ResponseHandler} handler
22 */
23export function listen(handler: ResponseHandler): void;