@serwist/core 9.0.0-preview.0 → 9.0.0-preview.10

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,3 +1,4 @@
1
+ import type { MessageKey } from "../models/messages/messages.js";
1
2
  import type { MapLikeObject } from "../types.js";
2
3
  /**
3
4
  * Serwist errors should be thrown with this class.
@@ -18,7 +19,7 @@ declare class SerwistError extends Error {
18
19
  * that will help developers identify issues should
19
20
  * be added as a key on the context object.
20
21
  */
21
- constructor(errorCode: string, details?: MapLikeObject);
22
+ constructor(errorCode: MessageKey, details?: MapLikeObject);
22
23
  }
23
24
  export { SerwistError };
24
25
  //# sourceMappingURL=SerwistError.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"SerwistError.d.ts","sourceRoot":"","sources":["../../src/_private/SerwistError.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD;;;;;;;;GAQG;AACH,cAAM,YAAa,SAAQ,KAAK;IAC9B,OAAO,CAAC,EAAE,aAAa,CAAC;IAExB;;;;;;;OAOG;gBACS,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa;CAQvD;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
1
+ {"version":3,"file":"SerwistError.d.ts","sourceRoot":"","sources":["../../src/_private/SerwistError.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD;;;;;;;;GAQG;AACH,cAAM,YAAa,SAAQ,KAAK;IAC9B,OAAO,CAAC,EAAE,aAAa,CAAC;IAExB;;;;;;;OAOG;gBACS,SAAS,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,aAAa;CAQ3D;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
@@ -6,6 +6,19 @@ declare global {
6
6
  __WB_DISABLE_DEV_LOGS: boolean;
7
7
  }
8
8
  }
9
- declare const logger: Console;
10
- export { logger };
9
+ /**
10
+ * The logger used by Serwist inside of both service workers and the window global scope.
11
+ *
12
+ * Note: This is forcibly `null` in production mode to reduce bundle size. Do check whether
13
+ * you are currently in development mode (by using `process.env.NODE_ENV !== "production"`)
14
+ * before using it.
15
+ */
16
+ export declare const logger: {
17
+ error: (...args: any[]) => void;
18
+ debug: (...args: any[]) => void;
19
+ log: (...args: any[]) => void;
20
+ warn: (...args: any[]) => void;
21
+ groupCollapsed: (...args: any[]) => void;
22
+ groupEnd: (...args: any[]) => void;
23
+ };
11
24
  //# sourceMappingURL=logger.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/_private/logger.ts"],"names":[],"mappings":"AAQA,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,iBAAiB;QACzB,qBAAqB,EAAE,OAAO,CAAC;KAChC;IAED,UAAU,MAAM;QACd,qBAAqB,EAAE,OAAO,CAAC;KAChC;CACF;AAID,QAAA,MAAM,MAAM,SAqEA,CAAC;AAEb,OAAO,EAAE,MAAM,EAAE,CAAC"}
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/_private/logger.ts"],"names":[],"mappings":"AAQA,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,iBAAiB;QACzB,qBAAqB,EAAE,OAAO,CAAC;KAChC;IAED,UAAU,MAAM;QACd,qBAAqB,EAAE,OAAO,CAAC;KAChC;CACF;AAED;;;;;;GAMG;AACH,eAAO,MAAM,MAAM;qBAmEoC,GAAG,EAAE,KAAK,IAAI;qBAAd,GAAG,EAAE,KAAK,IAAI;mBAAd,GAAG,EAAE,KAAK,IAAI;oBAAd,GAAG,EAAE,KAAK,IAAI;8BAAd,GAAG,EAAE,KAAK,IAAI;wBAAd,GAAG,EAAE,KAAK,IAAI;CAE3D,CAAC"}
@@ -7,6 +7,5 @@
7
7
  * @returns
8
8
  * @private
9
9
  */
10
- declare function waitUntil(event: ExtendableEvent, asyncFn: () => Promise<any>): Promise<any>;
11
- export { waitUntil };
10
+ export declare const waitUntil: <T = any>(event: ExtendableEvent, asyncFn: () => Promise<T>) => Promise<T>;
12
11
  //# sourceMappingURL=waitUntil.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"waitUntil.d.ts","sourceRoot":"","sources":["../../src/_private/waitUntil.ts"],"names":[],"mappings":"AAOA;;;;;;;;GAQG;AACH,iBAAS,SAAS,CAAC,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,CAIpF;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
1
+ {"version":3,"file":"waitUntil.d.ts","sourceRoot":"","sources":["../../src/_private/waitUntil.ts"],"names":[],"mappings":"AAOA;;;;;;;;GAQG;AACH,eAAO,MAAM,SAAS,mBAAoB,eAAe,0CAIxD,CAAC"}
@@ -1,10 +1,4 @@
1
- /*
2
- Copyright 2018 Google LLC
3
-
4
- Use of this source code is governed by an MIT-style
5
- license that can be found in the LICENSE file or at
6
- https://opensource.org/licenses/MIT.
7
- */ const _cacheNameDetails = {
1
+ const _cacheNameDetails = {
8
2
  googleAnalytics: "googleAnalytics",
9
3
  precache: "precache-v2",
10
4
  prefix: "serwist",
@@ -49,13 +43,7 @@ const cacheNames = {
49
43
  }
50
44
  };
51
45
 
52
- /*
53
- Copyright 2018 Google LLC
54
-
55
- Use of this source code is governed by an MIT-style
56
- license that can be found in the LICENSE file or at
57
- https://opensource.org/licenses/MIT.
58
- */ const messages = {
46
+ const messages = {
59
47
  "invalid-value": ({ paramName, validValueDescription, value })=>{
60
48
  if (!paramName || !validValueDescription) {
61
49
  throw new Error(`Unexpected input to 'invalid-value' error.`);
@@ -104,7 +92,7 @@ const cacheNames = {
104
92
  if (!thrownErrorMessage) {
105
93
  throw new Error("Unexpected input to " + `'plugin-error-request-will-fetch', error.`);
106
94
  }
107
- return `An error was thrown by a plugins 'requestWillFetch()' method. The thrown error message was: '${thrownErrorMessage}'.`;
95
+ return `An error was thrown by a plugin's 'requestWillFetch()' method. The thrown error message was: '${thrownErrorMessage}'.`;
108
96
  },
109
97
  "invalid-cache-name": ({ cacheNameId, value })=>{
110
98
  if (!cacheNameId) {
@@ -234,24 +222,9 @@ const generatorFunction = (code, details = {})=>{
234
222
  };
235
223
  const messageGenerator = process.env.NODE_ENV === "production" ? fallback : generatorFunction;
236
224
 
237
- /**
238
- * Serwist errors should be thrown with this class.
239
- * This allows use to ensure the type easily in tests,
240
- * helps developers identify errors from Serwist
241
- * easily and allows use to optimise error
242
- * messages correctly.
243
- *
244
- * @private
245
- */ class SerwistError extends Error {
225
+ class SerwistError extends Error {
246
226
  details;
247
- /**
248
- *
249
- * @param errorCode The error code that
250
- * identifies this particular error.
251
- * @param details Any relevant arguments
252
- * that will help developers identify issues should
253
- * be added as a key on the context object.
254
- */ constructor(errorCode, details){
227
+ constructor(errorCode, details){
255
228
  const message = messageGenerator(errorCode, details);
256
229
  super(message);
257
230
  this.name = errorCode;
@@ -259,21 +232,8 @@ const messageGenerator = process.env.NODE_ENV === "production" ? fallback : gene
259
232
  }
260
233
  }
261
234
 
262
- /*
263
- Copyright 2019 Google LLC
264
-
265
- Use of this source code is governed by an MIT-style
266
- license that can be found in the LICENSE file or at
267
- https://opensource.org/licenses/MIT.
268
- */ let supportStatus;
269
- /**
270
- * A utility function that determines whether the current browser supports
271
- * constructing a new `Response` from a `response.body` stream.
272
- *
273
- * @returns `true`, if the current browser can successfully construct
274
- * a `Response` from a `response.body` stream, `false` otherwise.
275
- * @private
276
- */ function canConstructResponseFromBodyStream() {
235
+ let supportStatus;
236
+ function canConstructResponseFromBodyStream() {
277
237
  if (supportStatus === undefined) {
278
238
  const testResponse = new Response("");
279
239
  if ("body" in testResponse) {
@@ -289,12 +249,7 @@ const messageGenerator = process.env.NODE_ENV === "production" ? fallback : gene
289
249
  return supportStatus;
290
250
  }
291
251
 
292
- /*
293
- * This method throws if the supplied value is not an array.
294
- * The destructed values are required to produce a meaningful error for users.
295
- * The destructed and restructured object is so it's clear what is
296
- * needed.
297
- */ const isArray = (value, details)=>{
252
+ const isArray = (value, details)=>{
298
253
  if (!Array.isArray(value)) {
299
254
  throw new SerwistError("not-an-array", details);
300
255
  }
@@ -307,14 +262,12 @@ const hasMethod = (object, expectedMethod, details)=>{
307
262
  }
308
263
  };
309
264
  const isType = (object, expectedType, details)=>{
310
- // biome-ignore lint/suspicious/useValidTypeof: Know to not make a mistake...
311
265
  if (typeof object !== expectedType) {
312
266
  details.expectedType = expectedType;
313
267
  throw new SerwistError("incorrect-type", details);
314
268
  }
315
269
  };
316
- const isInstance = (object, // biome-ignore lint/complexity/noBannedTypes: Need the general type to do the check later.
317
- expectedClass, details)=>{
270
+ const isInstance = (object, expectedClass, details)=>{
318
271
  if (!(object instanceof expectedClass)) {
319
272
  details.expectedClassName = expectedClass.name;
320
273
  throw new SerwistError("incorrect-class", details);
@@ -326,8 +279,7 @@ const isOneOf = (value, validValues, details)=>{
326
279
  throw new SerwistError("invalid-value", details);
327
280
  }
328
281
  };
329
- const isArrayOfClass = (value, // biome-ignore lint/complexity/noBannedTypes: Need general type to do check later.
330
- expectedClass, details)=>{
282
+ const isArrayOfClass = (value, expectedClass, details)=>{
331
283
  const error = new SerwistError("not-array-of-class", details);
332
284
  if (!Array.isArray(value)) {
333
285
  throw error;
@@ -347,15 +299,7 @@ const finalAssertExports = process.env.NODE_ENV === "production" ? null : {
347
299
  isArrayOfClass
348
300
  };
349
301
 
350
- /*
351
- Copyright 2019 Google LLC
352
- Use of this source code is governed by an MIT-style
353
- license that can be found in the LICENSE file or at
354
- https://opensource.org/licenses/MIT.
355
- */ // logger is used inside of both service workers and the window global scope.
356
302
  const logger = process.env.NODE_ENV === "production" ? null : (()=>{
357
- // Don't overwrite this value if it's already set.
358
- // See https://github.com/GoogleChrome/workbox/pull/2284#issuecomment-560470923
359
303
  if (!("__WB_DISABLE_DEV_LOGS" in globalThis)) {
360
304
  self.__WB_DISABLE_DEV_LOGS = false;
361
305
  }
@@ -373,8 +317,6 @@ const logger = process.env.NODE_ENV === "production" ? null : (()=>{
373
317
  return;
374
318
  }
375
319
  if (method === "groupCollapsed") {
376
- // Safari doesn't print all console.groupCollapsed() arguments:
377
- // https://bugs.webkit.org/show_bug.cgi?id=182754
378
320
  if (typeof navigator !== "undefined" && /^((?!chrome|android).)*safari/i.test(navigator.userAgent)) {
379
321
  console[method](...args);
380
322
  return;
@@ -387,7 +329,6 @@ const logger = process.env.NODE_ENV === "production" ? null : (()=>{
387
329
  "font-weight: bold",
388
330
  "padding: 2px 0.5em"
389
331
  ];
390
- // When in a group, the serwist prefix is not displayed.
391
332
  const logPrefix = inGroup ? [] : [
392
333
  "%cserwist",
393
334
  styles.join(";")
@@ -400,26 +341,15 @@ const logger = process.env.NODE_ENV === "production" ? null : (()=>{
400
341
  inGroup = false;
401
342
  }
402
343
  };
403
- // biome-ignore lint/complexity/noBannedTypes: Unknown reason
404
- const api = {};
405
344
  const loggerMethods = Object.keys(methodToColorMap);
406
- for (const key of loggerMethods){
407
- const method = key;
345
+ return loggerMethods.reduce((api, method)=>{
408
346
  api[method] = (...args)=>{
409
347
  print(method, args);
410
348
  };
411
- }
412
- return api;
349
+ return api;
350
+ }, {});
413
351
  })();
414
352
 
415
- /*
416
- Copyright 2018 Google LLC
417
-
418
- Use of this source code is governed by an MIT-style
419
- license that can be found in the LICENSE file or at
420
- https://opensource.org/licenses/MIT.
421
- */ // Callbacks to be executed whenever there's a quota error.
422
- // biome-ignore lint/complexity/noBannedTypes: Can't change Function type right now.
423
353
  const quotaErrorCallbacks = new Set();
424
354
 
425
355
  export { SerwistError as S, canConstructResponseFromBodyStream as a, cacheNames as c, finalAssertExports as f, logger as l, quotaErrorCallbacks as q };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Claim any currently available clients once the service worker
2
+ * Claims any currently available clients once the service worker
3
3
  * becomes active. This is normally used in conjunction with `skipWaiting()`.
4
4
  */
5
5
  declare function clientsClaim(): void;
package/dist/index.d.ts CHANGED
@@ -8,5 +8,5 @@ import { setCacheNameDetails } from "./setCacheNameDetails.js";
8
8
  * setting default values that need to be shared (like cache names).
9
9
  */
10
10
  export { cacheNames, clientsClaim, copyResponse, registerQuotaErrorCallback, setCacheNameDetails };
11
- export * from "./types.js";
11
+ export type * from "./types.js";
12
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAC7E,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D;;;GAGG;AACH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,CAAC;AAEnG,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAC7E,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D;;;GAGG;AACH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,CAAC;AAEnG,mBAAmB,YAAY,CAAC"}
@@ -1,26 +1,11 @@
1
1
  import { l as logger, q as quotaErrorCallbacks } from './chunks/quotaErrorCallbacks.js';
2
2
  export { S as SerwistError, f as assert, a as canConstructResponseFromBodyStream, c as privateCacheNames } from './chunks/quotaErrorCallbacks.js';
3
3
 
4
- /*
5
- Copyright 2018 Google LLC
6
-
7
- Use of this source code is governed by an MIT-style
8
- license that can be found in the LICENSE file or at
9
- https://opensource.org/licenses/MIT.
10
- */ /**
11
- * The Deferred class composes Promises in a way that allows for them to be
12
- * resolved or rejected from outside the constructor. In most cases promises
13
- * should be used directly, but Deferreds can be necessary when the logic to
14
- * resolve a promise must be separate.
15
- *
16
- * @private
17
- */ class Deferred {
4
+ class Deferred {
18
5
  promise;
19
6
  resolve;
20
7
  reject;
21
- /**
22
- * Creates a promise and exposes its resolve and reject functions as methods.
23
- */ constructor(){
8
+ constructor(){
24
9
  this.promise = new Promise((resolve, reject)=>{
25
10
  this.resolve = resolve;
26
11
  this.reject = reject;
@@ -28,36 +13,18 @@ export { S as SerwistError, f as assert, a as canConstructResponseFromBodyStream
28
13
  }
29
14
  }
30
15
 
31
- /*
32
- Copyright 2020 Google LLC
33
- Use of this source code is governed by an MIT-style
34
- license that can be found in the LICENSE file or at
35
- https://opensource.org/licenses/MIT.
36
- */ function stripParams(fullURL, ignoreParams) {
16
+ function stripParams(fullURL, ignoreParams) {
37
17
  const strippedURL = new URL(fullURL);
38
18
  for (const param of ignoreParams){
39
19
  strippedURL.searchParams.delete(param);
40
20
  }
41
21
  return strippedURL.href;
42
22
  }
43
- /**
44
- * Matches an item in the cache, ignoring specific URL params. This is similar
45
- * to the `ignoreSearch` option, but it allows you to ignore just specific
46
- * params (while continuing to match on the others).
47
- *
48
- * @private
49
- * @param cache
50
- * @param request
51
- * @param matchOptions
52
- * @param ignoreParams
53
- * @returns
54
- */ async function cacheMatchIgnoreParams(cache, request, ignoreParams, matchOptions) {
23
+ async function cacheMatchIgnoreParams(cache, request, ignoreParams, matchOptions) {
55
24
  const strippedRequestURL = stripParams(request.url, ignoreParams);
56
- // If the request doesn't include any ignored params, match as normal.
57
25
  if (request.url === strippedRequestURL) {
58
26
  return cache.match(request, matchOptions);
59
27
  }
60
- // Otherwise, match by comparing keys
61
28
  const keysOptions = {
62
29
  ...matchOptions,
63
30
  ignoreSearch: true
@@ -72,24 +39,9 @@ export { S as SerwistError, f as assert, a as canConstructResponseFromBodyStream
72
39
  return;
73
40
  }
74
41
 
75
- /*
76
- Copyright 2019 Google LLC
77
-
78
- Use of this source code is governed by an MIT-style
79
- license that can be found in the LICENSE file or at
80
- https://opensource.org/licenses/MIT.
81
- */ let supportStatus;
82
- /**
83
- * A utility function that determines whether the current browser supports
84
- * constructing a [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/ReadableStream)
85
- * object.
86
- *
87
- * @returns `true`, if the current browser can successfully construct a `ReadableStream`, `false` otherwise.
88
- *
89
- * @private
90
- */ function canConstructReadableStream() {
42
+ let supportStatus;
43
+ function canConstructReadableStream() {
91
44
  if (supportStatus === undefined) {
92
- // See https://github.com/GoogleChrome/workbox/issues/1473
93
45
  try {
94
46
  new ReadableStream({
95
47
  start () {}
@@ -102,26 +54,11 @@ export { S as SerwistError, f as assert, a as canConstructResponseFromBodyStream
102
54
  return supportStatus;
103
55
  }
104
56
 
105
- /*
106
- Copyright 2019 Google LLC
107
- Use of this source code is governed by an MIT-style
108
- license that can be found in the LICENSE file or at
109
- https://opensource.org/licenses/MIT.
110
- */ /**
111
- * A helper function that prevents a promise from being flagged as unused.
112
- *
113
- * @private
114
- **/ function dontWaitFor(promise) {
115
- // Effective no-op.
57
+ function dontWaitFor(promise) {
116
58
  void promise.then(()=>{});
117
59
  }
118
60
 
119
- /**
120
- * Runs all of the callback functions, one at a time sequentially, in the order
121
- * in which they were registered.
122
- *
123
- * @private
124
- */ async function executeQuotaErrorCallbacks() {
61
+ async function executeQuotaErrorCallbacks() {
125
62
  if (process.env.NODE_ENV !== "production") {
126
63
  logger.log(`About to run ${quotaErrorCallbacks.size} callbacks to clean up caches.`);
127
64
  }
@@ -136,46 +73,17 @@ export { S as SerwistError, f as assert, a as canConstructResponseFromBodyStream
136
73
  }
137
74
  }
138
75
 
139
- /*
140
- Copyright 2018 Google LLC
141
-
142
- Use of this source code is governed by an MIT-style
143
- license that can be found in the LICENSE file or at
144
- https://opensource.org/licenses/MIT.
145
- */ const getFriendlyURL = (url)=>{
76
+ const getFriendlyURL = (url)=>{
146
77
  const urlObj = new URL(String(url), location.href);
147
- // See https://github.com/GoogleChrome/workbox/issues/2323
148
- // We want to include everything, except for the origin if it's same-origin.
149
78
  return urlObj.href.replace(new RegExp(`^${location.origin}`), "");
150
79
  };
151
80
 
152
- /*
153
- Copyright 2019 Google LLC
154
- Use of this source code is governed by an MIT-style
155
- license that can be found in the LICENSE file or at
156
- https://opensource.org/licenses/MIT.
157
- */ /**
158
- * Returns a promise that resolves and the passed number of milliseconds.
159
- * This utility is an async/await-friendly version of `setTimeout`.
160
- *
161
- * @param ms
162
- * @returns
163
- * @private
164
- */ function timeout(ms) {
81
+ function timeout(ms) {
165
82
  return new Promise((resolve)=>setTimeout(resolve, ms));
166
83
  }
167
84
 
168
85
  const MAX_RETRY_TIME = 2000;
169
- /**
170
- * Returns a promise that resolves to a window client matching the passed
171
- * `resultingClientId`. For browsers that don't support `resultingClientId`
172
- * or if waiting for the resulting client to apper takes too long, resolve to
173
- * `undefined`.
174
- *
175
- * @param resultingClientId
176
- * @returns
177
- * @private
178
- */ async function resultingClientExists(resultingClientId) {
86
+ async function resultingClientExists(resultingClientId) {
179
87
  if (!resultingClientId) {
180
88
  return;
181
89
  }
@@ -185,45 +93,28 @@ const MAX_RETRY_TIME = 2000;
185
93
  const existingWindowIds = new Set(existingWindows.map((w)=>w.id));
186
94
  let resultingWindow = undefined;
187
95
  const startTime = performance.now();
188
- // Only wait up to `MAX_RETRY_TIME` to find a matching client.
189
96
  while(performance.now() - startTime < MAX_RETRY_TIME){
190
97
  existingWindows = await self.clients.matchAll({
191
98
  type: "window"
192
99
  });
193
100
  resultingWindow = existingWindows.find((w)=>{
194
101
  if (resultingClientId) {
195
- // If we have a `resultingClientId`, we can match on that.
196
102
  return w.id === resultingClientId;
197
103
  }
198
- // Otherwise match on finding a window not in `existingWindowIds`.
199
104
  return !existingWindowIds.has(w.id);
200
105
  });
201
106
  if (resultingWindow) {
202
107
  break;
203
108
  }
204
- // Sleep for 100ms and retry.
205
109
  await timeout(100);
206
110
  }
207
111
  return resultingWindow;
208
112
  }
209
113
 
210
- /*
211
- Copyright 2020 Google LLC
212
- Use of this source code is governed by an MIT-style
213
- license that can be found in the LICENSE file or at
214
- https://opensource.org/licenses/MIT.
215
- */ /**
216
- * A utility method that makes it easier to use `event.waitUntil` with
217
- * async functions and return the result.
218
- *
219
- * @param event
220
- * @param asyncFn
221
- * @returns
222
- * @private
223
- */ function waitUntil(event, asyncFn) {
114
+ const waitUntil = (event, asyncFn)=>{
224
115
  const returnPromise = asyncFn();
225
116
  event.waitUntil(returnPromise);
226
117
  return returnPromise;
227
- }
118
+ };
228
119
 
229
120
  export { Deferred, cacheMatchIgnoreParams, canConstructReadableStream, dontWaitFor, executeQuotaErrorCallbacks, getFriendlyURL, logger, resultingClientExists, timeout, waitUntil };
package/dist/index.js CHANGED
@@ -1,17 +1,6 @@
1
1
  import { c as cacheNames$1, S as SerwistError, a as canConstructResponseFromBodyStream, f as finalAssertExports, q as quotaErrorCallbacks, l as logger } from './chunks/quotaErrorCallbacks.js';
2
2
 
3
- /**
4
- * Get the current cache names and prefix/suffix used by Workbox.
5
- *
6
- * `cacheNames.precache` is used for precached assets,
7
- * `cacheNames.googleAnalytics` is used by `@serwist/google-analytics` to
8
- * store `analytics.js`, and `cacheNames.runtime` is used for everything else.
9
- *
10
- * `cacheNames.prefix` can be used to retrieve just the current prefix value.
11
- * `cacheNames.suffix` can be used to retrieve just the current suffix value.
12
- *
13
- * @returns An object with `precache`, `runtime`, `prefix`, and `googleAnalytics` properties.
14
- */ const cacheNames = {
3
+ const cacheNames = {
15
4
  get googleAnalytics () {
16
5
  return cacheNames$1.getGoogleAnalyticsName();
17
6
  },
@@ -29,40 +18,12 @@ import { c as cacheNames$1, S as SerwistError, a as canConstructResponseFromBody
29
18
  }
30
19
  };
31
20
 
32
- /*
33
- Copyright 2019 Google LLC
34
-
35
- Use of this source code is governed by an MIT-style
36
- license that can be found in the LICENSE file or at
37
- https://opensource.org/licenses/MIT.
38
- */ // Give TypeScript the correct global.
39
- /**
40
- * Claim any currently available clients once the service worker
41
- * becomes active. This is normally used in conjunction with `skipWaiting()`.
42
- */ function clientsClaim() {
21
+ function clientsClaim() {
43
22
  self.addEventListener("activate", ()=>self.clients.claim());
44
23
  }
45
24
 
46
- /**
47
- * Allows developers to copy a response and modify its `headers`, `status`,
48
- * or `statusText` values (the values settable via a
49
- * [`ResponseInit`](https://developer.mozilla.org/en-US/docs/Web/API/Response/Response#Syntax)
50
- * object in the constructor).
51
- * To modify these values, pass a function as the second argument. That
52
- * function will be invoked with a single object with the response properties
53
- * `{headers, status, statusText}`. The return value of this function will
54
- * be used as the `ResponseInit` for the new `Response`. To change the values
55
- * either modify the passed parameter(s) and return it, or return a totally
56
- * new object.
57
- *
58
- * This method is intentionally limited to same-origin responses, regardless of
59
- * whether CORS was used or not.
60
- *
61
- * @param response
62
- * @param modifier
63
- */ async function copyResponse(response, modifier) {
25
+ async function copyResponse(response, modifier) {
64
26
  let origin = null;
65
- // If response.url isn't set, assume it's cross-origin and keep origin null.
66
27
  if (response.url) {
67
28
  const responseURL = new URL(response.url);
68
29
  origin = responseURL.origin;
@@ -73,27 +34,16 @@ import { c as cacheNames$1, S as SerwistError, a as canConstructResponseFromBody
73
34
  });
74
35
  }
75
36
  const clonedResponse = response.clone();
76
- // Create a fresh `ResponseInit` object by cloning the headers.
77
37
  const responseInit = {
78
38
  headers: new Headers(clonedResponse.headers),
79
39
  status: clonedResponse.status,
80
40
  statusText: clonedResponse.statusText
81
41
  };
82
- // Apply any user modifications.
83
42
  const modifiedResponseInit = modifier ? modifier(responseInit) : responseInit;
84
- // Create the new response from the body stream and `ResponseInit`
85
- // modifications. Note: not all browsers support the Response.body stream,
86
- // so fall back to reading the entire body into memory as a blob.
87
43
  const body = canConstructResponseFromBodyStream() ? clonedResponse.body : await clonedResponse.blob();
88
44
  return new Response(body, modifiedResponseInit);
89
45
  }
90
46
 
91
- /**
92
- * Adds a function to the set of quotaErrorCallbacks that will be executed if
93
- * there's a quota error.
94
- *
95
- * @param callback
96
- */ // biome-ignore lint/complexity/noBannedTypes: Can't change Function type
97
47
  function registerQuotaErrorCallback(callback) {
98
48
  if (process.env.NODE_ENV !== "production") {
99
49
  finalAssertExports.isType(callback, "function", {
@@ -108,12 +58,7 @@ function registerQuotaErrorCallback(callback) {
108
58
  }
109
59
  }
110
60
 
111
- /**
112
- * Modifies the default cache names used by the Serwist packages.
113
- * Cache names are generated as `<prefix>-<Cache Name>-<suffix>`.
114
- *
115
- * @param details
116
- */ function setCacheNameDetails(details) {
61
+ function setCacheNameDetails(details) {
117
62
  if (process.env.NODE_ENV !== "production") {
118
63
  for (const key of Object.keys(details)){
119
64
  finalAssertExports.isType(details[key], "string", {
@@ -1,2 +1,4 @@
1
- export declare const messageGenerator: ((code: string, ...args: any[]) => string) | ((code: string, details?: {}) => string);
1
+ import type { MapLikeObject } from "../../types.js";
2
+ import { type MessageKey } from "./messages.js";
3
+ export declare const messageGenerator: ((code: string, ...args: any[]) => string) | ((code: MessageKey, details?: MapLikeObject) => string);
2
4
  //# sourceMappingURL=messageGenerator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"messageGenerator.d.ts","sourceRoot":"","sources":["../../../src/models/messages/messageGenerator.ts"],"names":[],"mappings":"AA2BA,eAAO,MAAM,gBAAgB,UAjBL,MAAM,WAAW,GAAG,EAAE,uBAQb,MAAM,0BAS6D,CAAC"}
1
+ {"version":3,"file":"messageGenerator.d.ts","sourceRoot":"","sources":["../../../src/models/messages/messageGenerator.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,KAAK,UAAU,EAAY,MAAM,eAAe,CAAC;AAmB1D,eAAO,MAAM,gBAAgB,UAjBL,MAAM,WAAW,GAAG,EAAE,uBAQb,UAAU,YAAW,aAAa,YASiC,CAAC"}
@@ -1,9 +1,44 @@
1
1
  interface LoggableObject {
2
2
  [key: string]: string | number;
3
3
  }
4
- interface MessageMap {
5
- [messageID: string]: (param: LoggableObject) => string;
6
- }
7
- export declare const messages: MessageMap;
4
+ export declare const messages: {
5
+ "invalid-value": ({ paramName, validValueDescription, value }: LoggableObject) => string;
6
+ "not-an-array": ({ moduleName, className, funcName, paramName }: LoggableObject) => string;
7
+ "incorrect-type": ({ expectedType, paramName, moduleName, className, funcName }: LoggableObject) => string;
8
+ "incorrect-class": ({ expectedClassName, paramName, moduleName, className, funcName, isReturnValueProblem }: LoggableObject) => string;
9
+ "missing-a-method": ({ expectedMethod, paramName, moduleName, className, funcName }: LoggableObject) => string;
10
+ "add-to-cache-list-unexpected-type": ({ entry }: LoggableObject) => string;
11
+ "add-to-cache-list-conflicting-entries": ({ firstEntry, secondEntry }: LoggableObject) => string;
12
+ "plugin-error-request-will-fetch": ({ thrownErrorMessage }: LoggableObject) => string;
13
+ "invalid-cache-name": ({ cacheNameId, value }: LoggableObject) => string;
14
+ "unregister-route-but-not-found-with-method": ({ method }: LoggableObject) => string;
15
+ "unregister-route-route-not-registered": () => string;
16
+ "queue-replay-failed": ({ name }: LoggableObject) => string;
17
+ "duplicate-queue-name": ({ name }: LoggableObject) => string;
18
+ "expired-test-without-max-age": ({ methodName, paramName }: LoggableObject) => string;
19
+ "unsupported-route-type": ({ moduleName, className, funcName, paramName }: LoggableObject) => string;
20
+ "not-array-of-class": ({ value, expectedClass, moduleName, className, funcName, paramName }: LoggableObject) => string;
21
+ "max-entries-or-age-required": ({ moduleName, className, funcName }: LoggableObject) => string;
22
+ "statuses-or-headers-required": ({ moduleName, className, funcName }: LoggableObject) => string;
23
+ "invalid-string": ({ moduleName, funcName, paramName }: LoggableObject) => string;
24
+ "channel-name-required": () => string;
25
+ "invalid-responses-are-same-args": () => string;
26
+ "expire-custom-caches-only": () => string;
27
+ "unit-must-be-bytes": ({ normalizedRangeHeader }: LoggableObject) => string;
28
+ "single-range-only": ({ normalizedRangeHeader }: LoggableObject) => string;
29
+ "invalid-range-values": ({ normalizedRangeHeader }: LoggableObject) => string;
30
+ "no-range-header": () => string;
31
+ "range-not-satisfiable": ({ size, start, end }: LoggableObject) => string;
32
+ "attempt-to-cache-non-get-request": ({ url, method }: LoggableObject) => string;
33
+ "cache-put-with-no-response": ({ url }: LoggableObject) => string;
34
+ "no-response": ({ url, error }: LoggableObject) => string;
35
+ "bad-precaching-response": ({ url, status }: LoggableObject) => string;
36
+ "non-precached-url": ({ url }: LoggableObject) => string;
37
+ "add-to-cache-list-conflicting-integrities": ({ url }: LoggableObject) => string;
38
+ "missing-precache-entry": ({ cacheName, url }: LoggableObject) => string;
39
+ "cross-origin-copy-response": ({ origin }: LoggableObject) => string;
40
+ "opaque-streams-source": ({ type }: LoggableObject) => string;
41
+ };
42
+ export type MessageKey = keyof typeof messages;
8
43
  export {};
9
44
  //# sourceMappingURL=messages.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../../src/models/messages/messages.ts"],"names":[],"mappings":"AAQA,UAAU,cAAc;IACtB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;CAChC;AACD,UAAU,UAAU;IAClB,CAAC,SAAS,EAAE,MAAM,GAAG,CAAC,KAAK,EAAE,cAAc,KAAK,MAAM,CAAC;CACxD;AAED,eAAO,MAAM,QAAQ,EAAE,UAuNtB,CAAC"}
1
+ {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../../src/models/messages/messages.ts"],"names":[],"mappings":"AAQA,UAAU,cAAc;IACtB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;CAChC;AAKD,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuNC,CAAC;AAEvB,MAAM,MAAM,UAAU,GAAG,MAAM,OAAO,QAAQ,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import type { PartialCacheNameDetails } from "./_private/cacheNames.js";
2
2
  /**
3
- * Modifies the default cache names used by the Serwist packages.
3
+ * Modifies the default cache names used by Serwist packages.
4
4
  * Cache names are generated as `<prefix>-<Cache Name>-<suffix>`.
5
5
  *
6
6
  * @param details
package/dist/types.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export type PromiseOrNot<T> = T | Promise<T>;
1
2
  export interface MapLikeObject {
2
3
  [key: string]: any;
3
4
  }
@@ -131,7 +132,7 @@ export interface CacheDidUpdateCallbackParam {
131
132
  state?: PluginState;
132
133
  }
133
134
  export interface CacheDidUpdateCallback {
134
- (param: CacheDidUpdateCallbackParam): Promise<any>;
135
+ (param: CacheDidUpdateCallbackParam): PromiseOrNot<any>;
135
136
  }
136
137
  export interface CacheKeyWillBeUsedCallbackParam {
137
138
  mode: string;
@@ -141,7 +142,7 @@ export interface CacheKeyWillBeUsedCallbackParam {
141
142
  state?: PluginState;
142
143
  }
143
144
  export interface CacheKeyWillBeUsedCallback {
144
- (param: CacheKeyWillBeUsedCallbackParam): Promise<Request | string>;
145
+ (param: CacheKeyWillBeUsedCallbackParam): PromiseOrNot<Request | string>;
145
146
  }
146
147
  export interface CacheWillUpdateCallbackParam {
147
148
  request: Request;
@@ -150,7 +151,7 @@ export interface CacheWillUpdateCallbackParam {
150
151
  state?: PluginState;
151
152
  }
152
153
  export interface CacheWillUpdateCallback {
153
- (param: CacheWillUpdateCallbackParam): Promise<any>;
154
+ (param: CacheWillUpdateCallbackParam): PromiseOrNot<any>;
154
155
  }
155
156
  export interface CachedResponseWillBeUsedCallbackParam {
156
157
  /**
@@ -172,7 +173,7 @@ export interface CachedResponseWillBeUsedCallbackParam {
172
173
  state?: PluginState;
173
174
  }
174
175
  export interface CachedResponseWillBeUsedCallback {
175
- (param: CachedResponseWillBeUsedCallbackParam): Promise<any>;
176
+ (param: CachedResponseWillBeUsedCallbackParam): PromiseOrNot<any>;
176
177
  }
177
178
  export interface FetchDidFailCallbackParam {
178
179
  error: Error;
@@ -182,7 +183,7 @@ export interface FetchDidFailCallbackParam {
182
183
  state?: PluginState;
183
184
  }
184
185
  export interface FetchDidFailCallback {
185
- (param: FetchDidFailCallbackParam): Promise<any>;
186
+ (param: FetchDidFailCallbackParam): PromiseOrNot<any>;
186
187
  }
187
188
  export interface FetchDidSucceedCallbackParam {
188
189
  request: Request;
@@ -191,7 +192,7 @@ export interface FetchDidSucceedCallbackParam {
191
192
  state?: PluginState;
192
193
  }
193
194
  export interface FetchDidSucceedCallback {
194
- (param: FetchDidSucceedCallbackParam): Promise<Response>;
195
+ (param: FetchDidSucceedCallbackParam): PromiseOrNot<Response>;
195
196
  }
196
197
  export interface RequestWillFetchCallbackParam {
197
198
  request: Request;
@@ -199,7 +200,7 @@ export interface RequestWillFetchCallbackParam {
199
200
  state?: PluginState;
200
201
  }
201
202
  export interface RequestWillFetchCallback {
202
- (param: RequestWillFetchCallbackParam): Promise<Request>;
203
+ (param: RequestWillFetchCallbackParam): PromiseOrNot<Request>;
203
204
  }
204
205
  export interface HandlerWillRespondCallbackParam {
205
206
  request: Request;
@@ -208,7 +209,7 @@ export interface HandlerWillRespondCallbackParam {
208
209
  state?: PluginState;
209
210
  }
210
211
  export interface HandlerWillRespondCallback {
211
- (param: HandlerWillRespondCallbackParam): Promise<Response>;
212
+ (param: HandlerWillRespondCallbackParam): PromiseOrNot<Response>;
212
213
  }
213
214
  export interface HandlerDidErrorCallbackParam {
214
215
  request: Request;
@@ -217,7 +218,7 @@ export interface HandlerDidErrorCallbackParam {
217
218
  state?: PluginState;
218
219
  }
219
220
  export interface HandlerDidErrorCallback {
220
- (param: HandlerDidErrorCallbackParam): Promise<Response | undefined>;
221
+ (param: HandlerDidErrorCallbackParam): PromiseOrNot<Response | undefined>;
221
222
  }
222
223
  export interface HandlerDidRespondCallbackParam {
223
224
  request: Request;
@@ -226,7 +227,7 @@ export interface HandlerDidRespondCallbackParam {
226
227
  state?: PluginState;
227
228
  }
228
229
  export interface HandlerDidRespondCallback {
229
- (param: HandlerDidRespondCallbackParam): Promise<any>;
230
+ (param: HandlerDidRespondCallbackParam): PromiseOrNot<any>;
230
231
  }
231
232
  export interface HandlerDidCompleteCallbackParam {
232
233
  request: Request;
@@ -236,7 +237,7 @@ export interface HandlerDidCompleteCallbackParam {
236
237
  state?: PluginState;
237
238
  }
238
239
  export interface HandlerDidCompleteCallback {
239
- (param: HandlerDidCompleteCallbackParam): Promise<any>;
240
+ (param: HandlerDidCompleteCallbackParam): PromiseOrNot<any>;
240
241
  }
241
242
  /**
242
243
  * An object with optional lifecycle callback properties for the fetch and
@@ -270,4 +271,9 @@ export interface SerwistPluginCallbackParam {
270
271
  handlerWillStart: HandlerWillStartCallbackParam;
271
272
  requestWillFetch: RequestWillFetchCallbackParam;
272
273
  }
274
+ export interface SerwistGlobalConfig {
275
+ __WB_DISABLE_DEV_LOGS: boolean;
276
+ __WB_FORCE_RUNTIME_CACHING: boolean;
277
+ __WB_CONCURRENT_PRECACHING: number;
278
+ }
273
279
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,aAAa;IAC5B,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,aAAa,CAAC;AAExC;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,KAAK,EAAE,eAAe,CAAC;IACvB,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,OAAO,CAAC;IACpB,GAAG,EAAE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AAiB,EAAE,8BAA8B,CAAC;IAClD,kBAAkB,EAAE,+BAA+B,CAAC;IACpD,gBAAgB,EAAE,6BAA6B,CAAC;IAChD,gBAAgB,EAAE,6BAA6B,CAAC;CACjD;AAED,MAAM,WAAW,mBAAmB;IAClC,qBAAqB,EAAE,OAAO,CAAC;IAC/B,0BAA0B,EAAE,OAAO,CAAC;IACpC,0BAA0B,EAAE,MAAM,CAAC;CACpC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serwist/core",
3
- "version": "9.0.0-preview.0",
3
+ "version": "9.0.0-preview.10",
4
4
  "type": "module",
5
5
  "description": "This module is used by a number of the other Serwist modules to share common code.",
6
6
  "files": [
@@ -39,8 +39,8 @@
39
39
  },
40
40
  "devDependencies": {
41
41
  "rollup": "4.9.6",
42
- "typescript": "5.4.0-dev.20240203",
43
- "@serwist/constants": "9.0.0-preview.0"
42
+ "typescript": "5.4.0-dev.20240206",
43
+ "@serwist/constants": "9.0.0-preview.10"
44
44
  },
45
45
  "peerDependencies": {
46
46
  "typescript": ">=5.0.0"
@@ -7,6 +7,7 @@
7
7
  */
8
8
 
9
9
  import { messageGenerator } from "../models/messages/messageGenerator.js";
10
+ import type { MessageKey } from "../models/messages/messages.js";
10
11
  import type { MapLikeObject } from "../types.js";
11
12
 
12
13
  /**
@@ -29,7 +30,7 @@ class SerwistError extends Error {
29
30
  * that will help developers identify issues should
30
31
  * be added as a key on the context object.
31
32
  */
32
- constructor(errorCode: string, details?: MapLikeObject) {
33
+ constructor(errorCode: MessageKey, details?: MapLikeObject) {
33
34
  const message = messageGenerator(errorCode, details);
34
35
 
35
36
  super(message);
@@ -16,11 +16,16 @@ declare global {
16
16
  }
17
17
  }
18
18
 
19
- type LoggerMethods = "debug" | "log" | "warn" | "error" | "groupCollapsed" | "groupEnd";
20
-
21
- const logger = (
19
+ /**
20
+ * The logger used by Serwist inside of both service workers and the window global scope.
21
+ *
22
+ * Note: This is forcibly `null` in production mode to reduce bundle size. Do check whether
23
+ * you are currently in development mode (by using `process.env.NODE_ENV !== "production"`)
24
+ * before using it.
25
+ */
26
+ export const logger =
22
27
  process.env.NODE_ENV === "production"
23
- ? null
28
+ ? null!
24
29
  : (() => {
25
30
  // Don't overwrite this value if it's already set.
26
31
  // See https://github.com/GoogleChrome/workbox/pull/2284#issuecomment-560470923
@@ -30,7 +35,7 @@ const logger = (
30
35
 
31
36
  let inGroup = false;
32
37
 
33
- const methodToColorMap: { [methodName: string]: string | null } = {
38
+ const methodToColorMap = {
34
39
  debug: "#7f8c8d", // Gray
35
40
  log: "#2ecc71", // Green
36
41
  warn: "#f39c12", // Yellow
@@ -39,6 +44,8 @@ const logger = (
39
44
  groupEnd: null, // No colored prefix on groupEnd
40
45
  };
41
46
 
47
+ type LoggerMethods = keyof typeof methodToColorMap;
48
+
42
49
  const print = (method: LoggerMethods, args: any[]) => {
43
50
  if (self.__WB_DISABLE_DEV_LOGS) {
44
51
  return;
@@ -73,20 +80,16 @@ const logger = (
73
80
  inGroup = false;
74
81
  }
75
82
  };
76
- // biome-ignore lint/complexity/noBannedTypes: Unknown reason
77
- const api: { [methodName: string]: Function } = {};
78
- const loggerMethods = Object.keys(methodToColorMap);
79
-
80
- for (const key of loggerMethods) {
81
- const method = key as LoggerMethods;
82
-
83
- api[method] = (...args: any[]) => {
84
- print(method, args);
85
- };
86
- }
87
-
88
- return api as unknown;
89
- })()
90
- ) as Console;
91
83
 
92
- export { logger };
84
+ const loggerMethods = Object.keys(methodToColorMap) as LoggerMethods[];
85
+
86
+ return loggerMethods.reduce(
87
+ (api, method) => {
88
+ api[method] = (...args: any[]) => {
89
+ print(method, args);
90
+ };
91
+ return api;
92
+ },
93
+ {} as { [method in LoggerMethods]: (...args: any[]) => void },
94
+ );
95
+ })();
@@ -14,10 +14,8 @@
14
14
  * @returns
15
15
  * @private
16
16
  */
17
- function waitUntil(event: ExtendableEvent, asyncFn: () => Promise<any>): Promise<any> {
17
+ export const waitUntil = <T = any>(event: ExtendableEvent, asyncFn: () => Promise<T>): Promise<T> => {
18
18
  const returnPromise = asyncFn();
19
19
  event.waitUntil(returnPromise);
20
20
  return returnPromise;
21
- }
22
-
23
- export { waitUntil };
21
+ };
@@ -10,7 +10,7 @@
10
10
  declare let self: ServiceWorkerGlobalScope;
11
11
 
12
12
  /**
13
- * Claim any currently available clients once the service worker
13
+ * Claims any currently available clients once the service worker
14
14
  * becomes active. This is normally used in conjunction with `skipWaiting()`.
15
15
  */
16
16
  function clientsClaim(): void {
package/src/index.ts CHANGED
@@ -17,4 +17,4 @@ import { setCacheNameDetails } from "./setCacheNameDetails.js";
17
17
  */
18
18
  export { cacheNames, clientsClaim, copyResponse, registerQuotaErrorCallback, setCacheNameDetails };
19
19
 
20
- export * from "./types.js";
20
+ export type * from "./types.js";
@@ -6,7 +6,8 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import { messages } from "./messages.js";
9
+ import type { MapLikeObject } from "../../types.js";
10
+ import { type MessageKey, messages } from "./messages.js";
10
11
 
11
12
  const fallback = (code: string, ...args: any[]) => {
12
13
  let msg = code;
@@ -16,7 +17,7 @@ const fallback = (code: string, ...args: any[]) => {
16
17
  return msg;
17
18
  };
18
19
 
19
- const generatorFunction = (code: string, details = {}) => {
20
+ const generatorFunction = (code: MessageKey, details: MapLikeObject = {}) => {
20
21
  const message = messages[code];
21
22
  if (!message) {
22
23
  throw new Error(`Unable to find message for code '${code}'.`);
@@ -13,7 +13,7 @@ interface MessageMap {
13
13
  [messageID: string]: (param: LoggableObject) => string;
14
14
  }
15
15
 
16
- export const messages: MessageMap = {
16
+ export const messages = {
17
17
  "invalid-value": ({ paramName, validValueDescription, value }) => {
18
18
  if (!paramName || !validValueDescription) {
19
19
  throw new Error(`Unexpected input to 'invalid-value' error.`);
@@ -82,7 +82,7 @@ export const messages: MessageMap = {
82
82
  throw new Error("Unexpected input to " + `'plugin-error-request-will-fetch', error.`);
83
83
  }
84
84
 
85
- return `An error was thrown by a plugins 'requestWillFetch()' method. The thrown error message was: '${thrownErrorMessage}'.`;
85
+ return `An error was thrown by a plugin's 'requestWillFetch()' method. The thrown error message was: '${thrownErrorMessage}'.`;
86
86
  },
87
87
 
88
88
  "invalid-cache-name": ({ cacheNameId, value }) => {
@@ -228,4 +228,6 @@ export const messages: MessageMap = {
228
228
  }
229
229
  return `${message} Please ensure your sources are CORS-enabled.`;
230
230
  },
231
- };
231
+ } satisfies MessageMap;
232
+
233
+ export type MessageKey = keyof typeof messages;
@@ -12,7 +12,7 @@ import type { PartialCacheNameDetails } from "./_private/cacheNames.js";
12
12
  import { cacheNames } from "./_private/cacheNames.js";
13
13
 
14
14
  /**
15
- * Modifies the default cache names used by the Serwist packages.
15
+ * Modifies the default cache names used by Serwist packages.
16
16
  * Cache names are generated as `<prefix>-<Cache Name>-<suffix>`.
17
17
  *
18
18
  * @param details
package/src/types.ts CHANGED
@@ -5,6 +5,7 @@
5
5
  license that can be found in the LICENSE file or at
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
+ export type PromiseOrNot<T> = T | Promise<T>;
8
9
 
9
10
  export interface MapLikeObject {
10
11
  [key: string]: any;
@@ -152,7 +153,7 @@ export interface CacheDidUpdateCallbackParam {
152
153
  }
153
154
 
154
155
  export interface CacheDidUpdateCallback {
155
- (param: CacheDidUpdateCallbackParam): Promise<any>;
156
+ (param: CacheDidUpdateCallbackParam): PromiseOrNot<any>;
156
157
  }
157
158
 
158
159
  export interface CacheKeyWillBeUsedCallbackParam {
@@ -164,7 +165,7 @@ export interface CacheKeyWillBeUsedCallbackParam {
164
165
  }
165
166
 
166
167
  export interface CacheKeyWillBeUsedCallback {
167
- (param: CacheKeyWillBeUsedCallbackParam): Promise<Request | string>;
168
+ (param: CacheKeyWillBeUsedCallbackParam): PromiseOrNot<Request | string>;
168
169
  }
169
170
 
170
171
  export interface CacheWillUpdateCallbackParam {
@@ -175,7 +176,7 @@ export interface CacheWillUpdateCallbackParam {
175
176
  }
176
177
 
177
178
  export interface CacheWillUpdateCallback {
178
- (param: CacheWillUpdateCallbackParam): Promise<any>;
179
+ (param: CacheWillUpdateCallbackParam): PromiseOrNot<any>;
179
180
  }
180
181
 
181
182
  export interface CachedResponseWillBeUsedCallbackParam {
@@ -199,7 +200,7 @@ export interface CachedResponseWillBeUsedCallbackParam {
199
200
  }
200
201
 
201
202
  export interface CachedResponseWillBeUsedCallback {
202
- (param: CachedResponseWillBeUsedCallbackParam): Promise<any>;
203
+ (param: CachedResponseWillBeUsedCallbackParam): PromiseOrNot<any>;
203
204
  }
204
205
 
205
206
  export interface FetchDidFailCallbackParam {
@@ -211,7 +212,7 @@ export interface FetchDidFailCallbackParam {
211
212
  }
212
213
 
213
214
  export interface FetchDidFailCallback {
214
- (param: FetchDidFailCallbackParam): Promise<any>;
215
+ (param: FetchDidFailCallbackParam): PromiseOrNot<any>;
215
216
  }
216
217
 
217
218
  export interface FetchDidSucceedCallbackParam {
@@ -222,7 +223,7 @@ export interface FetchDidSucceedCallbackParam {
222
223
  }
223
224
 
224
225
  export interface FetchDidSucceedCallback {
225
- (param: FetchDidSucceedCallbackParam): Promise<Response>;
226
+ (param: FetchDidSucceedCallbackParam): PromiseOrNot<Response>;
226
227
  }
227
228
 
228
229
  export interface RequestWillFetchCallbackParam {
@@ -232,7 +233,7 @@ export interface RequestWillFetchCallbackParam {
232
233
  }
233
234
 
234
235
  export interface RequestWillFetchCallback {
235
- (param: RequestWillFetchCallbackParam): Promise<Request>;
236
+ (param: RequestWillFetchCallbackParam): PromiseOrNot<Request>;
236
237
  }
237
238
 
238
239
  export interface HandlerWillRespondCallbackParam {
@@ -243,7 +244,7 @@ export interface HandlerWillRespondCallbackParam {
243
244
  }
244
245
 
245
246
  export interface HandlerWillRespondCallback {
246
- (param: HandlerWillRespondCallbackParam): Promise<Response>;
247
+ (param: HandlerWillRespondCallbackParam): PromiseOrNot<Response>;
247
248
  }
248
249
 
249
250
  export interface HandlerDidErrorCallbackParam {
@@ -254,7 +255,7 @@ export interface HandlerDidErrorCallbackParam {
254
255
  }
255
256
 
256
257
  export interface HandlerDidErrorCallback {
257
- (param: HandlerDidErrorCallbackParam): Promise<Response | undefined>;
258
+ (param: HandlerDidErrorCallbackParam): PromiseOrNot<Response | undefined>;
258
259
  }
259
260
 
260
261
  export interface HandlerDidRespondCallbackParam {
@@ -265,7 +266,7 @@ export interface HandlerDidRespondCallbackParam {
265
266
  }
266
267
 
267
268
  export interface HandlerDidRespondCallback {
268
- (param: HandlerDidRespondCallbackParam): Promise<any>;
269
+ (param: HandlerDidRespondCallbackParam): PromiseOrNot<any>;
269
270
  }
270
271
 
271
272
  export interface HandlerDidCompleteCallbackParam {
@@ -277,7 +278,7 @@ export interface HandlerDidCompleteCallbackParam {
277
278
  }
278
279
 
279
280
  export interface HandlerDidCompleteCallback {
280
- (param: HandlerDidCompleteCallbackParam): Promise<any>;
281
+ (param: HandlerDidCompleteCallbackParam): PromiseOrNot<any>;
281
282
  }
282
283
 
283
284
  /**
@@ -313,3 +314,9 @@ export interface SerwistPluginCallbackParam {
313
314
  handlerWillStart: HandlerWillStartCallbackParam;
314
315
  requestWillFetch: RequestWillFetchCallbackParam;
315
316
  }
317
+
318
+ export interface SerwistGlobalConfig {
319
+ __WB_DISABLE_DEV_LOGS: boolean;
320
+ __WB_FORCE_RUNTIME_CACHING: boolean;
321
+ __WB_CONCURRENT_PRECACHING: number;
322
+ }