@serwist/core 8.1.0 → 8.2.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/_private/Deferred.d.cts +18 -0
- package/dist/_private/SerwistError.d.cts +23 -0
- package/dist/_private/assert.d.cts +10 -0
- package/dist/_private/cacheMatchIgnoreParams.d.cts +14 -0
- package/dist/_private/cacheNames.d.cts +39 -0
- package/dist/_private/canConstructReadableStream.d.cts +11 -0
- package/dist/_private/canConstructResponseFromBodyStream.d.cts +10 -0
- package/dist/_private/dontWaitFor.d.cts +6 -0
- package/dist/_private/executeQuotaErrorCallbacks.d.cts +8 -0
- package/dist/_private/getFriendlyURL.d.cts +2 -0
- package/dist/_private/logger.d.cts +10 -0
- package/dist/_private/resultingClientExists.d.cts +11 -0
- package/dist/_private/timeout.d.cts +9 -0
- package/dist/_private/waitUntil.d.cts +11 -0
- package/dist/cacheNames.d.cts +20 -0
- package/dist/clientsClaim.d.cts +6 -0
- package/dist/copyResponse.d.cts +20 -0
- package/dist/index.cjs +154 -0
- package/dist/index.d.cts +0 -0
- package/dist/index.internal.cjs +244 -0
- package/dist/index.internal.js +7 -429
- package/dist/index.js +1 -424
- package/dist/models/messages/messageGenerator.d.cts +1 -0
- package/dist/models/messages/messages.d.cts +8 -0
- package/dist/models/pluginEvents.d.cts +9 -0
- package/dist/models/quotaErrorCallbacks.d.cts +2 -0
- package/dist/{index.internal.old.cjs → quotaErrorCallbacks-efexit-Y.js} +81 -322
- package/dist/{index.old.cjs → quotaErrorCallbacks-t3P-jWKl.js} +6 -150
- package/dist/registerQuotaErrorCallback.d.cts +8 -0
- package/dist/setCacheNameDetails.d.cts +9 -0
- package/dist/types.d.cts +272 -0
- package/dist/utils/pluginUtils.d.cts +4 -0
- package/dist/utils/welcome.d.cts +1 -0
- package/package.json +7 -7
- package/dist/index.old.d.cts +0 -11
- /package/dist/{index.internal.old.d.cts → index.internal.d.cts} +0 -0
|
@@ -1,4 +1,83 @@
|
|
|
1
|
-
|
|
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 = {
|
|
8
|
+
googleAnalytics: "googleAnalytics",
|
|
9
|
+
precache: "precache-v2",
|
|
10
|
+
prefix: "serwist",
|
|
11
|
+
runtime: "runtime",
|
|
12
|
+
suffix: typeof registration !== "undefined" ? registration.scope : ""
|
|
13
|
+
};
|
|
14
|
+
const _createCacheName = (cacheName)=>{
|
|
15
|
+
return [
|
|
16
|
+
_cacheNameDetails.prefix,
|
|
17
|
+
cacheName,
|
|
18
|
+
_cacheNameDetails.suffix
|
|
19
|
+
].filter((value)=>value && value.length > 0).join("-");
|
|
20
|
+
};
|
|
21
|
+
const eachCacheNameDetail = (fn)=>{
|
|
22
|
+
for (const key of Object.keys(_cacheNameDetails)){
|
|
23
|
+
fn(key);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const cacheNames = {
|
|
27
|
+
updateDetails: (details)=>{
|
|
28
|
+
eachCacheNameDetail((key)=>{
|
|
29
|
+
const detail = details[key];
|
|
30
|
+
if (typeof detail === "string") {
|
|
31
|
+
_cacheNameDetails[key] = detail;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
},
|
|
35
|
+
getGoogleAnalyticsName: (userCacheName)=>{
|
|
36
|
+
return userCacheName || _createCacheName(_cacheNameDetails.googleAnalytics);
|
|
37
|
+
},
|
|
38
|
+
getPrecacheName: (userCacheName)=>{
|
|
39
|
+
return userCacheName || _createCacheName(_cacheNameDetails.precache);
|
|
40
|
+
},
|
|
41
|
+
getPrefix: ()=>{
|
|
42
|
+
return _cacheNameDetails.prefix;
|
|
43
|
+
},
|
|
44
|
+
getRuntimeName: (userCacheName)=>{
|
|
45
|
+
return userCacheName || _createCacheName(_cacheNameDetails.runtime);
|
|
46
|
+
},
|
|
47
|
+
getSuffix: ()=>{
|
|
48
|
+
return _cacheNameDetails.suffix;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/*
|
|
53
|
+
Copyright 2019 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
|
+
*/ let supportStatus;
|
|
59
|
+
/**
|
|
60
|
+
* A utility function that determines whether the current browser supports
|
|
61
|
+
* constructing a new `Response` from a `response.body` stream.
|
|
62
|
+
*
|
|
63
|
+
* @returns `true`, if the current browser can successfully construct
|
|
64
|
+
* a `Response` from a `response.body` stream, `false` otherwise.
|
|
65
|
+
* @private
|
|
66
|
+
*/ function canConstructResponseFromBodyStream() {
|
|
67
|
+
if (supportStatus === undefined) {
|
|
68
|
+
const testResponse = new Response("");
|
|
69
|
+
if ("body" in testResponse) {
|
|
70
|
+
try {
|
|
71
|
+
new Response(testResponse.body);
|
|
72
|
+
supportStatus = true;
|
|
73
|
+
} catch (error) {
|
|
74
|
+
supportStatus = false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
supportStatus = false;
|
|
78
|
+
}
|
|
79
|
+
return supportStatus;
|
|
80
|
+
}
|
|
2
81
|
|
|
3
82
|
/*
|
|
4
83
|
Copyright 2018 Google LLC
|
|
@@ -268,202 +347,6 @@ const finalAssertExports = process.env.NODE_ENV === "production" ? null : {
|
|
|
268
347
|
isArrayOfClass
|
|
269
348
|
};
|
|
270
349
|
|
|
271
|
-
/*
|
|
272
|
-
Copyright 2020 Google LLC
|
|
273
|
-
Use of this source code is governed by an MIT-style
|
|
274
|
-
license that can be found in the LICENSE file or at
|
|
275
|
-
https://opensource.org/licenses/MIT.
|
|
276
|
-
*/ function stripParams(fullURL, ignoreParams) {
|
|
277
|
-
const strippedURL = new URL(fullURL);
|
|
278
|
-
for (const param of ignoreParams){
|
|
279
|
-
strippedURL.searchParams.delete(param);
|
|
280
|
-
}
|
|
281
|
-
return strippedURL.href;
|
|
282
|
-
}
|
|
283
|
-
/**
|
|
284
|
-
* Matches an item in the cache, ignoring specific URL params. This is similar
|
|
285
|
-
* to the `ignoreSearch` option, but it allows you to ignore just specific
|
|
286
|
-
* params (while continuing to match on the others).
|
|
287
|
-
*
|
|
288
|
-
* @private
|
|
289
|
-
* @param cache
|
|
290
|
-
* @param request
|
|
291
|
-
* @param matchOptions
|
|
292
|
-
* @param ignoreParams
|
|
293
|
-
* @returns
|
|
294
|
-
*/ async function cacheMatchIgnoreParams(cache, request, ignoreParams, matchOptions) {
|
|
295
|
-
const strippedRequestURL = stripParams(request.url, ignoreParams);
|
|
296
|
-
// If the request doesn't include any ignored params, match as normal.
|
|
297
|
-
if (request.url === strippedRequestURL) {
|
|
298
|
-
return cache.match(request, matchOptions);
|
|
299
|
-
}
|
|
300
|
-
// Otherwise, match by comparing keys
|
|
301
|
-
const keysOptions = {
|
|
302
|
-
...matchOptions,
|
|
303
|
-
ignoreSearch: true
|
|
304
|
-
};
|
|
305
|
-
const cacheKeys = await cache.keys(request, keysOptions);
|
|
306
|
-
for (const cacheKey of cacheKeys){
|
|
307
|
-
const strippedCacheKeyURL = stripParams(cacheKey.url, ignoreParams);
|
|
308
|
-
if (strippedRequestURL === strippedCacheKeyURL) {
|
|
309
|
-
return cache.match(cacheKey, matchOptions);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
/*
|
|
316
|
-
Copyright 2018 Google LLC
|
|
317
|
-
|
|
318
|
-
Use of this source code is governed by an MIT-style
|
|
319
|
-
license that can be found in the LICENSE file or at
|
|
320
|
-
https://opensource.org/licenses/MIT.
|
|
321
|
-
*/ const _cacheNameDetails = {
|
|
322
|
-
googleAnalytics: "googleAnalytics",
|
|
323
|
-
precache: "precache-v2",
|
|
324
|
-
prefix: "serwist",
|
|
325
|
-
runtime: "runtime",
|
|
326
|
-
suffix: typeof registration !== "undefined" ? registration.scope : ""
|
|
327
|
-
};
|
|
328
|
-
const _createCacheName = (cacheName)=>{
|
|
329
|
-
return [
|
|
330
|
-
_cacheNameDetails.prefix,
|
|
331
|
-
cacheName,
|
|
332
|
-
_cacheNameDetails.suffix
|
|
333
|
-
].filter((value)=>value && value.length > 0).join("-");
|
|
334
|
-
};
|
|
335
|
-
const eachCacheNameDetail = (fn)=>{
|
|
336
|
-
for (const key of Object.keys(_cacheNameDetails)){
|
|
337
|
-
fn(key);
|
|
338
|
-
}
|
|
339
|
-
};
|
|
340
|
-
const cacheNames = {
|
|
341
|
-
updateDetails: (details)=>{
|
|
342
|
-
eachCacheNameDetail((key)=>{
|
|
343
|
-
const detail = details[key];
|
|
344
|
-
if (typeof detail === "string") {
|
|
345
|
-
_cacheNameDetails[key] = detail;
|
|
346
|
-
}
|
|
347
|
-
});
|
|
348
|
-
},
|
|
349
|
-
getGoogleAnalyticsName: (userCacheName)=>{
|
|
350
|
-
return userCacheName || _createCacheName(_cacheNameDetails.googleAnalytics);
|
|
351
|
-
},
|
|
352
|
-
getPrecacheName: (userCacheName)=>{
|
|
353
|
-
return userCacheName || _createCacheName(_cacheNameDetails.precache);
|
|
354
|
-
},
|
|
355
|
-
getPrefix: ()=>{
|
|
356
|
-
return _cacheNameDetails.prefix;
|
|
357
|
-
},
|
|
358
|
-
getRuntimeName: (userCacheName)=>{
|
|
359
|
-
return userCacheName || _createCacheName(_cacheNameDetails.runtime);
|
|
360
|
-
},
|
|
361
|
-
getSuffix: ()=>{
|
|
362
|
-
return _cacheNameDetails.suffix;
|
|
363
|
-
}
|
|
364
|
-
};
|
|
365
|
-
|
|
366
|
-
/*
|
|
367
|
-
Copyright 2019 Google LLC
|
|
368
|
-
|
|
369
|
-
Use of this source code is governed by an MIT-style
|
|
370
|
-
license that can be found in the LICENSE file or at
|
|
371
|
-
https://opensource.org/licenses/MIT.
|
|
372
|
-
*/ let supportStatus$1;
|
|
373
|
-
/**
|
|
374
|
-
* A utility function that determines whether the current browser supports
|
|
375
|
-
* constructing a [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/ReadableStream)
|
|
376
|
-
* object.
|
|
377
|
-
*
|
|
378
|
-
* @returns `true`, if the current browser can successfully construct a `ReadableStream`, `false` otherwise.
|
|
379
|
-
*
|
|
380
|
-
* @private
|
|
381
|
-
*/ function canConstructReadableStream() {
|
|
382
|
-
if (supportStatus$1 === undefined) {
|
|
383
|
-
// See https://github.com/GoogleChrome/workbox/issues/1473
|
|
384
|
-
try {
|
|
385
|
-
new ReadableStream({
|
|
386
|
-
start () {}
|
|
387
|
-
});
|
|
388
|
-
supportStatus$1 = true;
|
|
389
|
-
} catch (error) {
|
|
390
|
-
supportStatus$1 = false;
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
return supportStatus$1;
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
/*
|
|
397
|
-
Copyright 2019 Google LLC
|
|
398
|
-
|
|
399
|
-
Use of this source code is governed by an MIT-style
|
|
400
|
-
license that can be found in the LICENSE file or at
|
|
401
|
-
https://opensource.org/licenses/MIT.
|
|
402
|
-
*/ let supportStatus;
|
|
403
|
-
/**
|
|
404
|
-
* A utility function that determines whether the current browser supports
|
|
405
|
-
* constructing a new `Response` from a `response.body` stream.
|
|
406
|
-
*
|
|
407
|
-
* @returns `true`, if the current browser can successfully construct
|
|
408
|
-
* a `Response` from a `response.body` stream, `false` otherwise.
|
|
409
|
-
* @private
|
|
410
|
-
*/ function canConstructResponseFromBodyStream() {
|
|
411
|
-
if (supportStatus === undefined) {
|
|
412
|
-
const testResponse = new Response("");
|
|
413
|
-
if ("body" in testResponse) {
|
|
414
|
-
try {
|
|
415
|
-
new Response(testResponse.body);
|
|
416
|
-
supportStatus = true;
|
|
417
|
-
} catch (error) {
|
|
418
|
-
supportStatus = false;
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
supportStatus = false;
|
|
422
|
-
}
|
|
423
|
-
return supportStatus;
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
/*
|
|
427
|
-
Copyright 2018 Google LLC
|
|
428
|
-
|
|
429
|
-
Use of this source code is governed by an MIT-style
|
|
430
|
-
license that can be found in the LICENSE file or at
|
|
431
|
-
https://opensource.org/licenses/MIT.
|
|
432
|
-
*/ /**
|
|
433
|
-
* The Deferred class composes Promises in a way that allows for them to be
|
|
434
|
-
* resolved or rejected from outside the constructor. In most cases promises
|
|
435
|
-
* should be used directly, but Deferreds can be necessary when the logic to
|
|
436
|
-
* resolve a promise must be separate.
|
|
437
|
-
*
|
|
438
|
-
* @private
|
|
439
|
-
*/ class Deferred {
|
|
440
|
-
promise;
|
|
441
|
-
resolve;
|
|
442
|
-
reject;
|
|
443
|
-
/**
|
|
444
|
-
* Creates a promise and exposes its resolve and reject functions as methods.
|
|
445
|
-
*/ constructor(){
|
|
446
|
-
this.promise = new Promise((resolve, reject)=>{
|
|
447
|
-
this.resolve = resolve;
|
|
448
|
-
this.reject = reject;
|
|
449
|
-
});
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
/*
|
|
454
|
-
Copyright 2019 Google LLC
|
|
455
|
-
Use of this source code is governed by an MIT-style
|
|
456
|
-
license that can be found in the LICENSE file or at
|
|
457
|
-
https://opensource.org/licenses/MIT.
|
|
458
|
-
*/ /**
|
|
459
|
-
* A helper function that prevents a promise from being flagged as unused.
|
|
460
|
-
*
|
|
461
|
-
* @private
|
|
462
|
-
**/ function dontWaitFor(promise) {
|
|
463
|
-
// Effective no-op.
|
|
464
|
-
void promise.then(()=>{});
|
|
465
|
-
}
|
|
466
|
-
|
|
467
350
|
/*
|
|
468
351
|
Copyright 2019 Google LLC
|
|
469
352
|
Use of this source code is governed by an MIT-style
|
|
@@ -540,128 +423,4 @@ const logger = process.env.NODE_ENV === "production" ? null : (()=>{
|
|
|
540
423
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
541
424
|
const quotaErrorCallbacks = new Set();
|
|
542
425
|
|
|
543
|
-
|
|
544
|
-
* Runs all of the callback functions, one at a time sequentially, in the order
|
|
545
|
-
* in which they were registered.
|
|
546
|
-
*
|
|
547
|
-
* @private
|
|
548
|
-
*/ async function executeQuotaErrorCallbacks() {
|
|
549
|
-
if (process.env.NODE_ENV !== "production") {
|
|
550
|
-
logger.log(`About to run ${quotaErrorCallbacks.size} ` + `callbacks to clean up caches.`);
|
|
551
|
-
}
|
|
552
|
-
for (const callback of quotaErrorCallbacks){
|
|
553
|
-
await callback();
|
|
554
|
-
if (process.env.NODE_ENV !== "production") {
|
|
555
|
-
logger.log(callback, "is complete.");
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
if (process.env.NODE_ENV !== "production") {
|
|
559
|
-
logger.log("Finished running callbacks.");
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
/*
|
|
564
|
-
Copyright 2018 Google LLC
|
|
565
|
-
|
|
566
|
-
Use of this source code is governed by an MIT-style
|
|
567
|
-
license that can be found in the LICENSE file or at
|
|
568
|
-
https://opensource.org/licenses/MIT.
|
|
569
|
-
*/ const getFriendlyURL = (url)=>{
|
|
570
|
-
const urlObj = new URL(String(url), location.href);
|
|
571
|
-
// See https://github.com/GoogleChrome/workbox/issues/2323
|
|
572
|
-
// We want to include everything, except for the origin if it's same-origin.
|
|
573
|
-
return urlObj.href.replace(new RegExp(`^${location.origin}`), "");
|
|
574
|
-
};
|
|
575
|
-
|
|
576
|
-
/*
|
|
577
|
-
Copyright 2019 Google LLC
|
|
578
|
-
Use of this source code is governed by an MIT-style
|
|
579
|
-
license that can be found in the LICENSE file or at
|
|
580
|
-
https://opensource.org/licenses/MIT.
|
|
581
|
-
*/ /**
|
|
582
|
-
* Returns a promise that resolves and the passed number of milliseconds.
|
|
583
|
-
* This utility is an async/await-friendly version of `setTimeout`.
|
|
584
|
-
*
|
|
585
|
-
* @param ms
|
|
586
|
-
* @returns
|
|
587
|
-
* @private
|
|
588
|
-
*/ function timeout(ms) {
|
|
589
|
-
return new Promise((resolve)=>setTimeout(resolve, ms));
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
const MAX_RETRY_TIME = 2000;
|
|
593
|
-
/**
|
|
594
|
-
* Returns a promise that resolves to a window client matching the passed
|
|
595
|
-
* `resultingClientId`. For browsers that don't support `resultingClientId`
|
|
596
|
-
* or if waiting for the resulting client to apper takes too long, resolve to
|
|
597
|
-
* `undefined`.
|
|
598
|
-
*
|
|
599
|
-
* @param resultingClientId
|
|
600
|
-
* @returns
|
|
601
|
-
* @private
|
|
602
|
-
*/ async function resultingClientExists(resultingClientId) {
|
|
603
|
-
if (!resultingClientId) {
|
|
604
|
-
return;
|
|
605
|
-
}
|
|
606
|
-
let existingWindows = await self.clients.matchAll({
|
|
607
|
-
type: "window"
|
|
608
|
-
});
|
|
609
|
-
const existingWindowIds = new Set(existingWindows.map((w)=>w.id));
|
|
610
|
-
let resultingWindow;
|
|
611
|
-
const startTime = performance.now();
|
|
612
|
-
// Only wait up to `MAX_RETRY_TIME` to find a matching client.
|
|
613
|
-
while(performance.now() - startTime < MAX_RETRY_TIME){
|
|
614
|
-
existingWindows = await self.clients.matchAll({
|
|
615
|
-
type: "window"
|
|
616
|
-
});
|
|
617
|
-
resultingWindow = existingWindows.find((w)=>{
|
|
618
|
-
if (resultingClientId) {
|
|
619
|
-
// If we have a `resultingClientId`, we can match on that.
|
|
620
|
-
return w.id === resultingClientId;
|
|
621
|
-
} else {
|
|
622
|
-
// Otherwise match on finding a window not in `existingWindowIds`.
|
|
623
|
-
return !existingWindowIds.has(w.id);
|
|
624
|
-
}
|
|
625
|
-
});
|
|
626
|
-
if (resultingWindow) {
|
|
627
|
-
break;
|
|
628
|
-
}
|
|
629
|
-
// Sleep for 100ms and retry.
|
|
630
|
-
await timeout(100);
|
|
631
|
-
}
|
|
632
|
-
return resultingWindow;
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
/*
|
|
636
|
-
Copyright 2020 Google LLC
|
|
637
|
-
Use of this source code is governed by an MIT-style
|
|
638
|
-
license that can be found in the LICENSE file or at
|
|
639
|
-
https://opensource.org/licenses/MIT.
|
|
640
|
-
*/ /**
|
|
641
|
-
* A utility method that makes it easier to use `event.waitUntil` with
|
|
642
|
-
* async functions and return the result.
|
|
643
|
-
*
|
|
644
|
-
* @param event
|
|
645
|
-
* @param asyncFn
|
|
646
|
-
* @returns
|
|
647
|
-
* @private
|
|
648
|
-
*/ function waitUntil(event, asyncFn) {
|
|
649
|
-
const returnPromise = asyncFn();
|
|
650
|
-
event.waitUntil(returnPromise);
|
|
651
|
-
return returnPromise;
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
exports.Deferred = Deferred;
|
|
655
|
-
exports.SerwistError = SerwistError;
|
|
656
|
-
exports.assert = finalAssertExports;
|
|
657
|
-
exports.cacheMatchIgnoreParams = cacheMatchIgnoreParams;
|
|
658
|
-
exports.canConstructReadableStream = canConstructReadableStream;
|
|
659
|
-
exports.canConstructResponseFromBodyStream = canConstructResponseFromBodyStream;
|
|
660
|
-
exports.dontWaitFor = dontWaitFor;
|
|
661
|
-
exports.executeQuotaErrorCallbacks = executeQuotaErrorCallbacks;
|
|
662
|
-
exports.getFriendlyURL = getFriendlyURL;
|
|
663
|
-
exports.logger = logger;
|
|
664
|
-
exports.privateCacheNames = cacheNames;
|
|
665
|
-
exports.resultingClientExists = resultingClientExists;
|
|
666
|
-
exports.timeout = timeout;
|
|
667
|
-
exports.waitUntil = waitUntil;
|
|
426
|
+
export { SerwistError as S, canConstructResponseFromBodyStream as a, cacheNames as c, finalAssertExports as f, logger as l, quotaErrorCallbacks as q };
|
|
@@ -25,7 +25,7 @@ const eachCacheNameDetail = (fn)=>{
|
|
|
25
25
|
fn(key);
|
|
26
26
|
}
|
|
27
27
|
};
|
|
28
|
-
const cacheNames
|
|
28
|
+
const cacheNames = {
|
|
29
29
|
updateDetails: (details)=>{
|
|
30
30
|
eachCacheNameDetail((key)=>{
|
|
31
31
|
const detail = details[key];
|
|
@@ -51,49 +51,6 @@ const cacheNames$1 = {
|
|
|
51
51
|
}
|
|
52
52
|
};
|
|
53
53
|
|
|
54
|
-
/**
|
|
55
|
-
* Get the current cache names and prefix/suffix used by Workbox.
|
|
56
|
-
*
|
|
57
|
-
* `cacheNames.precache` is used for precached assets,
|
|
58
|
-
* `cacheNames.googleAnalytics` is used by `@serwist/google-analytics` to
|
|
59
|
-
* store `analytics.js`, and `cacheNames.runtime` is used for everything else.
|
|
60
|
-
*
|
|
61
|
-
* `cacheNames.prefix` can be used to retrieve just the current prefix value.
|
|
62
|
-
* `cacheNames.suffix` can be used to retrieve just the current suffix value.
|
|
63
|
-
*
|
|
64
|
-
* @returns An object with `precache`, `runtime`, `prefix`, and `googleAnalytics` properties.
|
|
65
|
-
*/ const cacheNames = {
|
|
66
|
-
get googleAnalytics () {
|
|
67
|
-
return cacheNames$1.getGoogleAnalyticsName();
|
|
68
|
-
},
|
|
69
|
-
get precache () {
|
|
70
|
-
return cacheNames$1.getPrecacheName();
|
|
71
|
-
},
|
|
72
|
-
get prefix () {
|
|
73
|
-
return cacheNames$1.getPrefix();
|
|
74
|
-
},
|
|
75
|
-
get runtime () {
|
|
76
|
-
return cacheNames$1.getRuntimeName();
|
|
77
|
-
},
|
|
78
|
-
get suffix () {
|
|
79
|
-
return cacheNames$1.getSuffix();
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
/*
|
|
84
|
-
Copyright 2019 Google LLC
|
|
85
|
-
|
|
86
|
-
Use of this source code is governed by an MIT-style
|
|
87
|
-
license that can be found in the LICENSE file or at
|
|
88
|
-
https://opensource.org/licenses/MIT.
|
|
89
|
-
*/ // Give TypeScript the correct global.
|
|
90
|
-
/**
|
|
91
|
-
* Claim any currently available clients once the service worker
|
|
92
|
-
* becomes active. This is normally used in conjunction with `skipWaiting()`.
|
|
93
|
-
*/ function clientsClaim() {
|
|
94
|
-
self.addEventListener("activate", ()=>self.clients.claim());
|
|
95
|
-
}
|
|
96
|
-
|
|
97
54
|
/*
|
|
98
55
|
Copyright 2019 Google LLC
|
|
99
56
|
|
|
@@ -334,51 +291,6 @@ const messageGenerator = process.env.NODE_ENV === "production" ? fallback : gene
|
|
|
334
291
|
}
|
|
335
292
|
}
|
|
336
293
|
|
|
337
|
-
/**
|
|
338
|
-
* Allows developers to copy a response and modify its `headers`, `status`,
|
|
339
|
-
* or `statusText` values (the values settable via a
|
|
340
|
-
* [`ResponseInit`](https://developer.mozilla.org/en-US/docs/Web/API/Response/Response#Syntax)
|
|
341
|
-
* object in the constructor).
|
|
342
|
-
* To modify these values, pass a function as the second argument. That
|
|
343
|
-
* function will be invoked with a single object with the response properties
|
|
344
|
-
* `{headers, status, statusText}`. The return value of this function will
|
|
345
|
-
* be used as the `ResponseInit` for the new `Response`. To change the values
|
|
346
|
-
* either modify the passed parameter(s) and return it, or return a totally
|
|
347
|
-
* new object.
|
|
348
|
-
*
|
|
349
|
-
* This method is intentionally limited to same-origin responses, regardless of
|
|
350
|
-
* whether CORS was used or not.
|
|
351
|
-
*
|
|
352
|
-
* @param response
|
|
353
|
-
* @param modifier
|
|
354
|
-
*/ async function copyResponse(response, modifier) {
|
|
355
|
-
let origin = null;
|
|
356
|
-
// If response.url isn't set, assume it's cross-origin and keep origin null.
|
|
357
|
-
if (response.url) {
|
|
358
|
-
const responseURL = new URL(response.url);
|
|
359
|
-
origin = responseURL.origin;
|
|
360
|
-
}
|
|
361
|
-
if (origin !== self.location.origin) {
|
|
362
|
-
throw new SerwistError("cross-origin-copy-response", {
|
|
363
|
-
origin
|
|
364
|
-
});
|
|
365
|
-
}
|
|
366
|
-
const clonedResponse = response.clone();
|
|
367
|
-
// Create a fresh `ResponseInit` object by cloning the headers.
|
|
368
|
-
const responseInit = {
|
|
369
|
-
headers: new Headers(clonedResponse.headers),
|
|
370
|
-
status: clonedResponse.status,
|
|
371
|
-
statusText: clonedResponse.statusText
|
|
372
|
-
};
|
|
373
|
-
// Apply any user modifications.
|
|
374
|
-
const modifiedResponseInit = modifier ? modifier(responseInit) : responseInit;
|
|
375
|
-
// Create the new response from the body stream and `ResponseInit`
|
|
376
|
-
// modifications. Note: not all browsers support the Response.body stream,
|
|
377
|
-
// so fall back to reading the entire body into memory as a blob.
|
|
378
|
-
const body = canConstructResponseFromBodyStream() ? clonedResponse.body : await clonedResponse.blob();
|
|
379
|
-
return new Response(body, modifiedResponseInit);
|
|
380
|
-
}
|
|
381
|
-
|
|
382
294
|
/*
|
|
383
295
|
* This method throws if the supplied value is not an array.
|
|
384
296
|
* The destructed values are required to produce a meaningful error for users.
|
|
@@ -513,65 +425,9 @@ const logger = process.env.NODE_ENV === "production" ? null : (()=>{
|
|
|
513
425
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
514
426
|
const quotaErrorCallbacks = new Set();
|
|
515
427
|
|
|
516
|
-
|
|
517
|
-
* Adds a function to the set of quotaErrorCallbacks that will be executed if
|
|
518
|
-
* there's a quota error.
|
|
519
|
-
*
|
|
520
|
-
* @param callback
|
|
521
|
-
*/ // Can't change Function type
|
|
522
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
523
|
-
function registerQuotaErrorCallback(callback) {
|
|
524
|
-
if (process.env.NODE_ENV !== "production") {
|
|
525
|
-
finalAssertExports.isType(callback, "function", {
|
|
526
|
-
moduleName: "@serwist/core",
|
|
527
|
-
funcName: "register",
|
|
528
|
-
paramName: "callback"
|
|
529
|
-
});
|
|
530
|
-
}
|
|
531
|
-
quotaErrorCallbacks.add(callback);
|
|
532
|
-
if (process.env.NODE_ENV !== "production") {
|
|
533
|
-
logger.log("Registered a callback to respond to quota errors.", callback);
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
/**
|
|
538
|
-
* Modifies the default cache names used by the Serwist packages.
|
|
539
|
-
* Cache names are generated as `<prefix>-<Cache Name>-<suffix>`.
|
|
540
|
-
*
|
|
541
|
-
* @param details
|
|
542
|
-
*/ function setCacheNameDetails(details) {
|
|
543
|
-
if (process.env.NODE_ENV !== "production") {
|
|
544
|
-
Object.keys(details).forEach((key)=>{
|
|
545
|
-
finalAssertExports.isType(details[key], "string", {
|
|
546
|
-
moduleName: "@serwist/core",
|
|
547
|
-
funcName: "setCacheNameDetails",
|
|
548
|
-
paramName: `details.${key}`
|
|
549
|
-
});
|
|
550
|
-
});
|
|
551
|
-
if (details["precache"]?.length === 0) {
|
|
552
|
-
throw new SerwistError("invalid-cache-name", {
|
|
553
|
-
cacheNameId: "precache",
|
|
554
|
-
value: details["precache"]
|
|
555
|
-
});
|
|
556
|
-
}
|
|
557
|
-
if (details["runtime"]?.length === 0) {
|
|
558
|
-
throw new SerwistError("invalid-cache-name", {
|
|
559
|
-
cacheNameId: "runtime",
|
|
560
|
-
value: details["runtime"]
|
|
561
|
-
});
|
|
562
|
-
}
|
|
563
|
-
if (details["googleAnalytics"]?.length === 0) {
|
|
564
|
-
throw new SerwistError("invalid-cache-name", {
|
|
565
|
-
cacheNameId: "googleAnalytics",
|
|
566
|
-
value: details["googleAnalytics"]
|
|
567
|
-
});
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
cacheNames$1.updateDetails(details);
|
|
571
|
-
}
|
|
572
|
-
|
|
428
|
+
exports.SerwistError = SerwistError;
|
|
573
429
|
exports.cacheNames = cacheNames;
|
|
574
|
-
exports.
|
|
575
|
-
exports.
|
|
576
|
-
exports.
|
|
577
|
-
exports.
|
|
430
|
+
exports.canConstructResponseFromBodyStream = canConstructResponseFromBodyStream;
|
|
431
|
+
exports.finalAssertExports = finalAssertExports;
|
|
432
|
+
exports.logger = logger;
|
|
433
|
+
exports.quotaErrorCallbacks = quotaErrorCallbacks;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PartialCacheNameDetails } from "./_private/cacheNames.js";
|
|
2
|
+
/**
|
|
3
|
+
* Modifies the default cache names used by the Serwist packages.
|
|
4
|
+
* Cache names are generated as `<prefix>-<Cache Name>-<suffix>`.
|
|
5
|
+
*
|
|
6
|
+
* @param details
|
|
7
|
+
*/
|
|
8
|
+
declare function setCacheNameDetails(details: PartialCacheNameDetails): void;
|
|
9
|
+
export { setCacheNameDetails };
|