@serwist/core 8.4.4 → 9.0.0-preview.1

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.
Files changed (117) hide show
  1. package/dist/_private/Deferred.d.ts +1 -0
  2. package/dist/_private/Deferred.d.ts.map +1 -0
  3. package/dist/_private/SerwistError.d.ts +1 -0
  4. package/dist/_private/SerwistError.d.ts.map +1 -0
  5. package/dist/_private/assert.d.ts +1 -0
  6. package/dist/_private/assert.d.ts.map +1 -0
  7. package/dist/_private/cacheMatchIgnoreParams.d.ts +1 -0
  8. package/dist/_private/cacheMatchIgnoreParams.d.ts.map +1 -0
  9. package/dist/_private/cacheNames.d.ts +1 -0
  10. package/dist/_private/cacheNames.d.ts.map +1 -0
  11. package/dist/_private/canConstructReadableStream.d.ts +1 -0
  12. package/dist/_private/canConstructReadableStream.d.ts.map +1 -0
  13. package/dist/_private/canConstructResponseFromBodyStream.d.ts +1 -0
  14. package/dist/_private/canConstructResponseFromBodyStream.d.ts.map +1 -0
  15. package/dist/_private/dontWaitFor.d.ts +1 -0
  16. package/dist/_private/dontWaitFor.d.ts.map +1 -0
  17. package/dist/_private/executeQuotaErrorCallbacks.d.ts +1 -0
  18. package/dist/_private/executeQuotaErrorCallbacks.d.ts.map +1 -0
  19. package/dist/_private/getFriendlyURL.d.ts +1 -0
  20. package/dist/_private/getFriendlyURL.d.ts.map +1 -0
  21. package/dist/_private/logger.d.ts +1 -0
  22. package/dist/_private/logger.d.ts.map +1 -0
  23. package/dist/_private/resultingClientExists.d.ts +1 -0
  24. package/dist/_private/resultingClientExists.d.ts.map +1 -0
  25. package/dist/_private/timeout.d.ts +1 -0
  26. package/dist/_private/timeout.d.ts.map +1 -0
  27. package/dist/_private/waitUntil.d.ts +1 -0
  28. package/dist/_private/waitUntil.d.ts.map +1 -0
  29. package/dist/cacheNames.d.ts +1 -0
  30. package/dist/cacheNames.d.ts.map +1 -0
  31. package/dist/{quotaErrorCallbacks.js → chunks/quotaErrorCallbacks.js} +9 -77
  32. package/dist/clientsClaim.d.ts +1 -0
  33. package/dist/clientsClaim.d.ts.map +1 -0
  34. package/dist/copyResponse.d.ts +1 -0
  35. package/dist/copyResponse.d.ts.map +1 -0
  36. package/dist/index.d.ts +1 -0
  37. package/dist/index.d.ts.map +1 -0
  38. package/dist/index.internal.d.ts +1 -0
  39. package/dist/index.internal.d.ts.map +1 -0
  40. package/dist/index.internal.js +14 -123
  41. package/dist/index.js +5 -60
  42. package/dist/models/messages/messageGenerator.d.ts +1 -0
  43. package/dist/models/messages/messageGenerator.d.ts.map +1 -0
  44. package/dist/models/messages/messages.d.ts +1 -0
  45. package/dist/models/messages/messages.d.ts.map +1 -0
  46. package/dist/models/pluginEvents.d.ts +1 -0
  47. package/dist/models/pluginEvents.d.ts.map +1 -0
  48. package/dist/models/quotaErrorCallbacks.d.ts +1 -0
  49. package/dist/models/quotaErrorCallbacks.d.ts.map +1 -0
  50. package/dist/registerQuotaErrorCallback.d.ts +1 -0
  51. package/dist/registerQuotaErrorCallback.d.ts.map +1 -0
  52. package/dist/setCacheNameDetails.d.ts +1 -0
  53. package/dist/setCacheNameDetails.d.ts.map +1 -0
  54. package/dist/types.d.ts +1 -0
  55. package/dist/types.d.ts.map +1 -0
  56. package/dist/utils/pluginUtils.d.ts +1 -0
  57. package/dist/utils/pluginUtils.d.ts.map +1 -0
  58. package/dist/utils/welcome.d.ts +1 -0
  59. package/dist/utils/welcome.d.ts.map +1 -0
  60. package/package.json +18 -22
  61. package/src/_private/Deferred.ts +33 -0
  62. package/src/_private/SerwistError.ts +42 -0
  63. package/src/_private/assert.ts +89 -0
  64. package/src/_private/cacheMatchIgnoreParams.ts +54 -0
  65. package/src/_private/cacheNames.ts +87 -0
  66. package/src/_private/canConstructReadableStream.ts +34 -0
  67. package/src/_private/canConstructResponseFromBodyStream.ts +37 -0
  68. package/src/_private/dontWaitFor.ts +16 -0
  69. package/src/_private/executeQuotaErrorCallbacks.ts +35 -0
  70. package/src/_private/getFriendlyURL.ts +16 -0
  71. package/src/_private/logger.ts +92 -0
  72. package/src/_private/resultingClientExists.ts +58 -0
  73. package/src/_private/timeout.ts +19 -0
  74. package/src/_private/waitUntil.ts +23 -0
  75. package/src/cacheNames.ts +41 -0
  76. package/src/clientsClaim.ts +20 -0
  77. package/src/copyResponse.ts +62 -0
  78. package/{dist/index.internal.d.cts → src/index.internal.ts} +19 -1
  79. package/{dist/index.d.cts → src/index.ts} +9 -0
  80. package/src/models/messages/messageGenerator.ts +28 -0
  81. package/src/models/messages/messages.ts +231 -0
  82. package/src/models/pluginEvents.ts +17 -0
  83. package/src/models/quotaErrorCallbacks.ts +13 -0
  84. package/src/registerQuotaErrorCallback.ts +36 -0
  85. package/src/setCacheNameDetails.ts +55 -0
  86. package/src/types.ts +315 -0
  87. package/src/utils/pluginUtils.ts +15 -0
  88. package/src/utils/welcome.ts +25 -0
  89. package/dist/_private/Deferred.d.cts +0 -18
  90. package/dist/_private/SerwistError.d.cts +0 -23
  91. package/dist/_private/assert.d.cts +0 -10
  92. package/dist/_private/cacheMatchIgnoreParams.d.cts +0 -14
  93. package/dist/_private/cacheNames.d.cts +0 -39
  94. package/dist/_private/canConstructReadableStream.d.cts +0 -11
  95. package/dist/_private/canConstructResponseFromBodyStream.d.cts +0 -10
  96. package/dist/_private/dontWaitFor.d.cts +0 -6
  97. package/dist/_private/executeQuotaErrorCallbacks.d.cts +0 -8
  98. package/dist/_private/getFriendlyURL.d.cts +0 -2
  99. package/dist/_private/logger.d.cts +0 -10
  100. package/dist/_private/resultingClientExists.d.cts +0 -11
  101. package/dist/_private/timeout.d.cts +0 -9
  102. package/dist/_private/waitUntil.d.cts +0 -11
  103. package/dist/cacheNames.d.cts +0 -20
  104. package/dist/clientsClaim.d.cts +0 -6
  105. package/dist/copyResponse.d.cts +0 -20
  106. package/dist/index.cjs +0 -153
  107. package/dist/index.internal.cjs +0 -243
  108. package/dist/models/messages/messageGenerator.d.cts +0 -1
  109. package/dist/models/messages/messages.d.cts +0 -8
  110. package/dist/models/pluginEvents.d.cts +0 -9
  111. package/dist/models/quotaErrorCallbacks.d.cts +0 -2
  112. package/dist/quotaErrorCallbacks.cjs +0 -432
  113. package/dist/registerQuotaErrorCallback.d.cts +0 -8
  114. package/dist/setCacheNameDetails.d.cts +0 -9
  115. package/dist/types.d.cts +0 -272
  116. package/dist/utils/pluginUtils.d.cts +0 -4
  117. package/dist/utils/welcome.d.cts +0 -1
@@ -1,432 +0,0 @@
1
- 'use strict';
2
-
3
- /*
4
- Copyright 2018 Google LLC
5
-
6
- Use of this source code is governed by an MIT-style
7
- license that can be found in the LICENSE file or at
8
- https://opensource.org/licenses/MIT.
9
- */ const _cacheNameDetails = {
10
- googleAnalytics: "googleAnalytics",
11
- precache: "precache-v2",
12
- prefix: "serwist",
13
- runtime: "runtime",
14
- suffix: typeof registration !== "undefined" ? registration.scope : ""
15
- };
16
- const _createCacheName = (cacheName)=>{
17
- return [
18
- _cacheNameDetails.prefix,
19
- cacheName,
20
- _cacheNameDetails.suffix
21
- ].filter((value)=>value && value.length > 0).join("-");
22
- };
23
- const eachCacheNameDetail = (fn)=>{
24
- for (const key of Object.keys(_cacheNameDetails)){
25
- fn(key);
26
- }
27
- };
28
- const cacheNames = {
29
- updateDetails: (details)=>{
30
- eachCacheNameDetail((key)=>{
31
- const detail = details[key];
32
- if (typeof detail === "string") {
33
- _cacheNameDetails[key] = detail;
34
- }
35
- });
36
- },
37
- getGoogleAnalyticsName: (userCacheName)=>{
38
- return userCacheName || _createCacheName(_cacheNameDetails.googleAnalytics);
39
- },
40
- getPrecacheName: (userCacheName)=>{
41
- return userCacheName || _createCacheName(_cacheNameDetails.precache);
42
- },
43
- getPrefix: ()=>{
44
- return _cacheNameDetails.prefix;
45
- },
46
- getRuntimeName: (userCacheName)=>{
47
- return userCacheName || _createCacheName(_cacheNameDetails.runtime);
48
- },
49
- getSuffix: ()=>{
50
- return _cacheNameDetails.suffix;
51
- }
52
- };
53
-
54
- /*
55
- Copyright 2018 Google LLC
56
-
57
- Use of this source code is governed by an MIT-style
58
- license that can be found in the LICENSE file or at
59
- https://opensource.org/licenses/MIT.
60
- */ const messages = {
61
- "invalid-value": ({ paramName, validValueDescription, value })=>{
62
- if (!paramName || !validValueDescription) {
63
- throw new Error(`Unexpected input to 'invalid-value' error.`);
64
- }
65
- return `The '${paramName}' parameter was given a value with an ` + `unexpected value. ${validValueDescription} Received a value of ` + `${JSON.stringify(value)}.`;
66
- },
67
- "not-an-array": ({ moduleName, className, funcName, paramName })=>{
68
- if (!moduleName || !className || !funcName || !paramName) {
69
- throw new Error(`Unexpected input to 'not-an-array' error.`);
70
- }
71
- return `The parameter '${paramName}' passed into ` + `'${moduleName}.${className}.${funcName}()' must be an array.`;
72
- },
73
- "incorrect-type": ({ expectedType, paramName, moduleName, className, funcName })=>{
74
- if (!expectedType || !paramName || !moduleName || !funcName) {
75
- throw new Error(`Unexpected input to 'incorrect-type' error.`);
76
- }
77
- const classNameStr = className ? `${className}.` : "";
78
- return `The parameter '${paramName}' passed into ` + `'${moduleName}.${classNameStr}` + `${funcName}()' must be of type ${expectedType}.`;
79
- },
80
- "incorrect-class": ({ expectedClassName, paramName, moduleName, className, funcName, isReturnValueProblem })=>{
81
- if (!expectedClassName || !moduleName || !funcName) {
82
- throw new Error(`Unexpected input to 'incorrect-class' error.`);
83
- }
84
- const classNameStr = className ? `${className}.` : "";
85
- if (isReturnValueProblem) {
86
- return `The return value from '${moduleName}.${classNameStr}${funcName}()' must be an instance of class ${expectedClassName}.`;
87
- }
88
- return `The parameter '${paramName}' passed into ` + `'${moduleName}.${classNameStr}${funcName}()' ` + `must be an instance of class ${expectedClassName}.`;
89
- },
90
- "missing-a-method": ({ expectedMethod, paramName, moduleName, className, funcName })=>{
91
- if (!expectedMethod || !paramName || !moduleName || !className || !funcName) {
92
- throw new Error(`Unexpected input to 'missing-a-method' error.`);
93
- }
94
- return `${moduleName}.${className}.${funcName}() expected the ` + `'${paramName}' parameter to expose a '${expectedMethod}' method.`;
95
- },
96
- "add-to-cache-list-unexpected-type": ({ entry })=>{
97
- return `An unexpected entry was passed to '@serwist/precaching.PrecacheController.addToCacheList()' The entry '${JSON.stringify(entry)}' isn't supported. You must supply an array of strings with one or more characters, objects with a url property or Request objects.`;
98
- },
99
- "add-to-cache-list-conflicting-entries": ({ firstEntry, secondEntry })=>{
100
- if (!firstEntry || !secondEntry) {
101
- throw new Error("Unexpected input to " + `'add-to-cache-list-duplicate-entries' error.`);
102
- }
103
- return `Two of the entries passed to '@serwist/precaching.PrecacheController.addToCacheList()' had the URL ${firstEntry} but different revision details. Serwist is unable to cache and version the asset correctly. Please remove one of the entries.`;
104
- },
105
- "plugin-error-request-will-fetch": ({ thrownErrorMessage })=>{
106
- if (!thrownErrorMessage) {
107
- throw new Error("Unexpected input to " + `'plugin-error-request-will-fetch', error.`);
108
- }
109
- return `An error was thrown by a plugins 'requestWillFetch()' method. The thrown error message was: '${thrownErrorMessage}'.`;
110
- },
111
- "invalid-cache-name": ({ cacheNameId, value })=>{
112
- if (!cacheNameId) {
113
- throw new Error(`Expected a 'cacheNameId' for error 'invalid-cache-name'`);
114
- }
115
- return `You must provide a name containing at least one character for setCacheDetails({${cacheNameId}: '...'}). Received a value of '${JSON.stringify(value)}'`;
116
- },
117
- "unregister-route-but-not-found-with-method": ({ method })=>{
118
- if (!method) {
119
- throw new Error("Unexpected input to " + `'unregister-route-but-not-found-with-method' error.`);
120
- }
121
- return `The route you're trying to unregister was not previously registered for the method type '${method}'.`;
122
- },
123
- "unregister-route-route-not-registered": ()=>{
124
- return `The route you're trying to unregister was not previously ` + "registered.";
125
- },
126
- "queue-replay-failed": ({ name })=>{
127
- return `Replaying the background sync queue '${name}' failed.`;
128
- },
129
- "duplicate-queue-name": ({ name })=>{
130
- return `The Queue name '${name}' is already being used. All instances of backgroundSync.Queue must be given unique names.`;
131
- },
132
- "expired-test-without-max-age": ({ methodName, paramName })=>{
133
- return `The '${methodName}()' method can only be used when the ` + `'${paramName}' is used in the constructor.`;
134
- },
135
- "unsupported-route-type": ({ moduleName, className, funcName, paramName })=>{
136
- return `The supplied '${paramName}' parameter was an unsupported type. Please check the docs for ${moduleName}.${className}.${funcName} for valid input types.`;
137
- },
138
- "not-array-of-class": ({ value, expectedClass, moduleName, className, funcName, paramName })=>{
139
- return `The supplied '${paramName}' parameter must be an array of '${expectedClass}' objects. Received '${JSON.stringify(value)},'. Please check the call to ${moduleName}.${className}.${funcName}() to fix the issue.`;
140
- },
141
- "max-entries-or-age-required": ({ moduleName, className, funcName })=>{
142
- return `You must define either config.maxEntries or config.maxAgeSecondsin ${moduleName}.${className}.${funcName}`;
143
- },
144
- "statuses-or-headers-required": ({ moduleName, className, funcName })=>{
145
- return `You must define either config.statuses or config.headersin ${moduleName}.${className}.${funcName}`;
146
- },
147
- "invalid-string": ({ moduleName, funcName, paramName })=>{
148
- if (!paramName || !moduleName || !funcName) {
149
- throw new Error(`Unexpected input to 'invalid-string' error.`);
150
- }
151
- return `When using strings, the '${paramName}' parameter must start with 'http' (for cross-origin matches) or '/' (for same-origin matches). Please see the docs for ${moduleName}.${funcName}() for more info.`;
152
- },
153
- "channel-name-required": ()=>{
154
- return "You must provide a channelName to construct a " + "BroadcastCacheUpdate instance.";
155
- },
156
- "invalid-responses-are-same-args": ()=>{
157
- return "The arguments passed into responsesAreSame() appear to be " + "invalid. Please ensure valid Responses are used.";
158
- },
159
- "expire-custom-caches-only": ()=>{
160
- return `You must provide a 'cacheName' property when using the ` + "expiration plugin with a runtime caching strategy.";
161
- },
162
- "unit-must-be-bytes": ({ normalizedRangeHeader })=>{
163
- if (!normalizedRangeHeader) {
164
- throw new Error(`Unexpected input to 'unit-must-be-bytes' error.`);
165
- }
166
- return `The 'unit' portion of the Range header must be set to 'bytes'. The Range header provided was "${normalizedRangeHeader}"`;
167
- },
168
- "single-range-only": ({ normalizedRangeHeader })=>{
169
- if (!normalizedRangeHeader) {
170
- throw new Error(`Unexpected input to 'single-range-only' error.`);
171
- }
172
- return `Multiple ranges are not supported. Please use a single start value, and optional end value. The Range header provided was "${normalizedRangeHeader}"`;
173
- },
174
- "invalid-range-values": ({ normalizedRangeHeader })=>{
175
- if (!normalizedRangeHeader) {
176
- throw new Error(`Unexpected input to 'invalid-range-values' error.`);
177
- }
178
- return `The Range header is missing both start and end values. At least one of those values is needed. The Range header provided was "${normalizedRangeHeader}"`;
179
- },
180
- "no-range-header": ()=>{
181
- return "No Range header was found in the Request provided.";
182
- },
183
- "range-not-satisfiable": ({ size, start, end })=>{
184
- return `The start (${start}) and end (${end}) values in the Range are ` + `not satisfiable by the cached response, which is ${size} bytes.`;
185
- },
186
- "attempt-to-cache-non-get-request": ({ url, method })=>{
187
- return `Unable to cache '${url}' because it is a '${method}' request and only 'GET' requests can be cached.`;
188
- },
189
- "cache-put-with-no-response": ({ url })=>{
190
- return `There was an attempt to cache '${url}' but the response was not defined.`;
191
- },
192
- "no-response": ({ url, error })=>{
193
- let message = `The strategy could not generate a response for '${url}'.`;
194
- if (error) {
195
- message += ` The underlying error is ${error}.`;
196
- }
197
- return message;
198
- },
199
- "bad-precaching-response": ({ url, status })=>{
200
- return `The precaching request for '${url}' failed${status ? ` with an HTTP status of ${status}.` : "."}`;
201
- },
202
- "non-precached-url": ({ url })=>{
203
- return `createHandlerBoundToURL('${url}') was called, but that URL is not precached. Please pass in a URL that is precached instead.`;
204
- },
205
- "add-to-cache-list-conflicting-integrities": ({ url })=>{
206
- return `Two of the entries passed to '@serwist/precaching.PrecacheController.addToCacheList()' had the URL ${url} with different integrity values. Please remove one of them.`;
207
- },
208
- "missing-precache-entry": ({ cacheName, url })=>{
209
- return `Unable to find a precached response in ${cacheName} for ${url}.`;
210
- },
211
- "cross-origin-copy-response": ({ origin })=>{
212
- return `@serwist/core.copyResponse() can only be used with same-origin responses. It was passed a response with origin ${origin}.`;
213
- },
214
- "opaque-streams-source": ({ type })=>{
215
- const message = `One of the @serwist/streams sources resulted in an '${type}' response.`;
216
- if (type === "opaqueredirect") {
217
- return `${message} Please do not use a navigation request that results in a redirect as a source.`;
218
- }
219
- return `${message} Please ensure your sources are CORS-enabled.`;
220
- }
221
- };
222
-
223
- const fallback = (code, ...args)=>{
224
- let msg = code;
225
- if (args.length > 0) {
226
- msg += ` :: ${JSON.stringify(args)}`;
227
- }
228
- return msg;
229
- };
230
- const generatorFunction = (code, details = {})=>{
231
- const message = messages[code];
232
- if (!message) {
233
- throw new Error(`Unable to find message for code '${code}'.`);
234
- }
235
- return message(details);
236
- };
237
- const messageGenerator = process.env.NODE_ENV === "production" ? fallback : generatorFunction;
238
-
239
- /**
240
- * Serwist errors should be thrown with this class.
241
- * This allows use to ensure the type easily in tests,
242
- * helps developers identify errors from Serwist
243
- * easily and allows use to optimise error
244
- * messages correctly.
245
- *
246
- * @private
247
- */ class SerwistError extends Error {
248
- details;
249
- /**
250
- *
251
- * @param errorCode The error code that
252
- * identifies this particular error.
253
- * @param details Any relevant arguments
254
- * that will help developers identify issues should
255
- * be added as a key on the context object.
256
- */ constructor(errorCode, details){
257
- const message = messageGenerator(errorCode, details);
258
- super(message);
259
- this.name = errorCode;
260
- this.details = details;
261
- }
262
- }
263
-
264
- /*
265
- Copyright 2019 Google LLC
266
-
267
- Use of this source code is governed by an MIT-style
268
- license that can be found in the LICENSE file or at
269
- https://opensource.org/licenses/MIT.
270
- */ let supportStatus;
271
- /**
272
- * A utility function that determines whether the current browser supports
273
- * constructing a new `Response` from a `response.body` stream.
274
- *
275
- * @returns `true`, if the current browser can successfully construct
276
- * a `Response` from a `response.body` stream, `false` otherwise.
277
- * @private
278
- */ function canConstructResponseFromBodyStream() {
279
- if (supportStatus === undefined) {
280
- const testResponse = new Response("");
281
- if ("body" in testResponse) {
282
- try {
283
- new Response(testResponse.body);
284
- supportStatus = true;
285
- } catch (error) {
286
- supportStatus = false;
287
- }
288
- }
289
- supportStatus = false;
290
- }
291
- return supportStatus;
292
- }
293
-
294
- /*
295
- * This method throws if the supplied value is not an array.
296
- * The destructed values are required to produce a meaningful error for users.
297
- * The destructed and restructured object is so it's clear what is
298
- * needed.
299
- */ const isArray = (value, details)=>{
300
- if (!Array.isArray(value)) {
301
- throw new SerwistError("not-an-array", details);
302
- }
303
- };
304
- const hasMethod = (object, expectedMethod, details)=>{
305
- const type = typeof object[expectedMethod];
306
- if (type !== "function") {
307
- details.expectedMethod = expectedMethod;
308
- throw new SerwistError("missing-a-method", details);
309
- }
310
- };
311
- const isType = (object, expectedType, details)=>{
312
- // biome-ignore lint/suspicious/useValidTypeof: Know to not make a mistake...
313
- if (typeof object !== expectedType) {
314
- details.expectedType = expectedType;
315
- throw new SerwistError("incorrect-type", details);
316
- }
317
- };
318
- const isInstance = (object, // biome-ignore lint/complexity/noBannedTypes: Need the general type to do the check later.
319
- expectedClass, details)=>{
320
- if (!(object instanceof expectedClass)) {
321
- details.expectedClassName = expectedClass.name;
322
- throw new SerwistError("incorrect-class", details);
323
- }
324
- };
325
- const isOneOf = (value, validValues, details)=>{
326
- if (!validValues.includes(value)) {
327
- details.validValueDescription = `Valid values are ${JSON.stringify(validValues)}.`;
328
- throw new SerwistError("invalid-value", details);
329
- }
330
- };
331
- const isArrayOfClass = (value, // biome-ignore lint/complexity/noBannedTypes: Need general type to do check later.
332
- expectedClass, details)=>{
333
- const error = new SerwistError("not-array-of-class", details);
334
- if (!Array.isArray(value)) {
335
- throw error;
336
- }
337
- for (const item of value){
338
- if (!(item instanceof expectedClass)) {
339
- throw error;
340
- }
341
- }
342
- };
343
- const finalAssertExports = process.env.NODE_ENV === "production" ? null : {
344
- hasMethod,
345
- isArray,
346
- isInstance,
347
- isOneOf,
348
- isType,
349
- isArrayOfClass
350
- };
351
-
352
- /*
353
- Copyright 2019 Google LLC
354
- Use of this source code is governed by an MIT-style
355
- license that can be found in the LICENSE file or at
356
- https://opensource.org/licenses/MIT.
357
- */ // logger is used inside of both service workers and the window global scope.
358
- const logger = process.env.NODE_ENV === "production" ? null : (()=>{
359
- // Don't overwrite this value if it's already set.
360
- // See https://github.com/GoogleChrome/workbox/pull/2284#issuecomment-560470923
361
- if (!("__WB_DISABLE_DEV_LOGS" in globalThis)) {
362
- self.__WB_DISABLE_DEV_LOGS = false;
363
- }
364
- let inGroup = false;
365
- const methodToColorMap = {
366
- debug: "#7f8c8d",
367
- log: "#2ecc71",
368
- warn: "#f39c12",
369
- error: "#c0392b",
370
- groupCollapsed: "#3498db",
371
- groupEnd: null
372
- };
373
- const print = (method, args)=>{
374
- if (self.__WB_DISABLE_DEV_LOGS) {
375
- return;
376
- }
377
- if (method === "groupCollapsed") {
378
- // Safari doesn't print all console.groupCollapsed() arguments:
379
- // https://bugs.webkit.org/show_bug.cgi?id=182754
380
- if (typeof navigator !== "undefined" && /^((?!chrome|android).)*safari/i.test(navigator.userAgent)) {
381
- console[method](...args);
382
- return;
383
- }
384
- }
385
- const styles = [
386
- `background: ${methodToColorMap[method]}`,
387
- "border-radius: 0.5em",
388
- "color: white",
389
- "font-weight: bold",
390
- "padding: 2px 0.5em"
391
- ];
392
- // When in a group, the serwist prefix is not displayed.
393
- const logPrefix = inGroup ? [] : [
394
- "%cserwist",
395
- styles.join(";")
396
- ];
397
- console[method](...logPrefix, ...args);
398
- if (method === "groupCollapsed") {
399
- inGroup = true;
400
- }
401
- if (method === "groupEnd") {
402
- inGroup = false;
403
- }
404
- };
405
- // biome-ignore lint/complexity/noBannedTypes: Unknown reason
406
- const api = {};
407
- const loggerMethods = Object.keys(methodToColorMap);
408
- for (const key of loggerMethods){
409
- const method = key;
410
- api[method] = (...args)=>{
411
- print(method, args);
412
- };
413
- }
414
- return api;
415
- })();
416
-
417
- /*
418
- Copyright 2018 Google LLC
419
-
420
- Use of this source code is governed by an MIT-style
421
- license that can be found in the LICENSE file or at
422
- https://opensource.org/licenses/MIT.
423
- */ // Callbacks to be executed whenever there's a quota error.
424
- // biome-ignore lint/complexity/noBannedTypes: Can't change Function type right now.
425
- const quotaErrorCallbacks = new Set();
426
-
427
- exports.SerwistError = SerwistError;
428
- exports.cacheNames = cacheNames;
429
- exports.canConstructResponseFromBodyStream = canConstructResponseFromBodyStream;
430
- exports.finalAssertExports = finalAssertExports;
431
- exports.logger = logger;
432
- exports.quotaErrorCallbacks = quotaErrorCallbacks;
@@ -1,8 +0,0 @@
1
- /**
2
- * Adds a function to the set of quotaErrorCallbacks that will be executed if
3
- * there's a quota error.
4
- *
5
- * @param callback
6
- */
7
- declare function registerQuotaErrorCallback(callback: Function): void;
8
- export { registerQuotaErrorCallback };
@@ -1,9 +0,0 @@
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 };