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
package/src/legacy/Router.ts
CHANGED
|
@@ -29,15 +29,15 @@ interface CacheURLsMessageData {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
|
-
*
|
|
32
|
+
* A class that can be used to process a `fetch` event using one or more route(s), responding with a response
|
|
33
33
|
* if a matching route exists.
|
|
34
34
|
*
|
|
35
|
-
* If no
|
|
35
|
+
* If no route matches given a request, the router will use the default handler if one is defined.
|
|
36
36
|
*
|
|
37
|
-
* Should the matching
|
|
38
|
-
* gracefully deal with issues and respond with a
|
|
37
|
+
* Should the matching route throw an error, the router will use the catch handler if one is defined to
|
|
38
|
+
* gracefully deal with issues and respond with a response.
|
|
39
39
|
*
|
|
40
|
-
* If a
|
|
40
|
+
* If a request matches multiple routes, the earliest registered route will be used to respond to the it.
|
|
41
41
|
* @deprecated
|
|
42
42
|
*/
|
|
43
43
|
export class Router {
|
|
@@ -56,16 +56,16 @@ export class Router {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
|
-
* @returns routes A `Map` of HTTP method name (`'GET'`, etc.) to an array of all
|
|
60
|
-
* instances that are registered.
|
|
59
|
+
* @returns routes A `Map` of HTTP method name (`'GET'`, etc.) to an array of all
|
|
60
|
+
* the corresponding {@linkcode Route} instances that are registered.
|
|
61
61
|
*/
|
|
62
62
|
get routes(): Map<HTTPMethod, Route[]> {
|
|
63
63
|
return this._routes;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
|
-
* Adds a `fetch` event listener to respond to events when a
|
|
68
|
-
* the event's request. Effectively no-op if `
|
|
67
|
+
* Adds a `fetch` event listener to respond to events when a route matches
|
|
68
|
+
* the event's request. Effectively no-op if `addFetchListener` has been
|
|
69
69
|
* called, but `removeFetchListener` has not.
|
|
70
70
|
*/
|
|
71
71
|
addFetchListener(): void {
|
|
@@ -161,8 +161,8 @@ export class Router {
|
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
/**
|
|
164
|
-
* Apply the routing rules to a `
|
|
165
|
-
* appropriate
|
|
164
|
+
* Apply the routing rules to a `fetch` event to get a response from an
|
|
165
|
+
* appropriate route.
|
|
166
166
|
*
|
|
167
167
|
* @param options
|
|
168
168
|
* @returns A promise is returned if a registered route can handle the request.
|
|
@@ -367,7 +367,7 @@ export class Router {
|
|
|
367
367
|
}
|
|
368
368
|
|
|
369
369
|
/**
|
|
370
|
-
* Define a default
|
|
370
|
+
* Define a default handler that's called when no routes explicitly
|
|
371
371
|
* match the incoming request.
|
|
372
372
|
*
|
|
373
373
|
* Each HTTP method (`'GET'`, `'POST'`, etc.) gets its own default handler.
|
|
@@ -375,7 +375,7 @@ export class Router {
|
|
|
375
375
|
* Without a default handler, unmatched requests will go against the
|
|
376
376
|
* network as if there were no service worker present.
|
|
377
377
|
*
|
|
378
|
-
* @param handler A callback function that returns a
|
|
378
|
+
* @param handler A callback function that returns a promise resulting in a response.
|
|
379
379
|
* @param method The HTTP method to associate with this default handler. Each method
|
|
380
380
|
* has its own default. Defaults to `'GET'`.
|
|
381
381
|
*/
|
|
@@ -396,13 +396,13 @@ export class Router {
|
|
|
396
396
|
|
|
397
397
|
/**
|
|
398
398
|
* Registers a `RegExp`, string, or function with a caching
|
|
399
|
-
* strategy to the
|
|
399
|
+
* strategy to the router.
|
|
400
400
|
*
|
|
401
|
-
* @param capture If the capture param is a
|
|
402
|
-
* @param handler A callback function that returns a
|
|
403
|
-
* This parameter is required if `capture` is not a
|
|
404
|
-
* @param method The HTTP method to match the
|
|
405
|
-
* @returns The generated
|
|
401
|
+
* @param capture If the capture param is a {@linkcode Route} object, all other arguments will be ignored.
|
|
402
|
+
* @param handler A callback function that returns a promise resulting in a response.
|
|
403
|
+
* This parameter is required if `capture` is not a {@linkcode Route} object.
|
|
404
|
+
* @param method The HTTP method to match the route against. Defaults to `'GET'`.
|
|
405
|
+
* @returns The generated {@linkcode Route} object.
|
|
406
406
|
*/
|
|
407
407
|
registerCapture(capture: RegExp | string | RouteMatchCallback | Route, handler?: RouteHandler, method?: HTTPMethod): Route {
|
|
408
408
|
const route = parseRoute(capture, handler, method);
|
|
@@ -411,9 +411,9 @@ export class Router {
|
|
|
411
411
|
}
|
|
412
412
|
|
|
413
413
|
/**
|
|
414
|
-
* Registers a
|
|
414
|
+
* Registers a route with the router.
|
|
415
415
|
*
|
|
416
|
-
* @param route The
|
|
416
|
+
* @param route The route to register.
|
|
417
417
|
*/
|
|
418
418
|
registerRoute(route: Route): void {
|
|
419
419
|
if (process.env.NODE_ENV !== "production") {
|
|
@@ -463,9 +463,9 @@ export class Router {
|
|
|
463
463
|
}
|
|
464
464
|
|
|
465
465
|
/**
|
|
466
|
-
* Unregisters a
|
|
466
|
+
* Unregisters a route from the router.
|
|
467
467
|
*
|
|
468
|
-
* @param route The
|
|
468
|
+
* @param route The route to unregister.
|
|
469
469
|
*/
|
|
470
470
|
unregisterRoute(route: Route): void {
|
|
471
471
|
if (!this._routes.has(route.method)) {
|
package/src/legacy/addRoute.ts
CHANGED
|
@@ -11,16 +11,14 @@ import { registerRoute } from "./registerRoute.js";
|
|
|
11
11
|
import { getSingletonPrecacheController } from "./singletonPrecacheController.js";
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
* Add a `fetch` listener
|
|
15
|
-
* respond to
|
|
16
|
-
*
|
|
17
|
-
* with precached assets.
|
|
14
|
+
* Add a `fetch` listener that will
|
|
15
|
+
* respond to [network requests](https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API/Using_Service_Workers#Custom_responses_to_requests)
|
|
16
|
+
* with precached assets to the service worker.
|
|
18
17
|
*
|
|
19
|
-
*
|
|
20
|
-
* responded to, allowing the event to fall through to other `fetch` event
|
|
21
|
-
* listeners.
|
|
18
|
+
* As for requests for assets that aren't precached, the `fetch` event will not be
|
|
19
|
+
* responded to, allowing the event to fall through to other `fetch` event listeners.
|
|
22
20
|
*
|
|
23
|
-
* @param options See
|
|
21
|
+
* @param options See {@linkcode PrecacheRouteOptions}.
|
|
24
22
|
* @deprecated
|
|
25
23
|
*/
|
|
26
24
|
export const addRoute = (options?: PrecacheRouteOptions): void => {
|
|
@@ -7,18 +7,18 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import type { RouteHandlerCallback } from "../types.js";
|
|
10
|
+
import type { PrecacheController } from "./PrecacheController.js";
|
|
10
11
|
import { getSingletonPrecacheController } from "./singletonPrecacheController.js";
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
|
-
* Helper function that calls
|
|
14
|
-
* on the default
|
|
14
|
+
* Helper function that calls {@linkcode PrecacheController.createHandlerBoundToURL}
|
|
15
|
+
* on the default {@linkcode PrecacheController} instance.
|
|
15
16
|
*
|
|
16
|
-
* If you are creating your own
|
|
17
|
-
*
|
|
17
|
+
* If you are creating your own {@linkcode PrecacheController}, then call the
|
|
18
|
+
* {@linkcode PrecacheController.createHandlerBoundToURL} function on that instance
|
|
18
19
|
* instead of using this function.
|
|
19
20
|
*
|
|
20
|
-
* @param url The precached URL which will be used to
|
|
21
|
-
* `Response`.
|
|
21
|
+
* @param url The precached URL which will be used to look up the response.
|
|
22
22
|
* @param fallbackToNetwork Whether to attempt to get the
|
|
23
23
|
* response from the network if there's a precache miss.
|
|
24
24
|
* @return
|
package/src/legacy/fallbacks.ts
CHANGED
|
@@ -29,12 +29,12 @@ export interface FallbacksOptions {
|
|
|
29
29
|
|
|
30
30
|
export interface FallbacksOptions {
|
|
31
31
|
/**
|
|
32
|
-
* An optional
|
|
33
|
-
*
|
|
32
|
+
* An optional {@linkcode PrecacheController} instance. If not provided, the singleton
|
|
33
|
+
* {@linkcode PrecacheController} will be used.
|
|
34
34
|
*/
|
|
35
35
|
precacheController?: PrecacheController;
|
|
36
36
|
/**
|
|
37
|
-
* An optional
|
|
37
|
+
* An optional {@linkcode Router} instance. If not provided, the singleton {@linkcode Router}
|
|
38
38
|
* will be used.
|
|
39
39
|
*/
|
|
40
40
|
router?: Router;
|
|
@@ -13,12 +13,12 @@ import { getSingletonRouter } from "./singletonRouter.js";
|
|
|
13
13
|
*/
|
|
14
14
|
export interface HandlePrecachingOptions {
|
|
15
15
|
/**
|
|
16
|
-
* An optional
|
|
17
|
-
*
|
|
16
|
+
* An optional {@linkcode PrecacheController} instance. If not provided, the singleton
|
|
17
|
+
* {@linkcode PrecacheController} will be used.
|
|
18
18
|
*/
|
|
19
19
|
precacheController?: PrecacheController;
|
|
20
20
|
/**
|
|
21
|
-
* An optional
|
|
21
|
+
* An optional {@linkcode Router} instance. If not provided, the singleton {@linkcode Router}
|
|
22
22
|
* will be used.
|
|
23
23
|
*/
|
|
24
24
|
router?: Router;
|
|
@@ -33,7 +33,7 @@ import { getSingletonRouter } from "./singletonRouter.js";
|
|
|
33
33
|
*/
|
|
34
34
|
export interface GoogleAnalyticsInitializeOptions {
|
|
35
35
|
/**
|
|
36
|
-
* An optional
|
|
36
|
+
* An optional {@linkcode Router} instance. If not provided, the singleton {@linkcode Router}
|
|
37
37
|
* will be used.
|
|
38
38
|
*/
|
|
39
39
|
router?: Router;
|
|
@@ -17,18 +17,18 @@ import { getSingletonRouter } from "./singletonRouter.js";
|
|
|
17
17
|
declare const self: ServiceWorkerGlobalScope;
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
|
-
* Options for
|
|
20
|
+
* Options for {@linkcode installSerwist}.
|
|
21
21
|
*
|
|
22
22
|
* @deprecated
|
|
23
23
|
*/
|
|
24
24
|
export interface InstallSerwistOptions extends Omit<HandlePrecachingOptions, "precacheController" | "router"> {
|
|
25
25
|
/**
|
|
26
|
-
* An optional
|
|
27
|
-
*
|
|
26
|
+
* An optional {@linkcode PrecacheController} instance. If not provided, the singleton
|
|
27
|
+
* {@linkcode PrecacheController} will be used.
|
|
28
28
|
*/
|
|
29
29
|
precacheController?: PrecacheController;
|
|
30
30
|
/**
|
|
31
|
-
* An optional
|
|
31
|
+
* An optional {@linkcode Router} instance. If not provided, the singleton {@linkcode Router}
|
|
32
32
|
* will be used.
|
|
33
33
|
*/
|
|
34
34
|
router?: Router;
|
|
@@ -7,13 +7,14 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { getSingletonPrecacheController } from "./singletonPrecacheController.js";
|
|
10
|
+
import type { PrecacheController } from "./PrecacheController.js";
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
|
-
* Helper function that calls
|
|
13
|
-
* on the default
|
|
13
|
+
* Helper function that calls {@linkcode PrecacheController.matchPrecache}
|
|
14
|
+
* on the default {@linkcode PrecacheController} instance.
|
|
14
15
|
*
|
|
15
|
-
* If you are creating your own
|
|
16
|
-
*
|
|
16
|
+
* If you are creating your own {@linkcode PrecacheController}, then call
|
|
17
|
+
* the {@linkcode PrecacheController.matchPrecache} function on that instance
|
|
17
18
|
* instead of using this function.
|
|
18
19
|
*
|
|
19
20
|
* @param request The key (without revisioning parameters)
|
package/src/legacy/precache.ts
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
|
|
9
9
|
import type { PrecacheEntry } from "../types.js";
|
|
10
10
|
import { getSingletonPrecacheController } from "./singletonPrecacheController.js";
|
|
11
|
+
import type { addRoute } from "./addRoute.js";
|
|
12
|
+
import type { precacheAndRoute } from "./precacheAndRoute.js";
|
|
11
13
|
|
|
12
14
|
/**
|
|
13
15
|
* Adds items to the precache list, removing any duplicates and
|
|
@@ -18,10 +20,10 @@ import { getSingletonPrecacheController } from "./singletonPrecacheController.js
|
|
|
18
20
|
*
|
|
19
21
|
* Please note: This method **will not** serve any of the cached files for you.
|
|
20
22
|
* It only precaches files. To respond to a network request you call
|
|
21
|
-
*
|
|
23
|
+
* {@linkcode addRoute}.
|
|
22
24
|
*
|
|
23
25
|
* If you have a single array of files to precache, you can just call
|
|
24
|
-
*
|
|
26
|
+
* {@linkcode precacheAndRoute}.
|
|
25
27
|
*
|
|
26
28
|
* @param entries Array of entries to precache.
|
|
27
29
|
* @deprecated
|
|
@@ -12,14 +12,13 @@ import { precache } from "./precache.js";
|
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* This method will add entries to the precache list and add a route to
|
|
15
|
-
* respond to fetch events.
|
|
15
|
+
* respond to `fetch` events.
|
|
16
16
|
*
|
|
17
17
|
* This is a convenience method that will call
|
|
18
|
-
*
|
|
19
|
-
* `serwist/legacy.addRoute` in a single call.
|
|
18
|
+
* {@linkcode precache} and {@linkcode addRoute} in a single call.
|
|
20
19
|
*
|
|
21
20
|
* @param entries Array of entries to precache.
|
|
22
|
-
* @param options See the
|
|
21
|
+
* @param options See the {@linkcode PrecacheRouteOptions} options.
|
|
23
22
|
* @deprecated
|
|
24
23
|
*/
|
|
25
24
|
export const precacheAndRoute = (entries: (PrecacheEntry | string)[], options?: PrecacheRouteOptions): void => {
|
|
@@ -5,21 +5,22 @@
|
|
|
5
5
|
license that can be found in the LICENSE file or at
|
|
6
6
|
https://opensource.org/licenses/MIT.
|
|
7
7
|
*/
|
|
8
|
-
|
|
8
|
+
import type { Router } from "./Router.js";
|
|
9
9
|
import type { Route } from "../Route.js";
|
|
10
10
|
import type { HTTPMethod } from "../constants.js";
|
|
11
11
|
import type { RouteHandler, RouteMatchCallback } from "../types.js";
|
|
12
|
+
import type { unregisterRoute } from "./unregisterRoute.js";
|
|
12
13
|
import { getSingletonRouter } from "./singletonRouter.js";
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Registers a `RegExp`, string, or function with a caching
|
|
16
|
-
* strategy to a singleton
|
|
17
|
+
* strategy to a singleton {@linkcode Router} instance.
|
|
17
18
|
*
|
|
18
|
-
* @param capture If the capture param is a
|
|
19
|
-
* @param handler A callback function that returns a
|
|
20
|
-
* This parameter is required if `capture` is not a
|
|
21
|
-
* @param method The HTTP method to match the
|
|
22
|
-
* @returns The generated
|
|
19
|
+
* @param capture If the capture param is a {@linkcode Route}, all other arguments will be ignored.
|
|
20
|
+
* @param handler A callback function that returns a promise resulting in a response.
|
|
21
|
+
* This parameter is required if `capture` is not a {@linkcode Route} object.
|
|
22
|
+
* @param method The HTTP method to match the route against. Defaults to `'GET'`.
|
|
23
|
+
* @returns The generated {@linkcode Route} object, which can then be provided to {@linkcode unregisterRoute} if needed.
|
|
23
24
|
* @deprecated
|
|
24
25
|
*/
|
|
25
26
|
export const registerRoute = (capture: RegExp | string | RouteMatchCallback | Route, handler?: RouteHandler, method?: HTTPMethod): Route => {
|
|
@@ -4,7 +4,7 @@ import type { RuntimeCaching } from "../types.js";
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Registers caching strategies to a singleton Router instance. It is a simple
|
|
7
|
-
* syntatic sugar for
|
|
7
|
+
* syntatic sugar for {@linkcode registerRoute}.
|
|
8
8
|
*
|
|
9
9
|
* @param runtimeCachingList
|
|
10
10
|
* @returns
|
|
@@ -10,10 +10,10 @@ import type { RouteHandler } from "../types.js";
|
|
|
10
10
|
import { getSingletonRouter } from "./singletonRouter.js";
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* If a
|
|
13
|
+
* If a route throws an error while handling a request, this handler
|
|
14
14
|
* will be called and given a chance to provide a response.
|
|
15
15
|
*
|
|
16
|
-
* @param handler A callback function that returns a
|
|
16
|
+
* @param handler A callback function that returns a promise resulting in a response.
|
|
17
17
|
* @deprecated
|
|
18
18
|
*/
|
|
19
19
|
export const setCatchHandler = (handler: RouteHandler): void => {
|
|
@@ -10,13 +10,13 @@ import type { RouteHandler } from "../types.js";
|
|
|
10
10
|
import { getSingletonRouter } from "./singletonRouter.js";
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* Defines a default
|
|
13
|
+
* Defines a default handler that's called when no routes explicitly
|
|
14
14
|
* match the incoming request.
|
|
15
15
|
*
|
|
16
|
-
* Without a default
|
|
16
|
+
* Without a default handler, unmatched requests will go against the
|
|
17
17
|
* network as if there were no service worker present.
|
|
18
18
|
*
|
|
19
|
-
* @param handler A callback function that returns a
|
|
19
|
+
* @param handler A callback function that returns a promise resulting in a response.
|
|
20
20
|
* @deprecated
|
|
21
21
|
*/
|
|
22
22
|
export const setDefaultHandler = (handler: RouteHandler): void => {
|
|
@@ -11,12 +11,12 @@ import { PrecacheController } from "./PrecacheController.js";
|
|
|
11
11
|
let defaultPrecacheController: PrecacheController | undefined = undefined;
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
* Creates a new, singleton
|
|
14
|
+
* Creates a new, singleton {@linkcode PrecacheController} if one does not exist. If one does
|
|
15
15
|
* already exist, that instance is returned. This instance is used by Serwist's
|
|
16
|
-
*
|
|
17
|
-
*
|
|
16
|
+
* {@linkcode PrecacheController}-dependent functions and classes unless you provide a different
|
|
17
|
+
* {@linkcode PrecacheController} to them.
|
|
18
18
|
*
|
|
19
|
-
* @returns The singleton
|
|
19
|
+
* @returns The singleton {@linkcode PrecacheController}.
|
|
20
20
|
* @deprecated
|
|
21
21
|
*/
|
|
22
22
|
export const getSingletonPrecacheController = (): PrecacheController => {
|
|
@@ -27,8 +27,8 @@ export const getSingletonPrecacheController = (): PrecacheController => {
|
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
|
-
* Changes the singleton
|
|
31
|
-
* want to pass your own
|
|
30
|
+
* Changes the singleton {@linkcode PrecacheController} to a different instance. This is meant for when you do not
|
|
31
|
+
* want to pass your own {@linkcode PrecacheController} to every one of Serwist's {@linkcode PrecacheController}-dependent
|
|
32
32
|
* functions and classes.
|
|
33
33
|
*
|
|
34
34
|
* It is highly recommended that you call this before anything else, if you plan on doing so.
|
|
@@ -44,7 +44,7 @@ export const getSingletonPrecacheController = (): PrecacheController => {
|
|
|
44
44
|
* // Do something with your controller...
|
|
45
45
|
* ```
|
|
46
46
|
* @param router
|
|
47
|
-
* @returns The new singleton
|
|
47
|
+
* @returns The new singleton {@linkcode PrecacheController}.
|
|
48
48
|
* @deprecated
|
|
49
49
|
*/
|
|
50
50
|
export const setSingletonPrecacheController = (precacheController: PrecacheController): PrecacheController => {
|
|
@@ -11,12 +11,12 @@ import { Router } from "./Router.js";
|
|
|
11
11
|
let defaultRouter: Router | undefined = undefined;
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
* Creates a new, singleton
|
|
14
|
+
* Creates a new, singleton {@linkcode Router} if one does not exist. If one does
|
|
15
15
|
* already exist, that instance is returned. This instance is used by
|
|
16
|
-
* Serwist's
|
|
17
|
-
* a different
|
|
16
|
+
* Serwist's {@linkcode Router}-dependent functions and classes unless you provide
|
|
17
|
+
* a different {@linkcode Router} to them.
|
|
18
18
|
*
|
|
19
|
-
* @returns The singleton
|
|
19
|
+
* @returns The singleton {@linkcode Router}.
|
|
20
20
|
* @deprecated
|
|
21
21
|
*/
|
|
22
22
|
export const getSingletonRouter = (): Router => {
|
|
@@ -31,10 +31,10 @@ export const getSingletonRouter = (): Router => {
|
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
|
-
* Changes the singleton
|
|
35
|
-
* want to pass your own
|
|
36
|
-
* If this or
|
|
37
|
-
* previous singleton
|
|
34
|
+
* Changes the singleton {@linkcode Router} to a different instance. This is meant for when you do not
|
|
35
|
+
* want to pass your own {@linkcode Router} to every one of Serwist's {@linkcode Router}-dependent functions and classes.
|
|
36
|
+
* If this or {@linkcode getSingletonRouter} has been called before, it removes the listeners of the
|
|
37
|
+
* previous singleton {@linkcode Router}. It also adds those of the new one, so you need not do that yourself.
|
|
38
38
|
*
|
|
39
39
|
* It is highly recommended that you call this before anything else, if you plan on doing so.
|
|
40
40
|
*
|
|
@@ -55,7 +55,7 @@ export const getSingletonRouter = (): Router => {
|
|
|
55
55
|
* );
|
|
56
56
|
* ```
|
|
57
57
|
* @param router
|
|
58
|
-
* @returns The new singleton
|
|
58
|
+
* @returns The new singleton {@linkcode Router}.
|
|
59
59
|
* @deprecated
|
|
60
60
|
*/
|
|
61
61
|
export const setSingletonRouter = (router: Router): Router => {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { Route } from "../Route.js";
|
|
2
|
+
import type { Router } from "./Router.js";
|
|
2
3
|
import { getSingletonRouter } from "./singletonRouter.js";
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
|
-
* Unregisters a route from the singleton
|
|
6
|
+
* Unregisters a route from the singleton {@linkcode Router} instance.
|
|
6
7
|
*
|
|
7
8
|
* @param route The route to unregister.
|
|
8
9
|
* @deprecated
|
|
@@ -12,15 +12,15 @@ import { BackgroundSyncQueue } from "./BackgroundSyncQueue.js";
|
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* A class implementing the `fetchDidFail` lifecycle callback. This makes it
|
|
15
|
-
* easier to add failed requests to a
|
|
15
|
+
* easier to add failed requests to a {@linkcode BackgroundSyncQueue}.
|
|
16
16
|
*/
|
|
17
17
|
export class BackgroundSyncPlugin implements SerwistPlugin {
|
|
18
18
|
private readonly _queue: BackgroundSyncQueue;
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
|
-
* @param name See the
|
|
21
|
+
* @param name See the {@linkcode BackgroundSyncQueue}
|
|
22
22
|
* documentation for parameter details.
|
|
23
|
-
* @param options See the
|
|
23
|
+
* @param options See the {@linkcode BackgroundSyncQueue}
|
|
24
24
|
* documentation for parameter details.
|
|
25
25
|
* @see https://serwist.pages.dev/docs/core/background-sync-queue
|
|
26
26
|
*/
|
|
@@ -312,7 +312,7 @@ export class BackgroundSyncQueue {
|
|
|
312
312
|
|
|
313
313
|
/**
|
|
314
314
|
* Removes and returns the first or last (depending on `operation`) entry
|
|
315
|
-
* from the
|
|
315
|
+
* from the {@linkcode BackgroundSyncQueueStore} that's not older than the `maxRetentionTime`.
|
|
316
316
|
*
|
|
317
317
|
* @param operation
|
|
318
318
|
* @returns
|
|
@@ -77,7 +77,7 @@ export class StorableRequest {
|
|
|
77
77
|
|
|
78
78
|
/**
|
|
79
79
|
* Accepts an object of request data that can be used to construct a
|
|
80
|
-
* `Request` but can also be stored in IndexedDB.
|
|
80
|
+
* `Request` object but can also be stored in IndexedDB.
|
|
81
81
|
*
|
|
82
82
|
* @param requestData An object of request data that includes the `url` plus any relevant property of
|
|
83
83
|
* [`requestInit`](https://fetch.spec.whatwg.org/#requestinit).
|
|
@@ -54,8 +54,7 @@ export class BroadcastCacheUpdate {
|
|
|
54
54
|
private readonly _notifyAllClients: boolean;
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
|
-
* Construct
|
|
58
|
-
* broadcast messages on
|
|
57
|
+
* Construct an instance of `BroadcastCacheUpdate`.
|
|
59
58
|
*
|
|
60
59
|
* @param options
|
|
61
60
|
*/
|
|
@@ -18,9 +18,10 @@ export class BroadcastUpdatePlugin implements SerwistPlugin {
|
|
|
18
18
|
private readonly _broadcastUpdate: BroadcastCacheUpdate;
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
|
-
* Construct a
|
|
22
|
-
* the passed options and calls its
|
|
23
|
-
* plugin's
|
|
21
|
+
* Construct a {@linkcode BroadcastCacheUpdate} instance with
|
|
22
|
+
* the passed options and calls its {@linkcode BroadcastCacheUpdate.notifyIfUpdated}
|
|
23
|
+
* method whenever the plugin's {@linkcode BroadcastUpdatePlugin.cacheDidUpdate} callback
|
|
24
|
+
* is invoked.
|
|
24
25
|
*
|
|
25
26
|
* @param options
|
|
26
27
|
*/
|
|
@@ -29,10 +30,6 @@ export class BroadcastUpdatePlugin implements SerwistPlugin {
|
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
/**
|
|
32
|
-
* A "lifecycle" callback that will be triggered automatically by
|
|
33
|
-
* `@serwist/build.RuntimeCaching` handlers when an entry is
|
|
34
|
-
* added to a cache.
|
|
35
|
-
*
|
|
36
33
|
* @private
|
|
37
34
|
* @param options The input object to this function.
|
|
38
35
|
*/
|
|
@@ -6,7 +6,8 @@ export interface BroadcastCacheUpdateOptions {
|
|
|
6
6
|
* A list of headers that will be used to determine whether the responses
|
|
7
7
|
* differ.
|
|
8
8
|
*
|
|
9
|
-
* @default
|
|
9
|
+
* @default
|
|
10
|
+
* ['content-length', 'etag', 'last-modified']`
|
|
10
11
|
*/
|
|
11
12
|
headersToCheck?: string[];
|
|
12
13
|
/**
|
|
@@ -13,11 +13,11 @@ import { logger } from "../../utils/logger.js";
|
|
|
13
13
|
|
|
14
14
|
export interface CacheableResponseOptions {
|
|
15
15
|
/**
|
|
16
|
-
* One or more status codes that a
|
|
16
|
+
* One or more HTTP status codes that a response can have to be considered cacheable.
|
|
17
17
|
*/
|
|
18
18
|
statuses?: number[];
|
|
19
19
|
/**
|
|
20
|
-
* A mapping of header names and expected values that a
|
|
20
|
+
* A mapping of header names and expected values that a response can have and be
|
|
21
21
|
* considered cacheable. If multiple headers are provided, only one needs to be present.
|
|
22
22
|
*/
|
|
23
23
|
headers?: HeadersInit;
|
|
@@ -25,7 +25,7 @@ export interface CacheableResponseOptions {
|
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* Allows you to set up rules determining what status codes and/or headers need
|
|
28
|
-
* to be present in order for a [
|
|
28
|
+
* to be present in order for a [response](https://developer.mozilla.org/en-US/docs/Web/API/Response)
|
|
29
29
|
* to be considered cacheable.
|
|
30
30
|
*/
|
|
31
31
|
export class CacheableResponse {
|
|
@@ -33,11 +33,11 @@ export class CacheableResponse {
|
|
|
33
33
|
private readonly _headers?: Headers;
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
|
-
* To construct a new CacheableResponse instance you must provide at least
|
|
36
|
+
* To construct a new `CacheableResponse` instance you must provide at least
|
|
37
37
|
* one of the `config` properties.
|
|
38
38
|
*
|
|
39
39
|
* If both `statuses` and `headers` are specified, then both conditions must
|
|
40
|
-
* be met for the
|
|
40
|
+
* be met for the response to be considered cacheable.
|
|
41
41
|
*
|
|
42
42
|
* @param config
|
|
43
43
|
*/
|
|
@@ -81,7 +81,7 @@ export class CacheableResponse {
|
|
|
81
81
|
*
|
|
82
82
|
* @param response The response whose cacheability is being
|
|
83
83
|
* checked.
|
|
84
|
-
* @returns `true` if the
|
|
84
|
+
* @returns `true` if the response is cacheable, and `false`
|
|
85
85
|
* otherwise.
|
|
86
86
|
*/
|
|
87
87
|
isResponseCacheable(response: Response): boolean {
|
|
@@ -19,11 +19,11 @@ export class CacheableResponsePlugin implements SerwistPlugin {
|
|
|
19
19
|
private readonly _cacheableResponse: CacheableResponse;
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
* To construct a new CacheableResponsePlugin instance you must provide at
|
|
22
|
+
* To construct a new `CacheableResponsePlugin` instance you must provide at
|
|
23
23
|
* least one of the `config` properties.
|
|
24
24
|
*
|
|
25
25
|
* If both `statuses` and `headers` are specified, then both conditions must
|
|
26
|
-
* be met for the
|
|
26
|
+
* be met for the response to be considered cacheable.
|
|
27
27
|
*
|
|
28
28
|
* @param config
|
|
29
29
|
*/
|
|
@@ -13,7 +13,7 @@ import { CacheTimestampsModel } from "./models/CacheTimestampsModel.js";
|
|
|
13
13
|
|
|
14
14
|
interface CacheExpirationConfig {
|
|
15
15
|
/**
|
|
16
|
-
* The maximum number of entries to cache. Entries used
|
|
16
|
+
* The maximum number of entries to cache. Entries used least recently will
|
|
17
17
|
* be removed as the maximum is reached.
|
|
18
18
|
*/
|
|
19
19
|
maxEntries?: number;
|
|
@@ -42,7 +42,7 @@ export class CacheExpiration {
|
|
|
42
42
|
private readonly _timestampModel: CacheTimestampsModel;
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
|
-
* To construct a new CacheExpiration instance you must provide at least
|
|
45
|
+
* To construct a new `CacheExpiration` instance you must provide at least
|
|
46
46
|
* one of the `config` properties.
|
|
47
47
|
*
|
|
48
48
|
* @param cacheName Name of the cache to apply restrictions to.
|