serwist 9.0.2 → 9.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/NavigationRoute.d.ts +2 -2
- package/dist/PrecacheRoute.d.ts +2 -3
- package/dist/PrecacheRoute.d.ts.map +1 -1
- package/dist/RegExpRoute.d.ts +2 -2
- package/dist/Route.d.ts +4 -4
- package/dist/Serwist.d.ts +19 -19
- package/dist/chunks/printInstallDetails.js +6 -10
- package/dist/copyResponse.d.ts.map +1 -1
- package/dist/legacy/PrecacheController.d.ts +1 -1
- package/dist/legacy/PrecacheFallbackPlugin.d.ts +6 -7
- package/dist/legacy/PrecacheFallbackPlugin.d.ts.map +1 -1
- package/dist/legacy/PrecacheRoute.d.ts +3 -3
- package/dist/legacy/Router.d.ts +23 -23
- package/dist/legacy/addRoute.d.ts +6 -8
- package/dist/legacy/addRoute.d.ts.map +1 -1
- package/dist/legacy/createHandlerBoundToURL.d.ts +5 -6
- package/dist/legacy/createHandlerBoundToURL.d.ts.map +1 -1
- package/dist/legacy/fallbacks.d.ts +3 -3
- package/dist/legacy/handlePrecaching.d.ts +3 -3
- package/dist/legacy/initializeGoogleAnalytics.d.ts +1 -1
- package/dist/legacy/installSerwist.d.ts +4 -4
- package/dist/legacy/matchPrecache.d.ts +4 -4
- package/dist/legacy/matchPrecache.d.ts.map +1 -1
- package/dist/legacy/precache.d.ts +2 -2
- package/dist/legacy/precache.d.ts.map +1 -1
- package/dist/legacy/precacheAndRoute.d.ts +3 -4
- package/dist/legacy/precacheAndRoute.d.ts.map +1 -1
- package/dist/legacy/registerRoute.d.ts +6 -6
- package/dist/legacy/registerRoute.d.ts.map +1 -1
- package/dist/legacy/registerRuntimeCaching.d.ts +1 -1
- package/dist/legacy/setCatchHandler.d.ts +2 -2
- package/dist/legacy/setDefaultHandler.d.ts +3 -3
- package/dist/legacy/singletonPrecacheController.d.ts +7 -7
- package/dist/legacy/singletonRouter.d.ts +9 -9
- package/dist/legacy/unregisterRoute.d.ts +1 -1
- package/dist/legacy/unregisterRoute.d.ts.map +1 -1
- package/dist/lib/backgroundSync/BackgroundSyncPlugin.d.ts +3 -3
- package/dist/lib/backgroundSync/BackgroundSyncQueue.d.ts +1 -1
- package/dist/lib/backgroundSync/StorableRequest.d.ts +1 -1
- package/dist/lib/broadcastUpdate/BroadcastCacheUpdate.d.ts +1 -2
- package/dist/lib/broadcastUpdate/BroadcastCacheUpdate.d.ts.map +1 -1
- package/dist/lib/broadcastUpdate/BroadcastUpdatePlugin.d.ts +4 -7
- package/dist/lib/broadcastUpdate/BroadcastUpdatePlugin.d.ts.map +1 -1
- package/dist/lib/broadcastUpdate/types.d.ts +2 -1
- package/dist/lib/broadcastUpdate/types.d.ts.map +1 -1
- package/dist/lib/cacheableResponse/CacheableResponse.d.ts +6 -6
- package/dist/lib/cacheableResponse/CacheableResponsePlugin.d.ts +2 -2
- package/dist/lib/expiration/CacheExpiration.d.ts +2 -2
- package/dist/lib/expiration/ExpirationPlugin.d.ts +11 -11
- package/dist/lib/expiration/ExpirationPlugin.d.ts.map +1 -1
- package/dist/lib/precaching/PrecacheFallbackPlugin.d.ts +4 -4
- package/dist/lib/rangeRequests/RangeRequestsPlugin.d.ts +3 -4
- package/dist/lib/rangeRequests/RangeRequestsPlugin.d.ts.map +1 -1
- package/dist/lib/rangeRequests/createPartialResponse.d.ts +7 -7
- package/dist/lib/rangeRequests/createPartialResponse.d.ts.map +1 -1
- package/dist/lib/rangeRequests/utils/parseRangeHeader.d.ts +2 -2
- package/dist/lib/strategies/CacheFirst.d.ts +1 -1
- package/dist/lib/strategies/CacheOnly.d.ts +1 -1
- package/dist/lib/strategies/NetworkFirst.d.ts +1 -1
- package/dist/lib/strategies/NetworkOnly.d.ts +1 -1
- package/dist/lib/strategies/PrecacheStrategy.d.ts +3 -3
- package/dist/lib/strategies/PrecacheStrategy.d.ts.map +1 -1
- package/dist/lib/strategies/StaleWhileRevalidate.d.ts +1 -1
- package/dist/lib/strategies/Strategy.d.ts +7 -7
- package/dist/lib/strategies/StrategyHandler.d.ts +12 -13
- package/dist/lib/strategies/StrategyHandler.d.ts.map +1 -1
- package/dist/types.d.ts +37 -36
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/cacheNames.d.ts +1 -1
- package/dist/utils/cacheNames.d.ts.map +1 -1
- package/dist/utils/canConstructResponseFromBodyStream.d.ts +2 -2
- package/dist/utils/deleteOutdatedCaches.d.ts.map +1 -1
- package/dist/utils/executeQuotaErrorCallbacks.d.ts.map +1 -1
- package/dist/utils/parseRoute.d.ts +8 -8
- package/dist/utils/waitUntil.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/NavigationRoute.ts +2 -2
- package/src/PrecacheRoute.ts +2 -3
- package/src/RegExpRoute.ts +2 -2
- package/src/Route.ts +4 -4
- package/src/Serwist.ts +19 -19
- package/src/legacy/PrecacheController.ts +1 -1
- package/src/legacy/PrecacheFallbackPlugin.ts +6 -7
- package/src/legacy/PrecacheRoute.ts +3 -3
- package/src/legacy/Router.ts +23 -23
- package/src/legacy/addRoute.ts +6 -8
- package/src/legacy/createHandlerBoundToURL.ts +6 -6
- package/src/legacy/fallbacks.ts +3 -3
- package/src/legacy/handlePrecaching.ts +3 -3
- package/src/legacy/initializeGoogleAnalytics.ts +1 -1
- package/src/legacy/installSerwist.ts +4 -4
- package/src/legacy/matchPrecache.ts +5 -4
- package/src/legacy/precache.ts +4 -2
- package/src/legacy/precacheAndRoute.ts +3 -4
- package/src/legacy/registerRoute.ts +8 -7
- package/src/legacy/registerRuntimeCaching.ts +1 -1
- package/src/legacy/setCatchHandler.ts +2 -2
- package/src/legacy/setDefaultHandler.ts +3 -3
- package/src/legacy/singletonPrecacheController.ts +7 -7
- package/src/legacy/singletonRouter.ts +9 -9
- package/src/legacy/unregisterRoute.ts +2 -1
- package/src/lib/backgroundSync/BackgroundSyncPlugin.ts +3 -3
- package/src/lib/backgroundSync/BackgroundSyncQueue.ts +1 -1
- package/src/lib/backgroundSync/StorableRequest.ts +1 -1
- package/src/lib/broadcastUpdate/BroadcastCacheUpdate.ts +1 -2
- package/src/lib/broadcastUpdate/BroadcastUpdatePlugin.ts +4 -7
- package/src/lib/broadcastUpdate/types.ts +2 -1
- package/src/lib/cacheableResponse/CacheableResponse.ts +6 -6
- package/src/lib/cacheableResponse/CacheableResponsePlugin.ts +2 -2
- package/src/lib/expiration/CacheExpiration.ts +2 -2
- package/src/lib/expiration/ExpirationPlugin.ts +12 -11
- package/src/lib/precaching/PrecacheFallbackPlugin.ts +4 -4
- package/src/lib/rangeRequests/RangeRequestsPlugin.ts +3 -4
- package/src/lib/rangeRequests/createPartialResponse.ts +7 -7
- package/src/lib/rangeRequests/utils/parseRangeHeader.ts +2 -2
- package/src/lib/strategies/CacheFirst.ts +1 -1
- package/src/lib/strategies/CacheOnly.ts +1 -1
- package/src/lib/strategies/NetworkFirst.ts +1 -1
- package/src/lib/strategies/NetworkOnly.ts +1 -1
- package/src/lib/strategies/PrecacheStrategy.ts +4 -3
- package/src/lib/strategies/StaleWhileRevalidate.ts +1 -1
- package/src/lib/strategies/Strategy.ts +7 -7
- package/src/lib/strategies/StrategyHandler.ts +21 -25
- package/src/types.ts +39 -36
- package/src/utils/cacheNames.ts +2 -1
- package/src/utils/canConstructResponseFromBodyStream.ts +2 -2
- package/src/utils/parseRoute.ts +8 -8
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { HandlerCallbackOptions, MapLikeObject, SerwistPlugin, SerwistPluginCallbackParam } from "../../types.js";
|
|
2
2
|
import type { Strategy } from "./Strategy.js";
|
|
3
3
|
/**
|
|
4
|
-
* A class created every time a
|
|
5
|
-
*
|
|
4
|
+
* A class created every time a {@linkcode Strategy} instance calls {@linkcode Strategy.handle} or
|
|
5
|
+
* {@linkcode Strategy.handleAll} that wraps all fetch and cache actions around plugin callbacks
|
|
6
6
|
* and keeps track of when the strategy is "done" (i.e. when all added `event.waitUntil()` promises
|
|
7
7
|
* have resolved).
|
|
8
8
|
*/
|
|
@@ -20,15 +20,16 @@ export declare class StrategyHandler {
|
|
|
20
20
|
* A `URL` instance of `request.url` (if passed to the strategy's
|
|
21
21
|
* `handle()` or `handleAll()` method).
|
|
22
22
|
* Note: the `url` param will be present if the strategy is invoked
|
|
23
|
-
* from a
|
|
23
|
+
* from a {@linkcode Route} object.
|
|
24
24
|
*/
|
|
25
25
|
url?: URL;
|
|
26
26
|
/**
|
|
27
27
|
* Some additional params (if passed to the strategy's
|
|
28
28
|
* `handle()` or `handleAll()` method).
|
|
29
|
+
*
|
|
29
30
|
* Note: the `params` param will be present if the strategy is invoked
|
|
30
|
-
* from a
|
|
31
|
-
* (it will be that value).
|
|
31
|
+
* from a {@linkcode Route} object and that route's matcher returned a truthy
|
|
32
|
+
* value (it will be that value).
|
|
32
33
|
*/
|
|
33
34
|
params?: string[] | MapLikeObject;
|
|
34
35
|
private _cacheKeys;
|
|
@@ -53,7 +54,7 @@ export declare class StrategyHandler {
|
|
|
53
54
|
/**
|
|
54
55
|
* Fetches a given request (and invokes any applicable plugin callback
|
|
55
56
|
* methods), taking the `fetchOptions` (for non-navigation requests) and
|
|
56
|
-
* `plugins` provided to the
|
|
57
|
+
* `plugins` provided to the {@linkcode Strategy} object into account.
|
|
57
58
|
*
|
|
58
59
|
* The following plugin lifecycle methods are invoked when using this method:
|
|
59
60
|
* - `requestWillFetch()`
|
|
@@ -90,7 +91,7 @@ export declare class StrategyHandler {
|
|
|
90
91
|
/**
|
|
91
92
|
* Puts a request/response pair into the cache (and invokes any applicable
|
|
92
93
|
* plugin callback method) using the `cacheName` and `plugins` provided to
|
|
93
|
-
* the
|
|
94
|
+
* the {@linkcode Strategy} object.
|
|
94
95
|
*
|
|
95
96
|
* The following plugin lifecycle methods are invoked when using this method:
|
|
96
97
|
* - `cacheKeyWillBeUsed`
|
|
@@ -99,12 +100,12 @@ export declare class StrategyHandler {
|
|
|
99
100
|
*
|
|
100
101
|
* @param key The request or URL to use as the cache key.
|
|
101
102
|
* @param response The response to cache.
|
|
102
|
-
* @returns `false` if a cacheWillUpdate caused the response
|
|
103
|
+
* @returns `false` if a `cacheWillUpdate` caused the response to
|
|
103
104
|
* not be cached, and `true` otherwise.
|
|
104
105
|
*/
|
|
105
106
|
cachePut(key: RequestInfo, response: Response): Promise<boolean>;
|
|
106
107
|
/**
|
|
107
|
-
* Checks the `plugins` provided to the
|
|
108
|
+
* Checks the `plugins` provided to the {@linkcode Strategy} object for `cacheKeyWillBeUsed`
|
|
108
109
|
* callbacks and executes found callbacks in sequence. The final `Request`
|
|
109
110
|
* object returned by the last plugin is treated as the cache key for cache
|
|
110
111
|
* reads and/or writes. If no `cacheKeyWillBeUsed` plugin callbacks have
|
|
@@ -129,7 +130,7 @@ export declare class StrategyHandler {
|
|
|
129
130
|
*
|
|
130
131
|
* Note: since this method runs all plugins, it's not suitable for cases
|
|
131
132
|
* where the return value of a callback needs to be applied prior to calling
|
|
132
|
-
* the next callback. See
|
|
133
|
+
* the next callback. See {@linkcode StrategyHandler.iterateCallbacks} for how to handle that case.
|
|
133
134
|
*
|
|
134
135
|
* @param name The name of the callback to run within each plugin.
|
|
135
136
|
* @param param The object to pass as the first (and only) param when executing each callback. This object will be merged with the
|
|
@@ -148,9 +149,7 @@ export declare class StrategyHandler {
|
|
|
148
149
|
* [extend lifetime promises](https://w3c.github.io/ServiceWorker/#extendableevent-extend-lifetime-promises)
|
|
149
150
|
* of the event event associated with the request being handled (usually a `FetchEvent`).
|
|
150
151
|
*
|
|
151
|
-
* Note: you can await
|
|
152
|
-
* `serwist/strategies.StrategyHandler.doneWaiting`
|
|
153
|
-
* to know when all added promises have settled.
|
|
152
|
+
* Note: you can await {@linkcode StrategyHandler.doneWaiting} to know when all added promises have settled.
|
|
154
153
|
*
|
|
155
154
|
* @param promise A promise to add to the extend lifetime promises of
|
|
156
155
|
* the event that triggered the request.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StrategyHandler.d.ts","sourceRoot":"","sources":["../../../src/lib/strategies/StrategyHandler.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,sBAAsB,EAAE,aAAa,EAAE,aAAa,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAC;AASvH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"StrategyHandler.d.ts","sourceRoot":"","sources":["../../../src/lib/strategies/StrategyHandler.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,sBAAsB,EAAE,aAAa,EAAE,aAAa,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAC;AASvH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAO9C;;;;;GAKG;AACH,qBAAa,eAAe;IAC1B;;OAEG;IACI,KAAK,EAAE,eAAe,CAAC;IAC9B;;;OAGG;IACI,OAAO,EAAE,OAAO,CAAC;IACxB;;;;;OAKG;IACI,GAAG,CAAC,EAAE,GAAG,CAAC;IACjB;;;;;;;OAOG;IACI,MAAM,CAAC,EAAE,MAAM,EAAE,GAAG,aAAa,CAAC;IAEzC,OAAO,CAAC,UAAU,CAA+B;IACjD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAW;IACrC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAgB;IACjD,OAAO,CAAC,QAAQ,CAAC,uBAAuB,CAAiB;IACzD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAkB;IAC3C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAoC;IAEpE;;;;;;;;;OASG;gBAED,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,sBAAsB,GAAG;QAChC,OAAO,EAAE,sBAAsB,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC;KACtD;IAsCH;;;;;;;;;;;;OAYG;IACG,KAAK,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC;IAyElD;;;;;;;;OAQG;IACG,gBAAgB,CAAC,K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4,12 @@ export interface MapLikeObject {
|
|
|
4
4
|
[key: string]: any;
|
|
5
5
|
}
|
|
6
6
|
/**
|
|
7
|
-
* Using a plain
|
|
7
|
+
* Using a plain {@linkcode MapLikeObject} for now, but could extend/restrict this
|
|
8
8
|
* in the future.
|
|
9
9
|
*/
|
|
10
10
|
export type PluginState = MapLikeObject;
|
|
11
11
|
/**
|
|
12
|
-
* Options passed to a
|
|
12
|
+
* Options passed to a {@linkcode RouteMatchCallback} function.
|
|
13
13
|
*/
|
|
14
14
|
export interface RouteMatchCallbackOptions {
|
|
15
15
|
event: ExtendableEvent;
|
|
@@ -18,19 +18,21 @@ export interface RouteMatchCallbackOptions {
|
|
|
18
18
|
url: URL;
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
-
* The
|
|
22
|
-
* particular URL and request.
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
21
|
+
* The match callback is used to determine if a route should apply for a
|
|
22
|
+
* particular URL and request.
|
|
23
|
+
*
|
|
24
|
+
* When matching occurs in response to a `fetch` event from the client, the `event`
|
|
25
|
+
* object is also supplied. However, since the match callback can be invoked outside
|
|
26
|
+
* of a `fetch` event, matching logic should not assume the `event` object will always
|
|
27
|
+
* be available.
|
|
28
|
+
*
|
|
26
29
|
* If the match callback returns a truthy value, the matching route's
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* `options.params` argument.
|
|
30
|
+
* handler will be invoked immediately. If the value returned is a non-empty array
|
|
31
|
+
* or object, that value will be the handler's `options.params` argument.
|
|
30
32
|
*/
|
|
31
33
|
export type RouteMatchCallback = (options: RouteMatchCallbackOptions) => any;
|
|
32
34
|
/**
|
|
33
|
-
* Options passed to a
|
|
35
|
+
* Options passed to a {@linkcode RouteHandlerCallback} function.
|
|
34
36
|
*/
|
|
35
37
|
export interface RouteHandlerCallbackOptions {
|
|
36
38
|
/**
|
|
@@ -45,7 +47,7 @@ export interface RouteHandlerCallbackOptions {
|
|
|
45
47
|
params?: string[] | MapLikeObject;
|
|
46
48
|
}
|
|
47
49
|
/**
|
|
48
|
-
* Options passed to a
|
|
50
|
+
* Options passed to a {@linkcode ManualHandlerCallback} function.
|
|
49
51
|
*/
|
|
50
52
|
export interface ManualHandlerCallbackOptions {
|
|
51
53
|
/**
|
|
@@ -58,41 +60,40 @@ export interface ManualHandlerCallbackOptions {
|
|
|
58
60
|
request: Request | string;
|
|
59
61
|
url?: never;
|
|
60
62
|
/**
|
|
61
|
-
* The return value from
|
|
63
|
+
* The return value from {@linkcode RouteMatchCallback} (if applicable).
|
|
62
64
|
*/
|
|
63
65
|
params?: never;
|
|
64
66
|
}
|
|
65
67
|
export type HandlerCallbackOptions = RouteHandlerCallbackOptions | ManualHandlerCallbackOptions;
|
|
66
68
|
/**
|
|
67
|
-
* The "handler" callback is invoked whenever a
|
|
68
|
-
*
|
|
69
|
-
* return a
|
|
69
|
+
* The "handler" callback is invoked whenever a request is matched to a
|
|
70
|
+
* {@linkcode Route} via its {@linkcode RouteMatchCallback} This handler
|
|
71
|
+
* callback should return a promise that resolves to a response.
|
|
70
72
|
*
|
|
71
|
-
* If a non-empty array or object is returned by the
|
|
73
|
+
* If a non-empty array or object is returned by the matcher, it
|
|
72
74
|
* will be passed in as this handler's `options.params` argument.
|
|
73
75
|
*/
|
|
74
76
|
export type RouteHandlerCallback = (options: RouteHandlerCallbackOptions) => Promise<Response>;
|
|
75
77
|
/**
|
|
76
|
-
* The "handler" callback is invoked whenever a
|
|
77
|
-
*
|
|
78
|
-
* return a
|
|
78
|
+
* The "handler" callback is invoked whenever a request is matched to a
|
|
79
|
+
* {@linkcode Route} via its {@linkcode RouteMatchCallback} This handler
|
|
80
|
+
* callback should return a promise that resolves to a response.
|
|
79
81
|
*
|
|
80
|
-
* If a non-empty array or object is returned by the
|
|
82
|
+
* If a non-empty array or object is returned by the matcher, it
|
|
81
83
|
* will be passed in as this handler's `options.params` argument.
|
|
82
84
|
*/
|
|
83
85
|
export type ManualHandlerCallback = (options: ManualHandlerCallbackOptions) => Promise<Response>;
|
|
84
86
|
/**
|
|
85
|
-
* An object with a `handle` method of type
|
|
87
|
+
* An object with a `handle` method of type {@linkcode RouteHandlerCallback}.
|
|
86
88
|
*
|
|
87
|
-
* A
|
|
88
|
-
* function or this
|
|
89
|
-
* is it can be extended (as is done by the `serwist/strategies` package).
|
|
89
|
+
* A {@linkcode Route} object can be created with either an `RouteHandlerCallback`
|
|
90
|
+
* function or this {@linkcode RouteHandler} object.
|
|
90
91
|
*/
|
|
91
92
|
export interface RouteHandlerObject {
|
|
92
93
|
handle: RouteHandlerCallback;
|
|
93
94
|
}
|
|
94
95
|
/**
|
|
95
|
-
* Either a
|
|
96
|
+
* Either a {@linkcode RouteHandlerCallback} or a {@linkcode RouteHandlerObject}.
|
|
96
97
|
* Most APIs that accept route handlers take either.
|
|
97
98
|
*/
|
|
98
99
|
export type RouteHandler = RouteHandlerCallback | RouteHandlerObject;
|
|
@@ -109,11 +110,11 @@ export interface CacheDidUpdateCallbackParam {
|
|
|
109
110
|
*/
|
|
110
111
|
cacheName: string;
|
|
111
112
|
/**
|
|
112
|
-
*
|
|
113
|
+
* The possibly updated response.
|
|
113
114
|
*/
|
|
114
115
|
newResponse: Response;
|
|
115
116
|
/**
|
|
116
|
-
* The
|
|
117
|
+
* The request for the cached entry.
|
|
117
118
|
*/
|
|
118
119
|
request: Request;
|
|
119
120
|
/**
|
|
@@ -121,7 +122,7 @@ export interface CacheDidUpdateCallbackParam {
|
|
|
121
122
|
*/
|
|
122
123
|
event: ExtendableEvent;
|
|
123
124
|
/**
|
|
124
|
-
*
|
|
125
|
+
* The previous cached response.
|
|
125
126
|
*/
|
|
126
127
|
oldResponse?: Response | null;
|
|
127
128
|
state?: PluginState;
|
|
@@ -261,19 +262,19 @@ export interface RuntimeCaching {
|
|
|
261
262
|
*/
|
|
262
263
|
method?: HTTPMethod;
|
|
263
264
|
/**
|
|
264
|
-
*
|
|
265
|
-
* generate a response for any
|
|
266
|
-
* URLs. If multiple
|
|
267
|
-
*
|
|
265
|
+
* The match callback determines whether the configured handler will be used to
|
|
266
|
+
* generate a response for any request that doesn't match one of the precached
|
|
267
|
+
* URLs. If multiple routes are defined, then the first one to match the request
|
|
268
|
+
* will be the one that responds.
|
|
268
269
|
*
|
|
269
270
|
* This value directly maps to the first parameter passed to
|
|
270
|
-
*
|
|
271
|
-
*
|
|
271
|
+
* {@linkcode Serwist.registerRoute}. It's recommended to use a
|
|
272
|
+
* {@linkcode RouteMatchCallback} function for greatest flexibility.
|
|
272
273
|
*/
|
|
273
274
|
matcher: RegExp | string | RouteMatchCallback;
|
|
274
275
|
/**
|
|
275
276
|
* This determines how the runtime route will generate a response. It
|
|
276
|
-
* can be a
|
|
277
|
+
* can be a {@linkcode RouteHandler} callback function with custom
|
|
277
278
|
* response logic.
|
|
278
279
|
*/
|
|
279
280
|
handler: RouteHandler;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAIjD,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAE7C,MAAM,WAAW,aAAa;IAC5B,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,aAAa,CAAC;AAExC;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,KAAK,EAAE,eAAe,CAAC;IACvB,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,OAAO,CAAC;IACpB,GAAG,EAAE,GAAG,CAAC;CAC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S,CAAC,EAAE,OAAO,CAAC;IACpB;;;OAGG;IACH,eAAe,CAAC,EAAE,eAAe,CAAC;CACnC;AAED,MAAM,MAAM,eAAe,GAAG,CAAC,EAAE,GAAG,EAAE,EAAE;IAAE,GAAG,EAAE,GAAG,CAAA;CAAE,KAAK,GAAG,EAAE,CAAC"}
|
|
@@ -23,7 +23,7 @@ export interface PartialCacheNameDetails {
|
|
|
23
23
|
*/
|
|
24
24
|
runtime?: string;
|
|
25
25
|
/**
|
|
26
|
-
* The cache name to use for
|
|
26
|
+
* The cache name to use for {@linkcode initializeGoogleAnalytics}.
|
|
27
27
|
*/
|
|
28
28
|
googleAnalytics?: string;
|
|
29
29
|
[propName: string]: string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cacheNames.d.ts","sourceRoot":"","sources":["../../src/utils/cacheNames.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cacheNames.d.ts","sourceRoot":"","sources":["../../src/utils/cacheNames.ts"],"names":[],"mappings":"AAWA,MAAM,WAAW,gBAAgB;IAC/B,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;CACxC;AAED,MAAM,MAAM,oBAAoB,GAAG,iBAAiB,GAAG,UAAU,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,CAAC;AAoBpG,eAAO,MAAM,UAAU;6BACI,uBAAuB,KAAG,IAAI;6CAQd,MAAM,KAAG,MAAM;sCAGtB,MAAM,KAAG,MAAM;qBAGlC,MAAM;qCAGY,MAAM,KAAG,MAAM;qBAGjC,MAAM;CAGtB,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A utility function that determines whether the current browser supports
|
|
3
|
-
* constructing a new
|
|
3
|
+
* constructing a new response from a `response.body` stream.
|
|
4
4
|
*
|
|
5
5
|
* @returns `true`, if the current browser can successfully construct
|
|
6
|
-
* a
|
|
6
|
+
* a response from a `response.body` stream, `false` otherwise.
|
|
7
7
|
* @private
|
|
8
8
|
*/
|
|
9
9
|
declare function canConstructResponseFromBodyStream(): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deleteOutdatedCaches.d.ts","sourceRoot":"","sources":["../../src/utils/deleteOutdatedCaches.ts"],"names":[],"mappings":"AAaA;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,oBAAoB,wBAA+B,MAAM,oBAAmB,MAAM,KAAuB,
|
|
1
|
+
{"version":3,"file":"deleteOutdatedCaches.d.ts","sourceRoot":"","sources":["../../src/utils/deleteOutdatedCaches.ts"],"names":[],"mappings":"AAaA;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,oBAAoB,wBAA+B,MAAM,oBAAmB,MAAM,KAAuB,OAAO,CAAC,MAAM,EAAE,CAUrI,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executeQuotaErrorCallbacks.d.ts","sourceRoot":"","sources":["../../src/utils/executeQuotaErrorCallbacks.ts"],"names":[],"mappings":"AAWA;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,QAAa,
|
|
1
|
+
{"version":3,"file":"executeQuotaErrorCallbacks.d.ts","sourceRoot":"","sources":["../../src/utils/executeQuotaErrorCallbacks.ts"],"names":[],"mappings":"AAWA;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,QAAa,OAAO,CAAC,IAAI,CAe/D,CAAC"}
|
|
@@ -2,15 +2,15 @@ import { Route } from "../Route.js";
|
|
|
2
2
|
import type { HTTPMethod } from "../constants.js";
|
|
3
3
|
import type { RouteHandler, RouteMatchCallback } from "../types.js";
|
|
4
4
|
/**
|
|
5
|
-
* Parses a `RegExp`, string, or function with a caching strategy into a
|
|
6
|
-
* when you want to create a
|
|
7
|
-
* you want to call
|
|
5
|
+
* Parses a `RegExp`, string, or function with a caching strategy into a {@linkcode Route}. This is for
|
|
6
|
+
* when you want to create a {@linkcode Route}, but you don't want to register it just yet: sometimes
|
|
7
|
+
* you want to call {@linkcode Route.setCatchHandler} first, for example.
|
|
8
8
|
*
|
|
9
|
-
* @param capture If the capture param is a
|
|
10
|
-
* @param handler A callback function that returns a
|
|
11
|
-
* This parameter is required if `capture` is not a
|
|
12
|
-
* @param method The HTTP method to match the
|
|
13
|
-
* @returns The generated
|
|
9
|
+
* @param capture If the capture param is a {@linkcode Route} object, all other arguments will be ignored.
|
|
10
|
+
* @param handler A callback function that returns a promise resulting in a response.
|
|
11
|
+
* This parameter is required if `capture` is not a {@linkcode Route} object.
|
|
12
|
+
* @param method The HTTP method to match the route against. Defaults to `'GET'`.
|
|
13
|
+
* @returns The generated {@linkcode Route}.
|
|
14
14
|
*/
|
|
15
15
|
export declare const parseRoute: (capture: RegExp | string | RouteMatchCallback | Route, handler?: RouteHandler, method?: HTTPMethod) => Route;
|
|
16
16
|
//# sourceMappingURL=parseRoute.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"waitUntil.d.ts","sourceRoot":"","sources":["../../src/utils/waitUntil.ts"],"names":[],"mappings":"AAOA;;;;;;;;GAQG;AACH,eAAO,MAAM,SAAS,
|
|
1
|
+
{"version":3,"file":"waitUntil.d.ts","sourceRoot":"","sources":["../../src/utils/waitUntil.ts"],"names":[],"mappings":"AAOA;;;;;;;;GAQG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,eAAe,eAAe,WAAW,MAAM,OAAO,CAAC,CAAC,CAAC,KAAG,OAAO,CAAC,CAAC,CAI/F,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "serwist",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A Swiss Army knife for service workers.",
|
|
6
6
|
"files": [
|
|
@@ -49,10 +49,10 @@
|
|
|
49
49
|
"idb": "8.0.0"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"rollup": "4.
|
|
53
|
-
"typescript": "5.5.
|
|
54
|
-
"@serwist/configs": "9.0.
|
|
55
|
-
"@serwist/utils": "9.0.
|
|
52
|
+
"rollup": "4.18.1",
|
|
53
|
+
"typescript": "5.5.3",
|
|
54
|
+
"@serwist/configs": "9.0.4",
|
|
55
|
+
"@serwist/utils": "9.0.4"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"typescript": ">=5.0.0"
|
package/src/NavigationRoute.ts
CHANGED
|
@@ -27,9 +27,9 @@ export interface NavigationRouteMatchOptions {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
30
|
+
* A class that makes it easy to create a {@linkcode Route} object that matches navigation requests.
|
|
31
31
|
*
|
|
32
|
-
* It will only match incoming
|
|
32
|
+
* It will only match incoming requests whose [`mode`](https://fetch.spec.whatwg.org/#concept-request-mode) is set to `"navigate"`.
|
|
33
33
|
*
|
|
34
34
|
* You can optionally only apply this route to a subset of navigation requests
|
|
35
35
|
* by using one or both of the `denylist` and `allowlist` parameters.
|
package/src/PrecacheRoute.ts
CHANGED
|
@@ -15,13 +15,12 @@ import { getFriendlyURL } from "./utils/getFriendlyURL.js";
|
|
|
15
15
|
import { logger } from "./utils/logger.js";
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
* A subclass of
|
|
18
|
+
* A subclass of {@linkcode Route} that takes a {@linkcode Serwist} instance and uses it to match
|
|
19
19
|
* incoming requests and handle fetching responses from the precache.
|
|
20
20
|
*/
|
|
21
21
|
export class PrecacheRoute extends Route {
|
|
22
22
|
/**
|
|
23
|
-
* @param serwist A
|
|
24
|
-
* and respond to fetch events.
|
|
23
|
+
* @param serwist A {@linkcode Serwist} instance.
|
|
25
24
|
* @param options Options to control how requests are matched
|
|
26
25
|
* against the list of precached URLs.
|
|
27
26
|
*/
|
package/src/RegExpRoute.ts
CHANGED
|
@@ -13,7 +13,7 @@ import { assert } from "./utils/assert.js";
|
|
|
13
13
|
import { logger } from "./utils/logger.js";
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
16
|
+
* A class that makes it easy to create a {@linkcode Route} object with a regular expression.
|
|
17
17
|
*
|
|
18
18
|
* For same-origin requests the `RegExp` only needs to match part of the URL. For
|
|
19
19
|
* requests against third-party servers, you must define a `RegExp` that matches
|
|
@@ -27,7 +27,7 @@ export class RegExpRoute extends Route {
|
|
|
27
27
|
*
|
|
28
28
|
* @param regExp The regular expression to match against URLs.
|
|
29
29
|
* @param handler A callback function that returns a `Promise` resulting in a `Response`.
|
|
30
|
-
* @param method The HTTP method to match the
|
|
30
|
+
* @param method The HTTP method to match the {@linkcode Route} against. Defaults to `GET`.
|
|
31
31
|
* against.
|
|
32
32
|
*/
|
|
33
33
|
constructor(regExp: RegExp, handler: RouteHandler, method?: HTTPMethod) {
|
package/src/Route.ts
CHANGED
|
@@ -13,11 +13,11 @@ import { assert } from "./utils/assert.js";
|
|
|
13
13
|
import { normalizeHandler } from "./utils/normalizeHandler.js";
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
* A `Route` consists of a pair of callback functions, `match and `handler
|
|
16
|
+
* A `Route` consists of a pair of callback functions, `match` and `handler`.
|
|
17
17
|
* The `match` callback determines if a route should be used to handle a
|
|
18
|
-
* request by returning a truthy value if it can. The `handler callback
|
|
19
|
-
* is called when the route matches and should return a
|
|
20
|
-
* to a
|
|
18
|
+
* request by returning a truthy value if it can. The `handler` callback
|
|
19
|
+
* is called when the route matches and should return a promise that resolves
|
|
20
|
+
* to a response.
|
|
21
21
|
*/
|
|
22
22
|
export class Route {
|
|
23
23
|
handler: RouteHandlerObject;
|
package/src/Serwist.ts
CHANGED
|
@@ -135,7 +135,7 @@ export interface SerwistOptions {
|
|
|
135
135
|
*/
|
|
136
136
|
runtimeCaching?: RuntimeCaching[];
|
|
137
137
|
/**
|
|
138
|
-
* Your configuration for
|
|
138
|
+
* Your configuration for {@linkcode initializeGoogleAnalytics}. This plugin is
|
|
139
139
|
* only initialized when this option is not `undefined` or `false`.
|
|
140
140
|
*/
|
|
141
141
|
offlineAnalyticsConfig?: Omit<GoogleAnalyticsInitializeOptions, "serwist"> | boolean;
|
|
@@ -147,7 +147,7 @@ export interface SerwistOptions {
|
|
|
147
147
|
disableDevLogs?: boolean;
|
|
148
148
|
/**
|
|
149
149
|
* Precaches routes so that they can be used as a fallback when
|
|
150
|
-
* a
|
|
150
|
+
* a {@linkcode Strategy} fails to generate a response.
|
|
151
151
|
*
|
|
152
152
|
* Note: This option mutates `runtimeCaching`. It also expects the URLs
|
|
153
153
|
* defined in `entries` to have been precached beforehand.
|
|
@@ -284,13 +284,13 @@ export class Serwist {
|
|
|
284
284
|
}
|
|
285
285
|
|
|
286
286
|
/**
|
|
287
|
-
* The strategy used to precache assets and respond to fetch events.
|
|
287
|
+
* The strategy used to precache assets and respond to `fetch` events.
|
|
288
288
|
*/
|
|
289
289
|
get precacheStrategy(): Strategy {
|
|
290
290
|
return this._precacheStrategy;
|
|
291
291
|
}
|
|
292
292
|
/**
|
|
293
|
-
* A `Map` of HTTP method name (`'GET'`, etc.) to an array of all corresponding registered
|
|
293
|
+
* A `Map` of HTTP method name (`'GET'`, etc.) to an array of all corresponding registered {@linkcode Route}
|
|
294
294
|
* instances.
|
|
295
295
|
*/
|
|
296
296
|
get routes(): Map<HTTPMethod, Route[]> {
|
|
@@ -495,7 +495,7 @@ export class Serwist {
|
|
|
495
495
|
}
|
|
496
496
|
|
|
497
497
|
/**
|
|
498
|
-
* Define a default
|
|
498
|
+
* Define a default handler that's called when no routes explicitly
|
|
499
499
|
* match the incoming request.
|
|
500
500
|
*
|
|
501
501
|
* Each HTTP method (`'GET'`, `'POST'`, etc.) gets its own default handler.
|
|
@@ -512,11 +512,11 @@ export class Serwist {
|
|
|
512
512
|
}
|
|
513
513
|
|
|
514
514
|
/**
|
|
515
|
-
* If a
|
|
515
|
+
* If a {@linkcode Route} throws an error while handling a request, this handler
|
|
516
516
|
* will be called and given a chance to provide a response.
|
|
517
517
|
*
|
|
518
|
-
* @param handler A callback function that returns a Promise resulting
|
|
519
|
-
* in a Response
|
|
518
|
+
* @param handler A callback function that returns a `Promise` resulting
|
|
519
|
+
* in a `Response`.
|
|
520
520
|
*/
|
|
521
521
|
setCatchHandler(handler: RouteHandler): void {
|
|
522
522
|
this._catchHandler = normalizeHandler(handler);
|
|
@@ -526,11 +526,11 @@ export class Serwist {
|
|
|
526
526
|
* Registers a `RegExp`, string, or function with a caching
|
|
527
527
|
* strategy to the router.
|
|
528
528
|
*
|
|
529
|
-
* @param capture If the capture param is a
|
|
529
|
+
* @param capture If the capture param is a {@linkcode Route} object, all other arguments will be ignored.
|
|
530
530
|
* @param handler A callback function that returns a `Promise` resulting in a `Response`.
|
|
531
|
-
* This parameter is required if `capture` is not a
|
|
532
|
-
* @param method The HTTP method to match the
|
|
533
|
-
* @returns The generated
|
|
531
|
+
* This parameter is required if `capture` is not a {@linkcode Route} object.
|
|
532
|
+
* @param method The HTTP method to match the route against. Defaults to `'GET'`.
|
|
533
|
+
* @returns The generated {@linkcode Route} object.
|
|
534
534
|
*/
|
|
535
535
|
registerCapture<T extends RegExp | string | RouteMatchCallback | Route>(
|
|
536
536
|
capture: T,
|
|
@@ -543,9 +543,9 @@ export class Serwist {
|
|
|
543
543
|
}
|
|
544
544
|
|
|
545
545
|
/**
|
|
546
|
-
* Registers a
|
|
546
|
+
* Registers a {@linkcode Route} with the router.
|
|
547
547
|
*
|
|
548
|
-
* @param route The
|
|
548
|
+
* @param route The {@linkcode Route} to register.
|
|
549
549
|
*/
|
|
550
550
|
registerRoute(route: Route): void {
|
|
551
551
|
if (process.env.NODE_ENV !== "production") {
|
|
@@ -595,9 +595,9 @@ export class Serwist {
|
|
|
595
595
|
}
|
|
596
596
|
|
|
597
597
|
/**
|
|
598
|
-
* Unregisters a
|
|
598
|
+
* Unregisters a route from the router.
|
|
599
599
|
*
|
|
600
|
-
* @param route The
|
|
600
|
+
* @param route The {@linkcode Route} object to unregister.
|
|
601
601
|
*/
|
|
602
602
|
unregisterRoute(route: Route): void {
|
|
603
603
|
if (!this._routes.has(route.method)) {
|
|
@@ -706,12 +706,12 @@ export class Serwist {
|
|
|
706
706
|
}
|
|
707
707
|
|
|
708
708
|
/**
|
|
709
|
-
* Applies the routing rules to a `FetchEvent` object to get a
|
|
710
|
-
* appropriate
|
|
709
|
+
* Applies the routing rules to a `FetchEvent` object to get a response from an
|
|
710
|
+
* appropriate route.
|
|
711
711
|
*
|
|
712
712
|
* @param options
|
|
713
713
|
* @returns A promise is returned if a registered route can handle the request.
|
|
714
|
-
* If there is no matching route and there's no
|
|
714
|
+
* If there is no matching route and there's no default handler, `undefined`
|
|
715
715
|
* is returned.
|
|
716
716
|
*/
|
|
717
717
|
handleRequest({
|
|
@@ -79,7 +79,7 @@ export class PrecacheController {
|
|
|
79
79
|
|
|
80
80
|
/**
|
|
81
81
|
* The strategy created by this controller and
|
|
82
|
-
* used to cache assets and respond to fetch events.
|
|
82
|
+
* used to cache assets and respond to `fetch` events.
|
|
83
83
|
*/
|
|
84
84
|
get strategy(): Strategy {
|
|
85
85
|
return this._strategy;
|
|
@@ -35,23 +35,22 @@ export interface PrecacheFallbackPluginOptions {
|
|
|
35
35
|
*/
|
|
36
36
|
fallbackUrls: (string | PrecacheFallbackEntry)[];
|
|
37
37
|
/**
|
|
38
|
-
* An optional
|
|
39
|
-
*
|
|
38
|
+
* An optional {@linkcode PrecacheController} instance. If not provided,
|
|
39
|
+
* the default {@linkcode PrecacheController} will be used.
|
|
40
40
|
*/
|
|
41
41
|
precacheController?: PrecacheController;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
|
-
*
|
|
45
|
+
* A class that allows you to specify offline fallbacks
|
|
46
46
|
* to be used when a given strategy is unable to generate a response.
|
|
47
47
|
*
|
|
48
48
|
* It does this by intercepting the `handlerDidError` plugin callback
|
|
49
49
|
* and returning a precached response, taking the expected revision parameter
|
|
50
50
|
* into account automatically.
|
|
51
51
|
*
|
|
52
|
-
* Unless you explicitly pass in a
|
|
53
|
-
* constructor, the default instance will be used.
|
|
54
|
-
* developers will end up using the default.
|
|
52
|
+
* Unless you explicitly pass in a {@linkcode PrecacheController} instance to the
|
|
53
|
+
* constructor, the default instance will be used.
|
|
55
54
|
*
|
|
56
55
|
* @deprecated
|
|
57
56
|
*/
|
|
@@ -60,7 +59,7 @@ export class PrecacheFallbackPlugin implements SerwistPlugin {
|
|
|
60
59
|
private readonly _precacheController: PrecacheController;
|
|
61
60
|
|
|
62
61
|
/**
|
|
63
|
-
* Constructs a new
|
|
62
|
+
* Constructs a new instance with the associated `fallbackUrls`.
|
|
64
63
|
*
|
|
65
64
|
* @param config
|
|
66
65
|
*/
|
|
@@ -15,15 +15,15 @@ import { logger } from "../utils/logger.js";
|
|
|
15
15
|
import type { PrecacheController } from "./PrecacheController.js";
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
* A subclass of
|
|
18
|
+
* A subclass of {@linkcode Route} that takes a {@linkcode PrecacheController}
|
|
19
19
|
* instance and uses it to match incoming requests and handle fetching
|
|
20
20
|
* responses from the precache.
|
|
21
21
|
* @deprecated
|
|
22
22
|
*/
|
|
23
23
|
export class PrecacheRoute extends Route {
|
|
24
24
|
/**
|
|
25
|
-
* @param precacheController A
|
|
26
|
-
* instance used to both match requests and respond to fetch events.
|
|
25
|
+
* @param precacheController A {@linkcode PrecacheController}
|
|
26
|
+
* instance used to both match requests and respond to `fetch` events.
|
|
27
27
|
* @param options Options to control how requests are matched
|
|
28
28
|
* against the list of precached URLs.
|
|
29
29
|
*/
|