@serwist/broadcast-update 9.0.0-preview.10 → 9.0.0-preview.12

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/README.md CHANGED
@@ -1 +1 @@
1
- This module's documentation can be found at https://developers.google.com/web/tools/workbox/modules/workbox-broadcast-update
1
+ This module's documentation can be found at https://serwist.pages.dev/docs/broadcast-update
@@ -1,8 +1,8 @@
1
1
  import type { CacheDidUpdateCallbackParam } from "@serwist/core";
2
2
  import type { BroadcastCacheUpdateOptions } from "./types.js";
3
3
  /**
4
- * Uses the `postMessage()` API to inform any open windows/tabs when a cached
5
- * response has been updated.
4
+ * A class that uses the `postMessage()` API to inform any open windows/tabs when
5
+ * a cached response has been updated.
6
6
  *
7
7
  * For efficiency's sake, the underlying response bodies are not compared;
8
8
  * only specific response headers are checked.
@@ -19,10 +19,8 @@ export declare class BroadcastCacheUpdate {
19
19
  */
20
20
  constructor({ generatePayload, headersToCheck, notifyAllClients }?: BroadcastCacheUpdateOptions);
21
21
  /**
22
- * Compares two [Responses](https://developer.mozilla.org/en-US/docs/Web/API/Response)
23
- * and sends a message (via `postMessage()`) to all window clients if the
24
- * responses differ. Neither of the Responses can be
25
- * [opaque](https://developer.chrome.com/docs/workbox/caching-resources-during-runtime/#opaque-responses).
22
+ * Compares two responses and sends a message (via `postMessage()`) to all window clients if the
23
+ * responses differ. Neither of the Responses can be opaque.
26
24
  *
27
25
  * The message that's posted has the following format (where `payload` can
28
26
  * be customized via the `generatePayload` option the instance is created
@@ -1 +1 @@
1
- {"version":3,"file":"BroadcastCacheUpdate.d.ts","sourceRoot":"","sources":["../src/BroadcastCacheUpdate.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAKjE,OAAO,KAAK,EAAE,2BAA2B,EAAiE,MAAM,YAAY,CAAC;AAuB7H;;;;;;GAMG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAW;IAC3C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAA4B;IAC7D,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAU;IAE5C;;;;;OAKG;gBACS,EAAE,eAAe,EAAE,cAAc,EAAE,gBAAgB,EAAE,GAAE,2BAAgC;IAMnG;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACG,eAAe,CAAC,OAAO,EAAE,2BAA2B,GAAG,OAAO,CAAC,IAAI,CAAC;CA4E3E"}
1
+ {"version":3,"file":"BroadcastCacheUpdate.d.ts","sourceRoot":"","sources":["../src/BroadcastCacheUpdate.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAKjE,OAAO,KAAK,EAAE,2BAA2B,EAAiE,MAAM,YAAY,CAAC;AAuB7H;;;;;;GAMG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAW;IAC3C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAA4B;IAC7D,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAU;IAE5C;;;;;OAKG;gBACS,EAAE,eAAe,EAAE,cAAc,EAAE,gBAAgB,EAAE,GAAE,2BAAgC;IAMnG;;;;;;;;;;;;;;;;;;;;;OAqBG;IACG,eAAe,CAAC,OAAO,EAAE,2BAA2B,GAAG,OAAO,CAAC,IAAI,CAAC;CA4E3E"}
@@ -1,8 +1,8 @@
1
1
  import type { CacheDidUpdateCallbackParam, SerwistPlugin } from "@serwist/core";
2
2
  import type { BroadcastCacheUpdateOptions } from "./types.js";
3
3
  /**
4
- * This plugin will automatically broadcast a message whenever a cached response
5
- * is updated.
4
+ * A class implementing the `cacheDidUpdate` lifecycle callback. It will automatically
5
+ * broadcast a message whenever a cached response is updated.
6
6
  */
7
7
  export declare class BroadcastUpdatePlugin implements SerwistPlugin {
8
8
  private readonly _broadcastUpdate;
package/dist/index.js CHANGED
@@ -20,7 +20,7 @@ const responsesAreSame = (firstResponse, secondResponse, headersToCheck)=>{
20
20
  });
21
21
  if (!atLeastOneHeaderAvailable) {
22
22
  if (process.env.NODE_ENV !== "production") {
23
- logger.warn("Unable to determine where the response has been updated " + "because none of the headers that would be checked are present.");
23
+ logger.warn("Unable to determine where the response has been updated because none of the headers that would be checked are present.");
24
24
  logger.debug("Attempting to compare the following: ", firstResponse, secondResponse, headersToCheck);
25
25
  }
26
26
  return true;
@@ -2,11 +2,10 @@
2
2
  * Given two `Response's`, compares several header values to see if they are
3
3
  * the same or not.
4
4
  *
5
- * @param firstResponse
6
- * @param secondResponse
7
- * @param headersToCheck
5
+ * @param firstResponse The first response.
6
+ * @param secondResponse The second response.
7
+ * @param headersToCheck A list of headers to check.
8
8
  * @returns
9
9
  */
10
- declare const responsesAreSame: (firstResponse: Response, secondResponse: Response, headersToCheck: string[]) => boolean;
11
- export { responsesAreSame };
10
+ export declare const responsesAreSame: (firstResponse: Response, secondResponse: Response, headersToCheck: string[]) => boolean;
12
11
  //# sourceMappingURL=responsesAreSame.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"responsesAreSame.d.ts","sourceRoot":"","sources":["../src/responsesAreSame.ts"],"names":[],"mappings":"AAUA;;;;;;;;GAQG;AACH,QAAA,MAAM,gBAAgB,kBAAmB,QAAQ,kBAAkB,QAAQ,kBAAkB,MAAM,EAAE,KAAG,OA4BvG,CAAC;AAEF,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
1
+ {"version":3,"file":"responsesAreSame.d.ts","sourceRoot":"","sources":["../src/responsesAreSame.ts"],"names":[],"mappings":"AAUA;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,kBAAmB,QAAQ,kBAAkB,QAAQ,kBAAkB,MAAM,EAAE,KAAG,OA4B9G,CAAC"}
package/dist/types.d.ts CHANGED
@@ -17,7 +17,7 @@ export interface BroadcastCacheUpdateOptions {
17
17
  */
18
18
  generatePayload?: (options: CacheDidUpdateCallbackParam) => Record<string, any>;
19
19
  /**
20
- * If true (the default) then all open clients will receive a message. If false,
20
+ * If `true` (the default) then all open clients will receive a message. If `false`,
21
21
  * then only the client that make the original request will be notified of the update.
22
22
  *
23
23
  * @default true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serwist/broadcast-update",
3
- "version": "9.0.0-preview.10",
3
+ "version": "9.0.0-preview.12",
4
4
  "type": "module",
5
5
  "description": "A module that uses the Broadcast Channel API to announce when a cached response has updated",
6
6
  "files": [
@@ -29,12 +29,12 @@
29
29
  }
30
30
  },
31
31
  "dependencies": {
32
- "@serwist/core": "9.0.0-preview.10"
32
+ "@serwist/core": "9.0.0-preview.12"
33
33
  },
34
34
  "devDependencies": {
35
35
  "rollup": "4.9.6",
36
36
  "typescript": "5.4.0-dev.20240206",
37
- "@serwist/constants": "9.0.0-preview.10"
37
+ "@serwist/constants": "9.0.0-preview.12"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "typescript": ">=5.0.0"
@@ -35,8 +35,8 @@ const defaultPayloadGenerator = (data: CacheDidUpdateCallbackParam): BroadcastPa
35
35
  };
36
36
 
37
37
  /**
38
- * Uses the `postMessage()` API to inform any open windows/tabs when a cached
39
- * response has been updated.
38
+ * A class that uses the `postMessage()` API to inform any open windows/tabs when
39
+ * a cached response has been updated.
40
40
  *
41
41
  * For efficiency's sake, the underlying response bodies are not compared;
42
42
  * only specific response headers are checked.
@@ -59,10 +59,8 @@ export class BroadcastCacheUpdate {
59
59
  }
60
60
 
61
61
  /**
62
- * Compares two [Responses](https://developer.mozilla.org/en-US/docs/Web/API/Response)
63
- * and sends a message (via `postMessage()`) to all window clients if the
64
- * responses differ. Neither of the Responses can be
65
- * [opaque](https://developer.chrome.com/docs/workbox/caching-resources-during-runtime/#opaque-responses).
62
+ * Compares two responses and sends a message (via `postMessage()`) to all window clients if the
63
+ * responses differ. Neither of the Responses can be opaque.
66
64
  *
67
65
  * The message that's posted has the following format (where `payload` can
68
66
  * be customized via the `generatePayload` option the instance is created
@@ -12,8 +12,8 @@ import { BroadcastCacheUpdate } from "./BroadcastCacheUpdate.js";
12
12
  import type { BroadcastCacheUpdateOptions } from "./types.js";
13
13
 
14
14
  /**
15
- * This plugin will automatically broadcast a message whenever a cached response
16
- * is updated.
15
+ * A class implementing the `cacheDidUpdate` lifecycle callback. It will automatically
16
+ * broadcast a message whenever a cached response is updated.
17
17
  */
18
18
  export class BroadcastUpdatePlugin implements SerwistPlugin {
19
19
  private readonly _broadcastUpdate: BroadcastCacheUpdate;
@@ -12,12 +12,12 @@ import { SerwistError, logger } from "@serwist/core/internal";
12
12
  * Given two `Response's`, compares several header values to see if they are
13
13
  * the same or not.
14
14
  *
15
- * @param firstResponse
16
- * @param secondResponse
17
- * @param headersToCheck
15
+ * @param firstResponse The first response.
16
+ * @param secondResponse The second response.
17
+ * @param headersToCheck A list of headers to check.
18
18
  * @returns
19
19
  */
20
- const responsesAreSame = (firstResponse: Response, secondResponse: Response, headersToCheck: string[]): boolean => {
20
+ export const responsesAreSame = (firstResponse: Response, secondResponse: Response, headersToCheck: string[]): boolean => {
21
21
  if (process.env.NODE_ENV !== "production") {
22
22
  if (!(firstResponse instanceof Response && secondResponse instanceof Response)) {
23
23
  throw new SerwistError("invalid-responses-are-same-args");
@@ -30,7 +30,7 @@ const responsesAreSame = (firstResponse: Response, secondResponse: Response, hea
30
30
 
31
31
  if (!atLeastOneHeaderAvailable) {
32
32
  if (process.env.NODE_ENV !== "production") {
33
- logger.warn("Unable to determine where the response has been updated " + "because none of the headers that would be checked are present.");
33
+ logger.warn("Unable to determine where the response has been updated because none of the headers that would be checked are present.");
34
34
  logger.debug("Attempting to compare the following: ", firstResponse, secondResponse, headersToCheck);
35
35
  }
36
36
 
@@ -46,5 +46,3 @@ const responsesAreSame = (firstResponse: Response, secondResponse: Response, hea
46
46
  return headerStateComparison && headerValueComparison;
47
47
  });
48
48
  };
49
-
50
- export { responsesAreSame };
package/src/types.ts CHANGED
@@ -18,7 +18,7 @@ export interface BroadcastCacheUpdateOptions {
18
18
  */
19
19
  generatePayload?: (options: CacheDidUpdateCallbackParam) => Record<string, any>;
20
20
  /**
21
- * If true (the default) then all open clients will receive a message. If false,
21
+ * If `true` (the default) then all open clients will receive a message. If `false`,
22
22
  * then only the client that make the original request will be notified of the update.
23
23
  *
24
24
  * @default true