@serwist/core 9.0.0-preview.0 → 9.0.0-preview.2
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/logger.d.ts +8 -2
- package/dist/_private/logger.d.ts.map +1 -1
- package/dist/chunks/quotaErrorCallbacks.js +12 -82
- package/dist/index.internal.js +12 -121
- package/dist/index.js +4 -59
- package/package.json +3 -3
- package/src/_private/logger.ts +17 -21
|
@@ -6,6 +6,12 @@ declare global {
|
|
|
6
6
|
__WB_DISABLE_DEV_LOGS: boolean;
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
-
declare const logger:
|
|
10
|
-
|
|
9
|
+
export declare const logger: {
|
|
10
|
+
error: (...args: any[]) => void;
|
|
11
|
+
debug: (...args: any[]) => void;
|
|
12
|
+
log: (...args: any[]) => void;
|
|
13
|
+
warn: (...args: any[]) => void;
|
|
14
|
+
groupCollapsed: (...args: any[]) => void;
|
|
15
|
+
groupEnd: (...args: any[]) => void;
|
|
16
|
+
};
|
|
11
17
|
//# 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;
|
|
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,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"}
|
|
@@ -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.`);
|
|
@@ -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
|
-
|
|
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,
|
|
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,
|
|
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
|
-
|
|
407
|
-
const method = key;
|
|
345
|
+
return loggerMethods.reduce((api, method)=>{
|
|
408
346
|
api[method] = (...args)=>{
|
|
409
347
|
print(method, args);
|
|
410
348
|
};
|
|
411
|
-
|
|
412
|
-
|
|
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 };
|
package/dist/index.internal.js
CHANGED
|
@@ -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
|
-
|
|
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,42 +93,25 @@ 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
|
+
function waitUntil(event, asyncFn) {
|
|
224
115
|
const returnPromise = asyncFn();
|
|
225
116
|
event.waitUntil(returnPromise);
|
|
226
117
|
return returnPromise;
|
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", {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serwist/core",
|
|
3
|
-
"version": "9.0.0-preview.
|
|
3
|
+
"version": "9.0.0-preview.2",
|
|
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.
|
|
43
|
-
"@serwist/constants": "9.0.0-preview.
|
|
42
|
+
"typescript": "5.4.0-dev.20240206",
|
|
43
|
+
"@serwist/constants": "9.0.0-preview.2"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"typescript": ">=5.0.0"
|
package/src/_private/logger.ts
CHANGED
|
@@ -16,11 +16,9 @@ declare global {
|
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const logger = (
|
|
19
|
+
export const logger =
|
|
22
20
|
process.env.NODE_ENV === "production"
|
|
23
|
-
? null
|
|
21
|
+
? null!
|
|
24
22
|
: (() => {
|
|
25
23
|
// Don't overwrite this value if it's already set.
|
|
26
24
|
// See https://github.com/GoogleChrome/workbox/pull/2284#issuecomment-560470923
|
|
@@ -30,7 +28,7 @@ const logger = (
|
|
|
30
28
|
|
|
31
29
|
let inGroup = false;
|
|
32
30
|
|
|
33
|
-
const methodToColorMap
|
|
31
|
+
const methodToColorMap = {
|
|
34
32
|
debug: "#7f8c8d", // Gray
|
|
35
33
|
log: "#2ecc71", // Green
|
|
36
34
|
warn: "#f39c12", // Yellow
|
|
@@ -39,6 +37,8 @@ const logger = (
|
|
|
39
37
|
groupEnd: null, // No colored prefix on groupEnd
|
|
40
38
|
};
|
|
41
39
|
|
|
40
|
+
type LoggerMethods = keyof typeof methodToColorMap;
|
|
41
|
+
|
|
42
42
|
const print = (method: LoggerMethods, args: any[]) => {
|
|
43
43
|
if (self.__WB_DISABLE_DEV_LOGS) {
|
|
44
44
|
return;
|
|
@@ -73,20 +73,16 @@ const logger = (
|
|
|
73
73
|
inGroup = false;
|
|
74
74
|
}
|
|
75
75
|
};
|
|
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
76
|
|
|
92
|
-
|
|
77
|
+
const loggerMethods = Object.keys(methodToColorMap) as LoggerMethods[];
|
|
78
|
+
|
|
79
|
+
return loggerMethods.reduce(
|
|
80
|
+
(api, method) => {
|
|
81
|
+
api[method] = (...args: any[]) => {
|
|
82
|
+
print(method, args);
|
|
83
|
+
};
|
|
84
|
+
return api;
|
|
85
|
+
},
|
|
86
|
+
{} as { [method in LoggerMethods]: (...args: any[]) => void },
|
|
87
|
+
);
|
|
88
|
+
})();
|