serwist 9.0.0-preview.25 → 9.0.0
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 +5 -6
- package/dist/NavigationRoute.d.ts.map +1 -1
- package/dist/PrecacheRoute.d.ts +2 -2
- package/dist/RegExpRoute.d.ts +3 -3
- package/dist/Route.d.ts +9 -9
- package/dist/Serwist.d.ts +1 -1
- package/dist/Serwist.d.ts.map +1 -1
- package/dist/chunks/printInstallDetails.js +50 -76
- package/dist/chunks/waitUntil.js +27 -1
- package/dist/copyResponse.d.ts +7 -9
- package/dist/copyResponse.d.ts.map +1 -1
- package/dist/index.d.ts +2 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.internal.d.ts +3 -1
- package/dist/index.internal.d.ts.map +1 -1
- package/dist/index.internal.js +1 -1
- package/dist/index.js +5 -5
- package/dist/index.legacy.d.ts +1 -7
- package/dist/index.legacy.d.ts.map +1 -1
- package/dist/index.legacy.js +4 -5
- package/dist/legacy/Router.d.ts.map +1 -1
- package/dist/legacy/handlePrecaching.d.ts.map +1 -1
- package/dist/legacy/installSerwist.d.ts.map +1 -1
- package/dist/lib/backgroundSync/StorableRequest.d.ts +4 -4
- package/dist/lib/expiration/ExpirationPlugin.d.ts +1 -1
- package/dist/lib/precaching/PrecacheFallbackPlugin.d.ts +0 -4
- package/dist/lib/precaching/PrecacheFallbackPlugin.d.ts.map +1 -1
- package/dist/lib/strategies/CacheFirst.d.ts +1 -1
- package/dist/lib/strategies/CacheOnly.d.ts +2 -2
- package/dist/lib/strategies/NetworkFirst.d.ts +2 -2
- package/dist/lib/strategies/NetworkOnly.d.ts +2 -2
- package/dist/lib/strategies/{PrecacheOnly.d.ts → PrecacheStrategy.d.ts} +2 -2
- package/dist/lib/strategies/PrecacheStrategy.d.ts.map +1 -0
- package/dist/lib/strategies/StaleWhileRevalidate.d.ts +1 -1
- package/dist/lib/strategies/Strategy.d.ts +14 -16
- package/dist/lib/strategies/Strategy.d.ts.map +1 -1
- package/dist/lib/strategies/StrategyHandler.d.ts +34 -40
- package/dist/lib/strategies/StrategyHandler.d.ts.map +1 -1
- package/dist/utils/cleanupOutdatedCaches.d.ts.map +1 -0
- package/dist/utils/clientsClaim.d.ts.map +1 -0
- package/dist/{parseRoute.d.ts → utils/parseRoute.d.ts} +3 -3
- package/dist/utils/parseRoute.d.ts.map +1 -0
- package/package.json +3 -3
- package/src/NavigationRoute.ts +5 -6
- package/src/PrecacheRoute.ts +2 -2
- package/src/RegExpRoute.ts +3 -3
- package/src/Route.ts +9 -9
- package/src/Serwist.ts +10 -6
- package/src/copyResponse.ts +7 -9
- package/src/index.internal.ts +4 -0
- package/src/index.legacy.ts +0 -15
- package/src/index.ts +4 -11
- package/src/legacy/PrecacheController.ts +2 -2
- package/src/legacy/Router.ts +1 -1
- package/src/legacy/handlePrecaching.ts +1 -1
- package/src/legacy/installSerwist.ts +1 -1
- package/src/lib/backgroundSync/StorableRequest.ts +4 -4
- package/src/lib/expiration/ExpirationPlugin.ts +1 -1
- package/src/lib/precaching/PrecacheFallbackPlugin.ts +0 -4
- package/src/lib/strategies/CacheFirst.ts +1 -1
- package/src/lib/strategies/CacheOnly.ts +2 -2
- package/src/lib/strategies/NetworkFirst.ts +2 -2
- package/src/lib/strategies/NetworkOnly.ts +2 -2
- package/src/lib/strategies/{PrecacheOnly.ts → PrecacheStrategy.ts} +5 -5
- package/src/lib/strategies/StaleWhileRevalidate.ts +1 -1
- package/src/lib/strategies/Strategy.ts +14 -16
- package/src/lib/strategies/StrategyHandler.ts +34 -40
- package/src/{cleanupOutdatedCaches.ts → utils/cleanupOutdatedCaches.ts} +3 -4
- package/src/{parseRoute.ts → utils/parseRoute.ts} +21 -23
- package/dist/cleanupOutdatedCaches.d.ts.map +0 -1
- package/dist/clientsClaim.d.ts.map +0 -1
- package/dist/lib/strategies/PrecacheOnly.d.ts.map +0 -1
- package/dist/parseRoute.d.ts.map +0 -1
- /package/dist/{cleanupOutdatedCaches.d.ts → utils/cleanupOutdatedCaches.d.ts} +0 -0
- /package/dist/{clientsClaim.d.ts → utils/clientsClaim.d.ts} +0 -0
- /package/src/{clientsClaim.ts → utils/clientsClaim.ts} +0 -0
|
@@ -15,7 +15,7 @@ export declare class StorableRequest {
|
|
|
15
15
|
private readonly _requestData;
|
|
16
16
|
/**
|
|
17
17
|
* Converts a Request object to a plain object that can be structured
|
|
18
|
-
* cloned or JSON
|
|
18
|
+
* cloned or stringified to JSON.
|
|
19
19
|
*
|
|
20
20
|
* @param request
|
|
21
21
|
* @returns
|
|
@@ -25,12 +25,12 @@ export declare class StorableRequest {
|
|
|
25
25
|
* Accepts an object of request data that can be used to construct a
|
|
26
26
|
* `Request` but can also be stored in IndexedDB.
|
|
27
27
|
*
|
|
28
|
-
* @param requestData An object of request data that includes the `url` plus any relevant
|
|
29
|
-
* [requestInit](https://fetch.spec.whatwg.org/#requestinit).
|
|
28
|
+
* @param requestData An object of request data that includes the `url` plus any relevant property of
|
|
29
|
+
* [`requestInit`](https://fetch.spec.whatwg.org/#requestinit).
|
|
30
30
|
*/
|
|
31
31
|
constructor(requestData: RequestData);
|
|
32
32
|
/**
|
|
33
|
-
* Returns a deep clone of the
|
|
33
|
+
* Returns a deep clone of the instance's `requestData` object.
|
|
34
34
|
*
|
|
35
35
|
* @returns
|
|
36
36
|
*/
|
|
@@ -45,7 +45,7 @@ export interface ExpirationPluginOptions {
|
|
|
45
45
|
* When using `maxEntries`, the least recently requested entry will be removed
|
|
46
46
|
* from the cache.
|
|
47
47
|
*
|
|
48
|
-
* @see https://serwist.pages.dev/docs/serwist/plugins/expiration-plugin
|
|
48
|
+
* @see https://serwist.pages.dev/docs/serwist/runtime-caching/plugins/expiration-plugin
|
|
49
49
|
*/
|
|
50
50
|
export declare class ExpirationPlugin implements SerwistPlugin {
|
|
51
51
|
private readonly _config;
|
|
@@ -29,10 +29,6 @@ export interface PrecacheFallbackPluginOptions {
|
|
|
29
29
|
* It does this by intercepting the `handlerDidError` plugin callback
|
|
30
30
|
* and returning a precached response, taking the expected revision parameter
|
|
31
31
|
* into account automatically.
|
|
32
|
-
*
|
|
33
|
-
* Unless you explicitly pass in a `PrecacheController` instance to the
|
|
34
|
-
* constructor, the default instance will be used. Generally speaking, most
|
|
35
|
-
* developers will end up using the default.
|
|
36
32
|
*/
|
|
37
33
|
export declare class PrecacheFallbackPlugin implements SerwistPlugin {
|
|
38
34
|
private readonly _fallbackUrls;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrecacheFallbackPlugin.d.ts","sourceRoot":"","sources":["../../../src/lib/precaching/PrecacheFallbackPlugin.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,EAAE,4BAA4B,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAElF,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,OAAO,EAAE,CAAC,KAAK,EAAE,4BAA4B,KAAK,OAAO,CAAC;IAC1D;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,6BAA6B;IAC5C;;;OAGG;IACH,YAAY,EAAE,CAAC,MAAM,GAAG,qBAAqB,CAAC,EAAE,CAAC;IACjD;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;CAClB;AAED
|
|
1
|
+
{"version":3,"file":"PrecacheFallbackPlugin.d.ts","sourceRoot":"","sources":["../../../src/lib/precaching/PrecacheFallbackPlugin.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,EAAE,4BAA4B,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAElF,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,OAAO,EAAE,CAAC,KAAK,EAAE,4BAA4B,KAAK,OAAO,CAAC;IAC1D;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,6BAA6B;IAC5C;;;OAGG;IACH,YAAY,EAAE,CAAC,MAAM,GAAG,qBAAqB,CAAC,EAAE,CAAC;IACjD;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;;GAOG;AACH,qBAAa,sBAAuB,YAAW,aAAa;IAC1D,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAqC;IACnE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAU;IAEnC;;;;OAIG;gBACS,EAAE,YAAY,EAAE,OAAO,EAAE,EAAE,6BAA6B;IAKpE;;;;OAIG;IACG,eAAe,CAAC,KAAK,EAAE,4BAA4B;CAgB1D"}
|
|
@@ -5,7 +5,7 @@ import type { StrategyHandler } from "./StrategyHandler.js";
|
|
|
5
5
|
* request strategy.
|
|
6
6
|
*
|
|
7
7
|
* A cache first strategy is useful for assets that have been revisioned,
|
|
8
|
-
* such as URLs like
|
|
8
|
+
* such as URLs like "/styles/example.a8f5f1.css", since they
|
|
9
9
|
* can be cached for long periods of time.
|
|
10
10
|
*
|
|
11
11
|
* If the network request fails, and there is no cache match, this will throw
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Strategy } from "./Strategy.js";
|
|
2
2
|
import type { StrategyHandler } from "./StrategyHandler.js";
|
|
3
3
|
/**
|
|
4
|
-
* An implementation of the [cache only](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#
|
|
4
|
+
* An implementation of the [cache only](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#cache_only)
|
|
5
5
|
* request strategy.
|
|
6
6
|
*
|
|
7
|
-
* This class is useful if you
|
|
7
|
+
* This class is useful if you already have your own precaching step.
|
|
8
8
|
*
|
|
9
9
|
* If there is no cache match, this will throw a `SerwistError` exception.
|
|
10
10
|
*/
|
|
@@ -8,11 +8,11 @@ export interface NetworkFirstOptions extends StrategyOptions {
|
|
|
8
8
|
networkTimeoutSeconds?: number;
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
|
-
* An implementation of the [network first](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#
|
|
11
|
+
* An implementation of the [network first](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#network_first_falling_back_to_cache)
|
|
12
12
|
* request strategy.
|
|
13
13
|
*
|
|
14
14
|
* By default, this strategy will cache responses with a 200 status code as
|
|
15
|
-
* well as [opaque responses](https://developer.chrome.com/docs/workbox/caching-resources-during-runtime/#
|
|
15
|
+
* well as [opaque responses](https://developer.chrome.com/docs/workbox/caching-resources-during-runtime/#opaque_responses).
|
|
16
16
|
* Opaque responses are are cross-origin requests where the response doesn't
|
|
17
17
|
* support [CORS](https://enable-cors.org/).
|
|
18
18
|
*
|
|
@@ -8,10 +8,10 @@ export interface NetworkOnlyOptions extends Omit<StrategyOptions, "cacheName" |
|
|
|
8
8
|
networkTimeoutSeconds?: number;
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
|
-
* An implementation of the [network only](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#
|
|
11
|
+
* An implementation of the [network only](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#network_only)
|
|
12
12
|
* request strategy.
|
|
13
13
|
*
|
|
14
|
-
* This class is useful if you
|
|
14
|
+
* This class is useful if you require specific requests to only be fulfilled from the network.
|
|
15
15
|
*
|
|
16
16
|
* If the network request fails, this will throw a `SerwistError` exception.
|
|
17
17
|
*/
|
|
@@ -16,7 +16,7 @@ interface PrecacheStrategyOptions extends StrategyOptions {
|
|
|
16
16
|
* Note: an instance of this class is created automatically when creating a
|
|
17
17
|
* `Serwist` instance; it's generally not necessary to create this yourself.
|
|
18
18
|
*/
|
|
19
|
-
export declare class
|
|
19
|
+
export declare class PrecacheStrategy extends Strategy {
|
|
20
20
|
private readonly _fallbackToNetwork;
|
|
21
21
|
static readonly defaultPrecacheCacheabilityPlugin: SerwistPlugin;
|
|
22
22
|
static readonly copyRedirectedCacheableResponsesPlugin: SerwistPlugin;
|
|
@@ -63,4 +63,4 @@ export declare class PrecacheOnly extends Strategy {
|
|
|
63
63
|
_useDefaultCacheabilityPluginIfNeeded(): void;
|
|
64
64
|
}
|
|
65
65
|
export {};
|
|
66
|
-
//# sourceMappingURL=
|
|
66
|
+
//# sourceMappingURL=PrecacheStrategy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrecacheStrategy.d.ts","sourceRoot":"","sources":["../../../src/lib/strategies/PrecacheStrategy.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAKpD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D,UAAU,uBAAwB,SAAQ,eAAe;IACvD;;;OAGG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;;;;;GAMG;AACH,qBAAa,gBAAiB,SAAQ,QAAQ;IAC5C,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAU;IAE7C,MAAM,CAAC,QAAQ,CAAC,iCAAiC,EAAE,aAAa,CAQ9D;IAEF,MAAM,CAAC,QAAQ,CAAC,sCAAsC,EAAE,aAAa,CAInE;IAEF;;OAEG;gBACS,OAAO,GAAE,uBAA4B;IAcjD;;;;;OAKG;IACG,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;IAkBtE,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;IAyE3E,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;IAqBnF;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,qCAAqC,IAAI,IAAI;CA4B9C"}
|
|
@@ -3,7 +3,7 @@ import { Strategy } from "./Strategy.js";
|
|
|
3
3
|
import type { StrategyHandler } from "./StrategyHandler.js";
|
|
4
4
|
/**
|
|
5
5
|
* An implementation of the
|
|
6
|
-
* [stale-while-revalidate](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#
|
|
6
|
+
* [stale-while-revalidate](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#stale_while_revalidate)
|
|
7
7
|
* request strategy.
|
|
8
8
|
*
|
|
9
9
|
* Resources are requested from both the cache and the network in parallel.
|
|
@@ -6,26 +6,25 @@ export interface StrategyOptions {
|
|
|
6
6
|
*/
|
|
7
7
|
cacheName?: string;
|
|
8
8
|
/**
|
|
9
|
-
* [Plugins](https://
|
|
10
|
-
* to use in conjunction with this caching strategy.
|
|
9
|
+
* [Plugins](https://serwist.pages.dev/docs/serwist/runtime-caching/plugins) to use in conjunction with this caching strategy.
|
|
11
10
|
*/
|
|
12
11
|
plugins?: SerwistPlugin[];
|
|
13
12
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
13
|
+
* Options passed to [non-navigation](https://github.com/GoogleChrome/workbox/issues/1796) `fetch()` calls made by
|
|
14
|
+
* this strategy.
|
|
16
15
|
*/
|
|
17
16
|
fetchOptions?: RequestInit;
|
|
18
17
|
/**
|
|
19
18
|
* The [`CacheQueryOptions`](https://w3c.github.io/ServiceWorker/#dictdef-cachequeryoptions)
|
|
20
|
-
*
|
|
19
|
+
* passed to any `cache.match()` or `cache.put()` call made by this strategy.
|
|
21
20
|
*/
|
|
22
21
|
matchOptions?: CacheQueryOptions;
|
|
23
22
|
}
|
|
24
23
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* fetch options and plugins are used (per the current strategy instance).
|
|
24
|
+
* Abstract class for implementing runtime caching strategies.
|
|
25
|
+
*
|
|
26
|
+
* Custom strategies should extend this class and leverage `StrategyHandler`, which will ensure all relevant cache options,
|
|
27
|
+
* fetch options, and plugins are used (per the current strategy instance), to perform all fetching and caching logic.
|
|
29
28
|
*/
|
|
30
29
|
export declare abstract class Strategy implements RouteHandlerObject {
|
|
31
30
|
cacheName: string;
|
|
@@ -45,7 +44,7 @@ export declare abstract class Strategy implements RouteHandlerObject {
|
|
|
45
44
|
*/
|
|
46
45
|
constructor(options?: StrategyOptions);
|
|
47
46
|
/**
|
|
48
|
-
*
|
|
47
|
+
* Performs a request strategy and returns a `Promise` that will resolve with
|
|
49
48
|
* a `Response`, invoking all relevant plugin callbacks.
|
|
50
49
|
*
|
|
51
50
|
* When a strategy instance is registered with a `Route`, this method is automatically
|
|
@@ -62,12 +61,11 @@ export declare abstract class Strategy implements RouteHandlerObject {
|
|
|
62
61
|
*/
|
|
63
62
|
handle(options: FetchEvent | HandlerCallbackOptions): Promise<Response>;
|
|
64
63
|
/**
|
|
65
|
-
* Similar to `
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
* `event.waitUntil()` as part of performing the strategy have completed.
|
|
64
|
+
* Similar to `handle()`, but instead of just returning a `Promise` that
|
|
65
|
+
* resolves to a `Response`, it will return an tuple of `[response, done]` promises,
|
|
66
|
+
* where `response` is equivalent to what `handle()` returns, and `done` is a
|
|
67
|
+
* `Promise` that will resolve once all promises added to `event.waitUntil()` as a part
|
|
68
|
+
* of performing the strategy have completed.
|
|
71
69
|
*
|
|
72
70
|
* You can await the `done` promise to ensure any extra work performed by
|
|
73
71
|
* the strategy (usually caching responses) completes successfully.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Strategy.d.ts","sourceRoot":"","sources":["../../../src/lib/strategies/Strategy.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAKhG,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD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EAAE,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;IAyCnG,cAAc,CAAC,YAAY,EAAE,OAAO,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;CAqCzI"}
|
|
@@ -1,9 +1,9 @@
|
|
|
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 Strategy instance
|
|
4
|
+
* A class created every time a `Strategy` instance calls `Strategy.handle` or
|
|
5
5
|
* `Strategy.handleAll` that wraps all fetch and cache actions around plugin callbacks
|
|
6
|
-
* and keeps track of when the strategy is "done" (i.e. all added `event.waitUntil()` promises
|
|
6
|
+
* and keeps track of when the strategy is "done" (i.e. when all added `event.waitUntil()` promises
|
|
7
7
|
* have resolved).
|
|
8
8
|
*/
|
|
9
9
|
export declare class StrategyHandler {
|
|
@@ -12,23 +12,23 @@ export declare class StrategyHandler {
|
|
|
12
12
|
*/
|
|
13
13
|
event: ExtendableEvent;
|
|
14
14
|
/**
|
|
15
|
-
* The request the strategy is
|
|
15
|
+
* The request the strategy is processing (passed to the strategy's
|
|
16
16
|
* `handle()` or `handleAll()` method).
|
|
17
17
|
*/
|
|
18
18
|
request: Request;
|
|
19
19
|
/**
|
|
20
20
|
* A `URL` instance of `request.url` (if passed to the strategy's
|
|
21
21
|
* `handle()` or `handleAll()` method).
|
|
22
|
-
* Note: the `url` param will be present if the strategy
|
|
22
|
+
* Note: the `url` param will be present if the strategy is invoked
|
|
23
23
|
* from a `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
|
-
* Note: the `
|
|
30
|
-
* from a `Route` object and
|
|
31
|
-
*
|
|
29
|
+
* Note: the `params` param will be present if the strategy is invoked
|
|
30
|
+
* from a `Route` object and that route's matcher returned a truthy value
|
|
31
|
+
* (it will be that value).
|
|
32
32
|
*/
|
|
33
33
|
params?: string[] | MapLikeObject;
|
|
34
34
|
private _cacheKeys;
|
|
@@ -52,8 +52,8 @@ export declare class StrategyHandler {
|
|
|
52
52
|
});
|
|
53
53
|
/**
|
|
54
54
|
* Fetches a given request (and invokes any applicable plugin callback
|
|
55
|
-
* methods)
|
|
56
|
-
* `plugins`
|
|
55
|
+
* methods), taking the `fetchOptions` (for non-navigation requests) and
|
|
56
|
+
* `plugins` provided to the `Strategy` object into account.
|
|
57
57
|
*
|
|
58
58
|
* The following plugin lifecycle methods are invoked when using this method:
|
|
59
59
|
* - `requestWillFetch()`
|
|
@@ -65,11 +65,10 @@ export declare class StrategyHandler {
|
|
|
65
65
|
*/
|
|
66
66
|
fetch(input: RequestInfo): Promise<Response>;
|
|
67
67
|
/**
|
|
68
|
-
* Calls `this.fetch()` and (in the background)
|
|
69
|
-
* the response generated by `this.fetch()`.
|
|
68
|
+
* Calls `this.fetch()` and (in the background) caches the generated response.
|
|
70
69
|
*
|
|
71
70
|
* The call to `this.cachePut()` automatically invokes `this.waitUntil()`,
|
|
72
|
-
* so you do not have to
|
|
71
|
+
* so you do not have to call `waitUntil()` yourself.
|
|
73
72
|
*
|
|
74
73
|
* @param input The request or URL to fetch and cache.
|
|
75
74
|
* @returns
|
|
@@ -77,26 +76,26 @@ export declare class StrategyHandler {
|
|
|
77
76
|
fetchAndCachePut(input: RequestInfo): Promise<Response>;
|
|
78
77
|
/**
|
|
79
78
|
* Matches a request from the cache (and invokes any applicable plugin
|
|
80
|
-
* callback
|
|
81
|
-
*
|
|
79
|
+
* callback method) using the `cacheName`, `matchOptions`, and `plugins`
|
|
80
|
+
* provided to the `Strategy` object.
|
|
82
81
|
*
|
|
83
|
-
* The following
|
|
84
|
-
* - cacheKeyWillByUsed
|
|
85
|
-
* - cachedResponseWillByUsed
|
|
82
|
+
* The following lifecycle methods are invoked when using this method:
|
|
83
|
+
* - `cacheKeyWillByUsed`
|
|
84
|
+
* - `cachedResponseWillByUsed`
|
|
86
85
|
*
|
|
87
|
-
* @param key The Request or URL to use as the cache key.
|
|
86
|
+
* @param key The `Request` or `URL` object to use as the cache key.
|
|
88
87
|
* @returns A matching response, if found.
|
|
89
88
|
*/
|
|
90
89
|
cacheMatch(key: RequestInfo): Promise<Response | undefined>;
|
|
91
90
|
/**
|
|
92
|
-
* Puts a request/response pair
|
|
93
|
-
* plugin callback
|
|
94
|
-
* the
|
|
91
|
+
* Puts a request/response pair into the cache (and invokes any applicable
|
|
92
|
+
* plugin callback method) using the `cacheName` and `plugins` provided to
|
|
93
|
+
* the `Strategy` object.
|
|
95
94
|
*
|
|
96
95
|
* The following plugin lifecycle methods are invoked when using this method:
|
|
97
|
-
* - cacheKeyWillByUsed
|
|
98
|
-
* - cacheWillUpdate
|
|
99
|
-
* - cacheDidUpdate
|
|
96
|
+
* - `cacheKeyWillByUsed`
|
|
97
|
+
* - `cacheWillUpdate`
|
|
98
|
+
* - `cacheDidUpdate`
|
|
100
99
|
*
|
|
101
100
|
* @param key The request or URL to use as the cache key.
|
|
102
101
|
* @param response The response to cache.
|
|
@@ -105,11 +104,11 @@ export declare class StrategyHandler {
|
|
|
105
104
|
*/
|
|
106
105
|
cachePut(key: RequestInfo, response: Response): Promise<boolean>;
|
|
107
106
|
/**
|
|
108
|
-
* Checks the
|
|
109
|
-
*
|
|
107
|
+
* Checks the `plugins` provided to the `Strategy` object for `cacheKeyWillBeUsed`
|
|
108
|
+
* callbacks and executes found callbacks in sequence. The final `Request`
|
|
110
109
|
* object returned by the last plugin is treated as the cache key for cache
|
|
111
110
|
* reads and/or writes. If no `cacheKeyWillBeUsed` plugin callbacks have
|
|
112
|
-
* been registered, the passed request is returned unmodified
|
|
111
|
+
* been registered, the passed request is returned unmodified.
|
|
113
112
|
*
|
|
114
113
|
* @param request
|
|
115
114
|
* @param mode
|
|
@@ -117,7 +116,7 @@ export declare class StrategyHandler {
|
|
|
117
116
|
*/
|
|
118
117
|
getCacheKey(request: Request, mode: "read" | "write"): Promise<Request>;
|
|
119
118
|
/**
|
|
120
|
-
* Returns true if the strategy has at least one plugin with the given
|
|
119
|
+
* Returns `true` if the strategy has at least one plugin with the given
|
|
121
120
|
* callback.
|
|
122
121
|
*
|
|
123
122
|
* @param name The name of the callback to check for.
|
|
@@ -126,8 +125,7 @@ export declare class StrategyHandler {
|
|
|
126
125
|
hasCallback<C extends keyof SerwistPlugin>(name: C): boolean;
|
|
127
126
|
/**
|
|
128
127
|
* Runs all plugin callbacks matching the given name, in order, passing the
|
|
129
|
-
* given param object
|
|
130
|
-
* argument.
|
|
128
|
+
* given param object as the only argument.
|
|
131
129
|
*
|
|
132
130
|
* Note: since this method runs all plugins, it's not suitable for cases
|
|
133
131
|
* where the return value of a callback needs to be applied prior to calling
|
|
@@ -139,10 +137,7 @@ export declare class StrategyHandler {
|
|
|
139
137
|
*/
|
|
140
138
|
runCallbacks<C extends keyof NonNullable<SerwistPlugin>>(name: C, param: Omit<SerwistPluginCallbackParam[C], "state">): Promise<void>;
|
|
141
139
|
/**
|
|
142
|
-
* Accepts a callback and returns an iterable of matching plugin callbacks
|
|
143
|
-
* where each callback is wrapped with the current handler state (i.e. when
|
|
144
|
-
* you call each callback, whatever object parameter you pass it will
|
|
145
|
-
* be merged with the plugin's current state).
|
|
140
|
+
* Accepts a callback name and returns an iterable of matching plugin callbacks.
|
|
146
141
|
*
|
|
147
142
|
* @param name The name fo the callback to run
|
|
148
143
|
* @returns
|
|
@@ -163,17 +158,16 @@ export declare class StrategyHandler {
|
|
|
163
158
|
waitUntil<T>(promise: Promise<T>): Promise<T>;
|
|
164
159
|
/**
|
|
165
160
|
* Returns a promise that resolves once all promises passed to
|
|
166
|
-
* `
|
|
161
|
+
* `this.waitUntil()` have settled.
|
|
167
162
|
*
|
|
168
163
|
* Note: any work done after `doneWaiting()` settles should be manually
|
|
169
|
-
* passed to an event's `waitUntil()` method (not this
|
|
170
|
-
*
|
|
171
|
-
* prior to your work completing.
|
|
164
|
+
* passed to an event's `waitUntil()` method (not `this.waitUntil()`), otherwise
|
|
165
|
+
* the service worker thread may be killed prior to your work completing.
|
|
172
166
|
*/
|
|
173
167
|
doneWaiting(): Promise<void>;
|
|
174
168
|
/**
|
|
175
169
|
* Stops running the strategy and immediately resolves any pending
|
|
176
|
-
* `waitUntil()`
|
|
170
|
+
* `waitUntil()` promise.
|
|
177
171
|
*/
|
|
178
172
|
destroy(): void;
|
|
179
173
|
/**
|
|
@@ -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;AAM9C;;;;;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;;;;;;OAMG;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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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cleanupOutdatedCaches.d.ts","sourceRoot":"","sources":["../../src/utils/cleanupOutdatedCaches.ts"],"names":[],"mappings":"AAcA;;;GAGG;AACH,eAAO,MAAM,qBAAqB,eAAgB,MAAM,KAAG,IAY1D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clientsClaim.d.ts","sourceRoot":"","sources":["../../src/utils/clientsClaim.ts"],"names":[],"mappings":"AAWA;;;GAGG;AACH,eAAO,MAAM,YAAY,QAAO,IAE/B,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Route } from "
|
|
2
|
-
import type { HTTPMethod } from "
|
|
3
|
-
import type { RouteHandler, RouteMatchCallback } from "
|
|
1
|
+
import { Route } from "../Route.js";
|
|
2
|
+
import type { HTTPMethod } from "../constants.js";
|
|
3
|
+
import type { RouteHandler, RouteMatchCallback } from "../types.js";
|
|
4
4
|
/**
|
|
5
5
|
* Parses a `RegExp`, string, or function with a caching strategy into a `Route`. This is for
|
|
6
6
|
* when you want to create a `Route`, but you don't want to register it just yet: sometimes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseRoute.d.ts","sourceRoot":"","sources":["../../src/utils/parseRoute.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAIpE;;;;;;;;;;GAUG;AACH,eAAO,MAAM,UAAU,YAAa,MAAM,GAAG,MAAM,GAAG,kBAAkB,GAAG,KAAK,YAAY,YAAY,WAAW,UAAU,KAAG,KAyD/H,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "serwist",
|
|
3
|
-
"version": "9.0.0
|
|
3
|
+
"version": "9.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A Swiss Army knife for service workers.",
|
|
6
6
|
"files": [
|
|
@@ -51,8 +51,8 @@
|
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"rollup": "4.14.3",
|
|
53
53
|
"typescript": "5.5.0-dev.20240415",
|
|
54
|
-
"@serwist/configs": "9.0.0
|
|
55
|
-
"@serwist/utils": "9.0.0
|
|
54
|
+
"@serwist/configs": "9.0.0",
|
|
55
|
+
"@serwist/utils": "9.0.0"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"typescript": ">=5.0.0"
|
package/src/NavigationRoute.ts
CHANGED
|
@@ -27,10 +27,9 @@ export interface NavigationRouteMatchOptions {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
|
-
* NavigationRoute makes it easy to create a `Route` that matches
|
|
31
|
-
* [navigation requests](https://developers.google.com/web/fundamentals/primers/service-workers/high-performance-loading#first_what_are_navigation_requests).
|
|
30
|
+
* `NavigationRoute` makes it easy to create a `Route` object that matches navigation requests.
|
|
32
31
|
*
|
|
33
|
-
* It will only match incoming Requests whose [mode](https://fetch.spec.whatwg.org/#concept-request-mode) is set to `navigate`.
|
|
32
|
+
* It will only match incoming Requests whose [`mode`](https://fetch.spec.whatwg.org/#concept-request-mode) is set to `"navigate"`.
|
|
34
33
|
*
|
|
35
34
|
* You can optionally only apply this route to a subset of navigation requests
|
|
36
35
|
* by using one or both of the `denylist` and `allowlist` parameters.
|
|
@@ -40,8 +39,8 @@ export class NavigationRoute extends Route {
|
|
|
40
39
|
private readonly _denylist: RegExp[];
|
|
41
40
|
|
|
42
41
|
/**
|
|
43
|
-
* If both `denylist` and `allowlist` are provided,
|
|
44
|
-
* take precedence
|
|
42
|
+
* If both `denylist` and `allowlist` are provided, `denylist` will
|
|
43
|
+
* take precedence.
|
|
45
44
|
*
|
|
46
45
|
* The regular expressions in `allowlist` and `denylist`
|
|
47
46
|
* are matched against the concatenated
|
|
@@ -54,7 +53,7 @@ export class NavigationRoute extends Route {
|
|
|
54
53
|
* [complex RegExps](https://github.com/GoogleChrome/workbox/issues/3077),
|
|
55
54
|
* or else your users may see delays when navigating your site.
|
|
56
55
|
*
|
|
57
|
-
* @param handler A callback function that returns a Promise resulting in a Response
|
|
56
|
+
* @param handler A callback function that returns a `Promise` resulting in a `Response`.
|
|
58
57
|
* @param options
|
|
59
58
|
*/
|
|
60
59
|
constructor(handler: RouteHandler, { allowlist = [/./], denylist = [] }: NavigationRouteMatchOptions = {}) {
|
package/src/PrecacheRoute.ts
CHANGED
|
@@ -20,8 +20,8 @@ import { logger } from "./utils/logger.js";
|
|
|
20
20
|
*/
|
|
21
21
|
export class PrecacheRoute extends Route {
|
|
22
22
|
/**
|
|
23
|
-
* @param serwist A `
|
|
24
|
-
*
|
|
23
|
+
* @param serwist A `Serwist` instance used to both match requests
|
|
24
|
+
* and respond to fetch events.
|
|
25
25
|
* @param options Options to control how requests are matched
|
|
26
26
|
* against the list of precached URLs.
|
|
27
27
|
*/
|
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
|
-
* `RegExpRoute` makes it easy to create a
|
|
16
|
+
* `RegExpRoute` makes it easy to create a `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
|
|
@@ -26,8 +26,8 @@ export class RegExpRoute extends Route {
|
|
|
26
26
|
* the captured values will be passed to the `params` argument.
|
|
27
27
|
*
|
|
28
28
|
* @param regExp The regular expression to match against URLs.
|
|
29
|
-
* @param handler A callback function that returns a Promise resulting in a Response
|
|
30
|
-
* @param method The HTTP method to match the
|
|
29
|
+
* @param handler A callback function that returns a `Promise` resulting in a `Response`.
|
|
30
|
+
* @param method The HTTP method to match the 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,10 +13,10 @@ 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,
|
|
17
|
-
* The
|
|
18
|
-
* request by returning a
|
|
19
|
-
* is called when
|
|
16
|
+
* A `Route` consists of a pair of callback functions, `match and `handler.
|
|
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 `Promise` that resolves
|
|
20
20
|
* to a `Response`.
|
|
21
21
|
*/
|
|
22
22
|
export class Route {
|
|
@@ -29,11 +29,11 @@ export class Route {
|
|
|
29
29
|
* Constructor for Route class.
|
|
30
30
|
*
|
|
31
31
|
* @param match A callback function that determines whether the
|
|
32
|
-
* route matches a given `fetch` event by returning a
|
|
33
|
-
* @param handler A callback function that returns a Promise resolving
|
|
34
|
-
* to a Response
|
|
35
|
-
* @param method The HTTP method to match the
|
|
36
|
-
* to GET
|
|
32
|
+
* route matches a given `fetch` event by returning a truthy value.
|
|
33
|
+
* @param handler A callback function that returns a `Promise` resolving
|
|
34
|
+
* to a `Response`.
|
|
35
|
+
* @param method The HTTP method to match the route against. Defaults
|
|
36
|
+
* to `GET`.
|
|
37
37
|
*/
|
|
38
38
|
constructor(match: RouteMatchCallback, handler: RouteHandler, method: HTTPMethod = defaultMethod) {
|
|
39
39
|
if (process.env.NODE_ENV !== "production") {
|
package/src/Serwist.ts
CHANGED
|
@@ -2,16 +2,13 @@ import { parallel } from "@serwist/utils";
|
|
|
2
2
|
import { NavigationRoute } from "./NavigationRoute.js";
|
|
3
3
|
import { PrecacheRoute } from "./PrecacheRoute.js";
|
|
4
4
|
import type { Route } from "./Route.js";
|
|
5
|
-
import { cleanupOutdatedCaches as cleanupOutdatedCachesImpl } from "./cleanupOutdatedCaches.js";
|
|
6
|
-
import { clientsClaim as clientsClaimImpl } from "./clientsClaim.js";
|
|
7
5
|
import { type HTTPMethod, defaultMethod } from "./constants.js";
|
|
8
6
|
import { disableDevLogs as disableDevLogsImpl } from "./disableDevLogs.js";
|
|
9
7
|
import { type GoogleAnalyticsInitializeOptions, initializeGoogleAnalytics } from "./lib/googleAnalytics/initializeGoogleAnalytics.js";
|
|
10
8
|
import { type PrecacheFallbackEntry, PrecacheFallbackPlugin } from "./lib/precaching/PrecacheFallbackPlugin.js";
|
|
11
|
-
import {
|
|
9
|
+
import { PrecacheStrategy } from "./lib/strategies/PrecacheStrategy.js";
|
|
12
10
|
import { Strategy } from "./lib/strategies/Strategy.js";
|
|
13
11
|
import { enableNavigationPreload } from "./navigationPreload.js";
|
|
14
|
-
import { parseRoute } from "./parseRoute.js";
|
|
15
12
|
import { setCacheNameDetails } from "./setCacheNameDetails.js";
|
|
16
13
|
import type {
|
|
17
14
|
RouteHandler,
|
|
@@ -29,10 +26,13 @@ import { PrecacheInstallReportPlugin } from "./utils/PrecacheInstallReportPlugin
|
|
|
29
26
|
import { SerwistError } from "./utils/SerwistError.js";
|
|
30
27
|
import { assert } from "./utils/assert.js";
|
|
31
28
|
import { cacheNames as privateCacheNames } from "./utils/cacheNames.js";
|
|
29
|
+
import { cleanupOutdatedCaches as cleanupOutdatedCachesImpl } from "./utils/cleanupOutdatedCaches.js";
|
|
30
|
+
import { clientsClaim as clientsClaimImpl } from "./utils/clientsClaim.js";
|
|
32
31
|
import { createCacheKey } from "./utils/createCacheKey.js";
|
|
33
32
|
import { getFriendlyURL } from "./utils/getFriendlyURL.js";
|
|
34
33
|
import { logger } from "./utils/logger.js";
|
|
35
34
|
import { normalizeHandler } from "./utils/normalizeHandler.js";
|
|
35
|
+
import { parseRoute } from "./utils/parseRoute.js";
|
|
36
36
|
import { printCleanupDetails } from "./utils/printCleanupDetails.js";
|
|
37
37
|
import { printInstallDetails } from "./utils/printInstallDetails.js";
|
|
38
38
|
import { waitUntil } from "./utils/waitUntil.js";
|
|
@@ -193,7 +193,7 @@ export class Serwist {
|
|
|
193
193
|
fallbacks,
|
|
194
194
|
}: SerwistOptions = {}) {
|
|
195
195
|
this._concurrentPrecaching = precacheOptions?.concurrency ?? 10;
|
|
196
|
-
this._precacheStrategy = new
|
|
196
|
+
this._precacheStrategy = new PrecacheStrategy({
|
|
197
197
|
cacheName: privateCacheNames.getPrecacheName(precacheOptions?.cacheName),
|
|
198
198
|
plugins: [...(precacheOptions?.plugins ?? []), new PrecacheCacheKeyPlugin({ precacheController: this })],
|
|
199
199
|
fallbackToNetwork: precacheOptions?.fallbackToNetwork,
|
|
@@ -532,7 +532,11 @@ export class Serwist {
|
|
|
532
532
|
* @param method The HTTP method to match the Route against. Defaults to `'GET'`.
|
|
533
533
|
* @returns The generated `Route`.
|
|
534
534
|
*/
|
|
535
|
-
registerCapture
|
|
535
|
+
registerCapture<T extends RegExp | string | RouteMatchCallback | Route>(
|
|
536
|
+
capture: T,
|
|
537
|
+
handler?: T extends Route ? never : RouteHandler,
|
|
538
|
+
method?: T extends Route ? never : HTTPMethod,
|
|
539
|
+
): Route {
|
|
536
540
|
const route = parseRoute(capture, handler, method);
|
|
537
541
|
this.registerRoute(route);
|
|
538
542
|
return route;
|
package/src/copyResponse.ts
CHANGED
|
@@ -11,21 +11,19 @@ import { canConstructResponseFromBodyStream } from "./utils/canConstructResponse
|
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Allows developers to copy a response and modify its `headers`, `status`,
|
|
14
|
-
* or `statusText` values (the
|
|
15
|
-
*
|
|
16
|
-
* object in the constructor).
|
|
14
|
+
* or `statusText` values (the [valid options](https://developer.mozilla.org/en-US/docs/Web/API/Response/Response#options)
|
|
15
|
+
* when constructing a `Response` object).
|
|
17
16
|
* To modify these values, pass a function as the second argument. That
|
|
18
|
-
* function will be invoked with
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* either modify the passed parameter(s) and return it, or return a totally
|
|
17
|
+
* function will be invoked with the options of the initial `Response` object.
|
|
18
|
+
* The return value of this function will be used as the options for the new `Response` object.
|
|
19
|
+
* To change the values either modify the passed parameter(s) and return it or return a totally
|
|
22
20
|
* new object.
|
|
23
21
|
*
|
|
24
22
|
* This method is intentionally limited to same-origin responses, regardless of
|
|
25
23
|
* whether CORS was used or not.
|
|
26
24
|
*
|
|
27
|
-
* @param response
|
|
28
|
-
* @param modifier
|
|
25
|
+
* @param response The initial response.
|
|
26
|
+
* @param modifier The function used to modify the options of the `Response` object.
|
|
29
27
|
*/
|
|
30
28
|
export const copyResponse = async (response: Response, modifier?: (responseInit: ResponseInit) => ResponseInit): Promise<Response> => {
|
|
31
29
|
let origin = null;
|