@serwist/strategies 9.0.0-preview.12 → 9.0.0-preview.13

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.
@@ -1,7 +1,7 @@
1
1
  import { Strategy } from "./Strategy.js";
2
2
  import type { StrategyHandler } from "./StrategyHandler.js";
3
3
  /**
4
- * An implementation of the [cache first](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#cache-first-falling-back-to-network)
4
+ * An implementation of the [cache first](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#cache_first_falling_back_to_network)
5
5
  * request strategy.
6
6
  *
7
7
  * A cache first strategy is useful for assets that have been revisioned,
@@ -7,20 +7,21 @@ export interface NetworkFirstOptions extends StrategyOptions {
7
7
  */
8
8
  networkTimeoutSeconds?: number;
9
9
  }
10
+ /**
11
+ * An implementation of the [network first](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#network-first-falling-back-to-cache)
12
+ * request strategy.
13
+ *
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/#opaque-responses).
16
+ * Opaque responses are are cross-origin requests where the response doesn't
17
+ * support [CORS](https://enable-cors.org/).
18
+ *
19
+ * If the network request fails, and there is no cache match, this will throw
20
+ * a `SerwistError` exception.
21
+ */
10
22
  export declare class NetworkFirst extends Strategy {
11
23
  private readonly _networkTimeoutSeconds;
12
24
  /**
13
- * An implementation of the [network first](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#network-first-falling-back-to-cache)
14
- * request strategy.
15
- *
16
- * By default, this strategy will cache responses with a 200 status code as
17
- * well as [opaque responses](https://developer.chrome.com/docs/workbox/caching-resources-during-runtime/#opaque-responses).
18
- * Opaque responses are are cross-origin requests where the response doesn't
19
- * support [CORS](https://enable-cors.org/).
20
- *
21
- * If the network request fails, and there is no cache match, this will throw
22
- * a `SerwistError` exception.
23
- *
24
25
  * @param options
25
26
  * This option can be used to combat
26
27
  * "[lie-fi](https://developers.google.com/web/fundamentals/performance/poor-connectivity/#lie-fi)"
@@ -1 +1 @@
1
- {"version":3,"file":"NetworkFirst.d.ts","sourceRoot":"","sources":["../src/NetworkFirst.ts"],"names":[],"mappings":"AAUA,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;AAI5D,MAAM,WAAW,mBAAoB,SAAQ,eAAe;IAC1D;;OAEG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED,qBAAa,YAAa,SAAQ,QAAQ;IACxC,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAS;IAEhD;;;;;;;;;;;;;;;;OAgBG;gBACS,OAAO,GAAE,mBAAwB;IAsB7C;;;;;OAKG;IACG,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;IAgE5E;;;;OAIG;IACH,OAAO,CAAC,kBAAkB;IA8B1B;;;;;;;;;OASG;IACG,kBAAkB,CAAC,EACvB,SAAS,EACT,OAAO,EACP,IAAI,EACJ,OAAO,GACR,EAAE;QACD,OAAO,EAAE,OAAO,CAAC;QACjB,IAAI,EAAE,GAAG,EAAE,CAAC;QACZ,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,OAAO,EAAE,eAAe,CAAC;KAC1B,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC;CAqClC"}
1
+ {"version":3,"file":"NetworkFirst.d.ts","sourceRoot":"","sources":["../src/NetworkFirst.ts"],"names":[],"mappings":"AAUA,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;AAI5D,MAAM,WAAW,mBAAoB,SAAQ,eAAe;IAC1D;;OAEG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,YAAa,SAAQ,QAAQ;IACxC,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAS;IAChD;;;;;OAKG;gBACS,OAAO,GAAE,mBAAwB;IAsB7C;;;;;OAKG;IACG,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;IAgE5E;;;;OAIG;IACH,OAAO,CAAC,kBAAkB;IA8B1B;;;;;;;;;OASG;IACG,kBAAkB,CAAC,EACvB,SAAS,EACT,OAAO,EACP,IAAI,EACJ,OAAO,GACR,EAAE;QACD,OAAO,EAAE,OAAO,CAAC;QACjB,IAAI,EAAE,GAAG,EAAE,CAAC;QACZ,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,OAAO,EAAE,eAAe,CAAC;KAC1B,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC;CAqClC"}
@@ -7,16 +7,17 @@ export interface NetworkOnlyOptions extends Omit<StrategyOptions, "cacheName" |
7
7
  */
8
8
  networkTimeoutSeconds?: number;
9
9
  }
10
+ /**
11
+ * An implementation of the [network only](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#network-only)
12
+ * request strategy.
13
+ *
14
+ * This class is useful if you want to take advantage of any Serwist plugin.
15
+ *
16
+ * If the network request fails, this will throw a `SerwistError` exception.
17
+ */
10
18
  export declare class NetworkOnly extends Strategy {
11
19
  private readonly _networkTimeoutSeconds;
12
20
  /**
13
- * An implementation of the [network only](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#network-only)
14
- * request strategy.
15
- *
16
- * This class is useful if you want to take advantage of any Serwist plugin.
17
- *
18
- * If the network request fails, this will throw a `SerwistError` exception.
19
- *
20
21
  * @param options
21
22
  */
22
23
  constructor(options?: NetworkOnlyOptions);
@@ -1 +1 @@
1
- {"version":3,"file":"NetworkOnly.d.ts","sourceRoot":"","sources":["../src/NetworkOnly.ts"],"names":[],"mappings":"AAUA,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;AAG5D,MAAM,WAAW,kBAAmB,SAAQ,IAAI,CAAC,eAAe,EAAE,WAAW,GAAG,cAAc,CAAC;IAC7F;;OAEG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED,qBAAa,WAAY,SAAQ,QAAQ;IACvC,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAS;IAEhD;;;;;;;;;OASG;gBACS,OAAO,GAAE,kBAAuB;IAM5C;;;;;OAKG;IACG,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;CA+C7E"}
1
+ {"version":3,"file":"NetworkOnly.d.ts","sourceRoot":"","sources":["../src/NetworkOnly.ts"],"names":[],"mappings":"AAUA,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;AAG5D,MAAM,WAAW,kBAAmB,SAAQ,IAAI,CAAC,eAAe,EAAE,WAAW,GAAG,cAAc,CAAC;IAC7F;;OAEG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED;;;;;;;GAOG;AACH,qBAAa,WAAY,SAAQ,QAAQ;IACvC,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAS;IAEhD;;OAEG;gBACS,OAAO,GAAE,kBAAuB;IAM5C;;;;;OAKG;IACG,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;CA+C7E"}
@@ -1,25 +1,26 @@
1
1
  import type { StrategyOptions } from "./Strategy.js";
2
2
  import { Strategy } from "./Strategy.js";
3
3
  import type { StrategyHandler } from "./StrategyHandler.js";
4
+ /**
5
+ * An implementation of the
6
+ * [stale-while-revalidate](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#stale-while-revalidate)
7
+ * request strategy.
8
+ *
9
+ * Resources are requested from both the cache and the network in parallel.
10
+ * The strategy will respond with the cached version if available, otherwise
11
+ * wait for the network response. The cache is updated with the network response
12
+ * with each successful request.
13
+ *
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/#opaque-responses).
16
+ * Opaque responses are cross-origin requests where the response doesn't
17
+ * support [CORS](https://enable-cors.org/).
18
+ *
19
+ * If the network request fails, and there is no cache match, this will throw
20
+ * a `SerwistError` exception.
21
+ */
4
22
  export declare class StaleWhileRevalidate extends Strategy {
5
23
  /**
6
- * An implementation of the
7
- * [stale-while-revalidate](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#stale-while-revalidate)
8
- * request strategy.
9
- *
10
- * Resources are requested from both the cache and the network in parallel.
11
- * The strategy will respond with the cached version if available, otherwise
12
- * wait for the network response. The cache is updated with the network response
13
- * with each successful request.
14
- *
15
- * By default, this strategy will cache responses with a 200 status code as
16
- * well as [opaque responses](https://developer.chrome.com/docs/workbox/caching-resources-during-runtime/#opaque-responses).
17
- * Opaque responses are cross-origin requests where the response doesn't
18
- * support [CORS](https://enable-cors.org/).
19
- *
20
- * If the network request fails, and there is no cache match, this will throw
21
- * a `SerwistError` exception.
22
- *
23
24
  * @param options
24
25
  */
25
26
  constructor(options?: StrategyOptions);
@@ -1 +1 @@
1
- {"version":3,"file":"StaleWhileRevalidate.d.ts","sourceRoot":"","sources":["../src/StaleWhileRevalidate.ts"],"names":[],"mappings":"AAUA,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;AAI5D,qBAAa,oBAAqB,SAAQ,QAAQ;IAChD;;;;;;;;;;;;;;;;;;;OAmBG;gBACS,OAAO,GAAE,eAAoB;IAUzC;;;;;OAKG;IACG,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;CAsD7E"}
1
+ {"version":3,"file":"StaleWhileRevalidate.d.ts","sourceRoot":"","sources":["../src/StaleWhileRevalidate.ts"],"names":[],"mappings":"AAUA,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;AAI5D;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,oBAAqB,SAAQ,QAAQ;IAChD;;OAEG;gBACS,OAAO,GAAE,eAAoB;IAUzC;;;;;OAKG;IACG,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;CAsD7E"}
@@ -6,7 +6,7 @@ export interface StrategyOptions {
6
6
  */
7
7
  cacheName?: string;
8
8
  /**
9
- * [Plugins](https://developers.google.com/web/tools/workbox/guides/using-plugins)
9
+ * [Plugins](https://developer.chrome.com/docs/workbox/using-plugins)
10
10
  * to use in conjunction with this caching strategy.
11
11
  */
12
12
  plugins?: SerwistPlugin[];
@@ -1 +1 @@
1
- {"version":3,"file":"Strategy.d.ts","sourceRoot":"","sources":["../src/Strategy.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAG/F,OAAO,EAAE,eAAe,EAAE,MA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,EAAE,OAAO,EAAE,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;CAqCzI"}
@@ -1,4 +1,4 @@
1
- import type { HandlerCallbackOptions, SerwistPlugin, SerwistPluginCallbackParam } from "@serwist/core";
1
+ import type { HandlerCallbackOptions, MapLikeObject, SerwistPlugin, SerwistPluginCallbackParam } from "@serwist/core";
2
2
  import type { Strategy } from "./Strategy.js";
3
3
  /**
4
4
  * A class created every time a Strategy instance instance calls `Strategy.handle` or
@@ -7,6 +7,10 @@ import type { Strategy } from "./Strategy.js";
7
7
  * have resolved).
8
8
  */
9
9
  export declare class StrategyHandler {
10
+ /**
11
+ * The event associated with this request.
12
+ */
13
+ event: ExtendableEvent;
10
14
  /**
11
15
  * The request the strategy is performing (passed to the strategy's
12
16
  * `handle()` or `handleAll()` method).
@@ -19,10 +23,6 @@ export declare class StrategyHandler {
19
23
  * from a `@serwist/routing.Route` object.
20
24
  */
21
25
  url?: URL;
22
- /**
23
- * The event associated with this request.
24
- */
25
- event: ExtendableEvent;
26
26
  /**
27
27
  * A `param` value (if passed to the strategy's
28
28
  * `handle()` or `handleAll()` method).
@@ -30,11 +30,11 @@ export declare class StrategyHandler {
30
30
  * from a `@serwist/routing.Route` object and the `@serwist/strategies.matchCallback`
31
31
  * returned a truthy value (it will be that value).
32
32
  */
33
- params?: any;
33
+ params?: string[] | MapLikeObject;
34
34
  private _cacheKeys;
35
35
  private readonly _strategy;
36
- private readonly _extendLifetimePromises;
37
36
  private readonly _handlerDeferred;
37
+ private readonly _extendLifetimePromises;
38
38
  private readonly _plugins;
39
39
  private readonly _pluginStateMap;
40
40
  /**
@@ -47,7 +47,9 @@ export declare class StrategyHandler {
47
47
  * @param strategy
48
48
  * @param options
49
49
  */
50
- constructor(strategy: Strategy, options: HandlerCallbackOptions);
50
+ constructor(strategy: Strategy, options: HandlerCallbackOptions & {
51
+ request: HandlerCallbackOptions["request"] & Request;
52
+ });
51
53
  /**
52
54
  * Fetches a given request (and invokes any applicable plugin callback
53
55
  * methods) using the `fetchOptions` (for non-navigation requests) and
@@ -1 +1 @@
1
- {"version":3,"file":"StrategyHandler.d.ts","sourceRoot":"","sources":["../src/StrategyHandler.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,sBAAsB,EAAiB,aAAa,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAC;AAYtH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAM9C;;;;;GAKG;AACH,qBAAa,eAAe;IAC1B;;;OAGG;IACI,OAAO,EAAG,OAAO,CAAC;IACzB;;;;;OAKG;IACI,GAAG,CAAC,EAAE,GAAG,CAAC;IACjB;;OAEG;IACI,KAAK,EAAE,eAAe,CAAC;IAC9B;;;;;;OAMG;IACI,MAAM,CAAC,EAAE,GAAG,CAAC;IAEpB,OAAO,CAAC,UAAU,CAA+B;IAEjD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAW;IACrC,OAAO,CAAC,QAAQ,CAAC,uBAAuB,CAAiB;IACzD,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAgB;IACjD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAkB;IAC3C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAoC;IAEpE;;;;;;;;;OASG;gBACS,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,sBAAsB;IA4B/D;;;;;;;;;;;;OAYG;IACG,KAAK,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC;IAyElD;;;;;;;;;OASG;IACG,gBAAgB,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC;IAS7D;;;;;;;;;;;OAWG;IACG,UAAU,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC;IA+BjE;;;;;;;;;;;;;;OAcG;IACG,QAAQ,CAAC,GAAG,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,GA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C,GAAG,OAAO;IAS5D;;;;;;;;;;;;OAYG;IACG,YAAY,CAAC,CAAC,SAAS,MAAM,WAAW,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,0BAA0B,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ3I;;;;;;;;OAQG;IACF,gBAAgB,CAAC,CAAC,SAAS,MAAM,aAAa,EAAE,IAAI,EAAE,CAAC,GAAG,SAAS,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;IAgBnG;;;;;;;;;;;OAWG;IACH,SAAS,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAK7C;;;;;;;;OAQG;IACG,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAOlC;;;OAGG;IACH,OAAO,IAAI,IAAI;IAIf;;;;;;;OAOG;IACG,0BAA0B,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC;CAuCpF"}
package/dist/index.js CHANGED
@@ -4,14 +4,14 @@ function toRequest(input) {
4
4
  return typeof input === "string" ? new Request(input) : input;
5
5
  }
6
6
  class StrategyHandler {
7
+ event;
7
8
  request;
8
9
  url;
9
- event;
10
10
  params;
11
11
  _cacheKeys = {};
12
12
  _strategy;
13
- _extendLifetimePromises;
14
13
  _handlerDeferred;
14
+ _extendLifetimePromises;
15
15
  _plugins;
16
16
  _pluginStateMap;
17
17
  constructor(strategy, options){
@@ -22,9 +22,19 @@ class StrategyHandler {
22
22
  funcName: "constructor",
23
23
  paramName: "options.event"
24
24
  });
25
+ assert.isInstance(options.request, Request, {
26
+ moduleName: "@serwist/strategies",
27
+ className: "StrategyHandler",
28
+ funcName: "constructor",
29
+ paramName: "options.request"
30
+ });
25
31
  }
26
- Object.assign(this, options);
27
32
  this.event = options.event;
33
+ this.request = options.request;
34
+ if (options.url) {
35
+ this.url = options.url;
36
+ this.params = options.params;
37
+ }
28
38
  this._strategy = strategy;
29
39
  this._handlerDeferred = new Deferred();
30
40
  this._extendLifetimePromises = [];
@@ -308,11 +318,14 @@ class Strategy {
308
318
  }
309
319
  const event = options.event;
310
320
  const request = typeof options.request === "string" ? new Request(options.request) : options.request;
311
- const params = "params" in options ? options.params : undefined;
312
- const handler = new StrategyHandler(this, {
321
+ const handler = new StrategyHandler(this, options.url ? {
313
322
  event,
314
323
  request,
315
- params
324
+ url: options.url,
325
+ params: options.params
326
+ } : {
327
+ event,
328
+ request
316
329
  });
317
330
  const responseDone = this._getResponse(handler, request, event);
318
331
  const handlerDone = this._awaitComplete(responseDone, handler, request, event);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serwist/strategies",
3
- "version": "9.0.0-preview.12",
3
+ "version": "9.0.0-preview.13",
4
4
  "type": "module",
5
5
  "description": "A service worker helper library implementing common caching strategies.",
6
6
  "files": [
@@ -30,12 +30,12 @@
30
30
  "./package.json": "./package.json"
31
31
  },
32
32
  "dependencies": {
33
- "@serwist/core": "9.0.0-preview.12"
33
+ "@serwist/core": "9.0.0-preview.13"
34
34
  },
35
35
  "devDependencies": {
36
- "rollup": "4.9.6",
37
- "typescript": "5.4.0-dev.20240206",
38
- "@serwist/constants": "9.0.0-preview.12"
36
+ "rollup": "4.12.0",
37
+ "typescript": "5.5.0-dev.20240304",
38
+ "@serwist/constants": "9.0.0-preview.13"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "typescript": ">=5.0.0"
package/src/CacheFirst.ts CHANGED
@@ -13,7 +13,7 @@ import type { StrategyHandler } from "./StrategyHandler.js";
13
13
  import { messages } from "./utils/messages.js";
14
14
 
15
15
  /**
16
- * An implementation of the [cache first](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#cache-first-falling-back-to-network)
16
+ * An implementation of the [cache first](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#cache_first_falling_back_to_network)
17
17
  * request strategy.
18
18
  *
19
19
  * A cache first strategy is useful for assets that have been revisioned,
@@ -21,21 +21,21 @@ export interface NetworkFirstOptions extends StrategyOptions {
21
21
  networkTimeoutSeconds?: number;
22
22
  }
23
23
 
24
+ /**
25
+ * An implementation of the [network first](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#network-first-falling-back-to-cache)
26
+ * request strategy.
27
+ *
28
+ * By default, this strategy will cache responses with a 200 status code as
29
+ * well as [opaque responses](https://developer.chrome.com/docs/workbox/caching-resources-during-runtime/#opaque-responses).
30
+ * Opaque responses are are cross-origin requests where the response doesn't
31
+ * support [CORS](https://enable-cors.org/).
32
+ *
33
+ * If the network request fails, and there is no cache match, this will throw
34
+ * a `SerwistError` exception.
35
+ */
24
36
  export class NetworkFirst extends Strategy {
25
37
  private readonly _networkTimeoutSeconds: number;
26
-
27
38
  /**
28
- * An implementation of the [network first](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#network-first-falling-back-to-cache)
29
- * request strategy.
30
- *
31
- * By default, this strategy will cache responses with a 200 status code as
32
- * well as [opaque responses](https://developer.chrome.com/docs/workbox/caching-resources-during-runtime/#opaque-responses).
33
- * Opaque responses are are cross-origin requests where the response doesn't
34
- * support [CORS](https://enable-cors.org/).
35
- *
36
- * If the network request fails, and there is no cache match, this will throw
37
- * a `SerwistError` exception.
38
- *
39
39
  * @param options
40
40
  * This option can be used to combat
41
41
  * "[lie-fi](https://developers.google.com/web/fundamentals/performance/poor-connectivity/#lie-fi)"
@@ -20,17 +20,18 @@ export interface NetworkOnlyOptions extends Omit<StrategyOptions, "cacheName" |
20
20
  networkTimeoutSeconds?: number;
21
21
  }
22
22
 
23
+ /**
24
+ * An implementation of the [network only](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#network-only)
25
+ * request strategy.
26
+ *
27
+ * This class is useful if you want to take advantage of any Serwist plugin.
28
+ *
29
+ * If the network request fails, this will throw a `SerwistError` exception.
30
+ */
23
31
  export class NetworkOnly extends Strategy {
24
32
  private readonly _networkTimeoutSeconds: number;
25
33
 
26
34
  /**
27
- * An implementation of the [network only](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#network-only)
28
- * request strategy.
29
- *
30
- * This class is useful if you want to take advantage of any Serwist plugin.
31
- *
32
- * If the network request fails, this will throw a `SerwistError` exception.
33
- *
34
35
  * @param options
35
36
  */
36
37
  constructor(options: NetworkOnlyOptions = {}) {
@@ -14,25 +14,26 @@ import type { StrategyHandler } from "./StrategyHandler.js";
14
14
  import { cacheOkAndOpaquePlugin } from "./plugins/cacheOkAndOpaquePlugin.js";
15
15
  import { messages } from "./utils/messages.js";
16
16
 
17
+ /**
18
+ * An implementation of the
19
+ * [stale-while-revalidate](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#stale-while-revalidate)
20
+ * request strategy.
21
+ *
22
+ * Resources are requested from both the cache and the network in parallel.
23
+ * The strategy will respond with the cached version if available, otherwise
24
+ * wait for the network response. The cache is updated with the network response
25
+ * with each successful request.
26
+ *
27
+ * By default, this strategy will cache responses with a 200 status code as
28
+ * well as [opaque responses](https://developer.chrome.com/docs/workbox/caching-resources-during-runtime/#opaque-responses).
29
+ * Opaque responses are cross-origin requests where the response doesn't
30
+ * support [CORS](https://enable-cors.org/).
31
+ *
32
+ * If the network request fails, and there is no cache match, this will throw
33
+ * a `SerwistError` exception.
34
+ */
17
35
  export class StaleWhileRevalidate extends Strategy {
18
36
  /**
19
- * An implementation of the
20
- * [stale-while-revalidate](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#stale-while-revalidate)
21
- * request strategy.
22
- *
23
- * Resources are requested from both the cache and the network in parallel.
24
- * The strategy will respond with the cached version if available, otherwise
25
- * wait for the network response. The cache is updated with the network response
26
- * with each successful request.
27
- *
28
- * By default, this strategy will cache responses with a 200 status code as
29
- * well as [opaque responses](https://developer.chrome.com/docs/workbox/caching-resources-during-runtime/#opaque-responses).
30
- * Opaque responses are cross-origin requests where the response doesn't
31
- * support [CORS](https://enable-cors.org/).
32
- *
33
- * If the network request fails, and there is no cache match, this will throw
34
- * a `SerwistError` exception.
35
- *
36
37
  * @param options
37
38
  */
38
39
  constructor(options: StrategyOptions = {}) {
package/src/Strategy.ts CHANGED
@@ -17,7 +17,7 @@ export interface StrategyOptions {
17
17
  */
18
18
  cacheName?: string;
19
19
  /**
20
- * [Plugins](https://developers.google.com/web/tools/workbox/guides/using-plugins)
20
+ * [Plugins](https://developer.chrome.com/docs/workbox/using-plugins)
21
21
  * to use in conjunction with this caching strategy.
22
22
  */
23
23
  plugins?: SerwistPlugin[];
@@ -111,9 +111,8 @@ export abstract class Strategy implements RouteHandlerObject {
111
111
 
112
112
  const event = options.event;
113
113
  const request = typeof options.request === "string" ? new Request(options.request) : options.request;
114
- const params = "params" in options ? options.params : undefined;
115
114
 
116
- const handler = new StrategyHandler(this, { event, request, params });
115
+ const handler = new StrategyHandler(this, options.url ? { event, request, url: options.url, params: options.params } : { event, request });
117
116
 
118
117
  const responseDone = this._getResponse(handler, request, event);
119
118
  const handlerDone = this._awaitComplete(responseDone, handler, request, event);
@@ -31,11 +31,15 @@ function toRequest(input: RequestInfo) {
31
31
  * have resolved).
32
32
  */
33
33
  export class StrategyHandler {
34
+ /**
35
+ * The event associated with this request.
36
+ */
37
+ public event: ExtendableEvent;
34
38
  /**
35
39
  * The request the strategy is performing (passed to the strategy's
36
40
  * `handle()` or `handleAll()` method).
37
41
  */
38
- public request!: Request;
42
+ public request: Request;
39
43
  /**
40
44
  * A `URL` instance of `request.url` (if passed to the strategy's
41
45
  * `handle()` or `handleAll()` method).
@@ -43,10 +47,6 @@ export class StrategyHandler {
43
47
  * from a `@serwist/routing.Route` object.
44
48
  */
45
49
  public url?: URL;
46
- /**
47
- * The event associated with this request.
48
- */
49
- public event: ExtendableEvent;
50
50
  /**
51
51
  * A `param` value (if passed to the strategy's
52
52
  * `handle()` or `handleAll()` method).
@@ -54,13 +54,12 @@ export class StrategyHandler {
54
54
  * from a `@serwist/routing.Route` object and the `@serwist/strategies.matchCallback`
55
55
  * returned a truthy value (it will be that value).
56
56
  */
57
- public params?: any;
57
+ public params?: string[] | MapLikeObject;
58
58
 
59
59
  private _cacheKeys: Record<string, Request> = {};
60
-
61
60
  private readonly _strategy: Strategy;
62
- private readonly _extendLifetimePromises: Promise<any>[];
63
61
  private readonly _handlerDeferred: Deferred<any>;
62
+ private readonly _extendLifetimePromises: Promise<any>[];
64
63
  private readonly _plugins: SerwistPlugin[];
65
64
  private readonly _pluginStateMap: Map<SerwistPlugin, MapLikeObject>;
66
65
 
@@ -74,7 +73,12 @@ export class StrategyHandler {
74
73
  * @param strategy
75
74
  * @param options
76
75
  */
77
- constructor(strategy: Strategy, options: HandlerCallbackOptions) {
76
+ constructor(
77
+ strategy: Strategy,
78
+ options: HandlerCallbackOptions & {
79
+ request: HandlerCallbackOptions["request"] & Request;
80
+ },
81
+ ) {
78
82
  if (process.env.NODE_ENV !== "production") {
79
83
  assert!.isInstance(options.event, ExtendableEvent, {
80
84
  moduleName: "@serwist/strategies",
@@ -82,11 +86,20 @@ export class StrategyHandler {
82
86
  funcName: "constructor",
83
87
  paramName: "options.event",
84
88
  });
89
+ assert!.isInstance(options.request, Request, {
90
+ moduleName: "@serwist/strategies",
91
+ className: "StrategyHandler",
92
+ funcName: "constructor",
93
+ paramName: "options.request",
94
+ });
85
95
  }
86
96
 
87
- Object.assign(this, options);
88
-
89
97
  this.event = options.event;
98
+ this.request = options.request;
99
+ if (options.url) {
100
+ this.url = options.url;
101
+ this.params = options.params;
102
+ }
90
103
  this._strategy = strategy;
91
104
  this._handlerDeferred = new Deferred();
92
105
  this._extendLifetimePromises = [];