jekyll-pwa-plugin 1.0.2 → 2.0.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 (50) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jekyll-pwa-plugin.rb +18 -36
  3. data/lib/vendor/workbox-v3.3.1/workbox-background-sync.dev.js +593 -0
  4. data/lib/vendor/workbox-v3.3.1/workbox-background-sync.dev.js.map +1 -0
  5. data/lib/vendor/workbox-v3.3.1/workbox-background-sync.prod.js +3 -0
  6. data/lib/vendor/workbox-v3.3.1/workbox-background-sync.prod.js.map +1 -0
  7. data/lib/vendor/workbox-v3.3.1/workbox-broadcast-cache-update.dev.js +395 -0
  8. data/lib/vendor/workbox-v3.3.1/workbox-broadcast-cache-update.dev.js.map +1 -0
  9. data/lib/vendor/workbox-v3.3.1/workbox-broadcast-cache-update.prod.js +3 -0
  10. data/lib/vendor/workbox-v3.3.1/workbox-broadcast-cache-update.prod.js.map +1 -0
  11. data/lib/vendor/workbox-v3.3.1/workbox-cache-expiration.dev.js +740 -0
  12. data/lib/vendor/workbox-v3.3.1/workbox-cache-expiration.dev.js.map +1 -0
  13. data/lib/vendor/workbox-v3.3.1/workbox-cache-expiration.prod.js +3 -0
  14. data/lib/vendor/workbox-v3.3.1/workbox-cache-expiration.prod.js.map +1 -0
  15. data/lib/vendor/workbox-v3.3.1/workbox-cacheable-response.dev.js +236 -0
  16. data/lib/vendor/workbox-v3.3.1/workbox-cacheable-response.dev.js.map +1 -0
  17. data/lib/vendor/workbox-v3.3.1/workbox-cacheable-response.prod.js +3 -0
  18. data/lib/vendor/workbox-v3.3.1/workbox-cacheable-response.prod.js.map +1 -0
  19. data/lib/vendor/workbox-v3.3.1/workbox-core.dev.js +1690 -0
  20. data/lib/vendor/workbox-v3.3.1/workbox-core.dev.js.map +1 -0
  21. data/lib/vendor/workbox-v3.3.1/workbox-core.prod.js +3 -0
  22. data/lib/vendor/workbox-v3.3.1/workbox-core.prod.js.map +1 -0
  23. data/lib/vendor/workbox-v3.3.1/workbox-google-analytics.dev.js +255 -0
  24. data/lib/vendor/workbox-v3.3.1/workbox-google-analytics.dev.js.map +1 -0
  25. data/lib/vendor/workbox-v3.3.1/workbox-google-analytics.prod.js +3 -0
  26. data/lib/vendor/workbox-v3.3.1/workbox-google-analytics.prod.js.map +1 -0
  27. data/lib/vendor/workbox-v3.3.1/workbox-precaching.dev.js +1149 -0
  28. data/lib/vendor/workbox-v3.3.1/workbox-precaching.dev.js.map +1 -0
  29. data/lib/vendor/workbox-v3.3.1/workbox-precaching.prod.js +3 -0
  30. data/lib/vendor/workbox-v3.3.1/workbox-precaching.prod.js.map +1 -0
  31. data/lib/vendor/workbox-v3.3.1/workbox-range-requests.dev.js +299 -0
  32. data/lib/vendor/workbox-v3.3.1/workbox-range-requests.dev.js.map +1 -0
  33. data/lib/vendor/workbox-v3.3.1/workbox-range-requests.prod.js +3 -0
  34. data/lib/vendor/workbox-v3.3.1/workbox-range-requests.prod.js.map +1 -0
  35. data/lib/vendor/workbox-v3.3.1/workbox-routing.dev.js +863 -0
  36. data/lib/vendor/workbox-v3.3.1/workbox-routing.dev.js.map +1 -0
  37. data/lib/vendor/workbox-v3.3.1/workbox-routing.prod.js +3 -0
  38. data/lib/vendor/workbox-v3.3.1/workbox-routing.prod.js.map +1 -0
  39. data/lib/vendor/workbox-v3.3.1/workbox-strategies.dev.js +1091 -0
  40. data/lib/vendor/workbox-v3.3.1/workbox-strategies.dev.js.map +1 -0
  41. data/lib/vendor/workbox-v3.3.1/workbox-strategies.prod.js +3 -0
  42. data/lib/vendor/workbox-v3.3.1/workbox-strategies.prod.js.map +1 -0
  43. data/lib/vendor/workbox-v3.3.1/workbox-streams.dev.js +390 -0
  44. data/lib/vendor/workbox-v3.3.1/workbox-streams.dev.js.map +1 -0
  45. data/lib/vendor/workbox-v3.3.1/workbox-streams.prod.js +3 -0
  46. data/lib/vendor/workbox-v3.3.1/workbox-streams.prod.js.map +1 -0
  47. data/lib/vendor/workbox-v3.3.1/workbox-sw.js +3 -0
  48. data/lib/vendor/workbox-v3.3.1/workbox-sw.js.map +1 -0
  49. metadata +48 -3
  50. data/lib/vendor/workbox-sw.prod.v2.1.1.js +0 -186
@@ -0,0 +1,1690 @@
1
+ /* eslint-disable */
2
+ // This is extracted from the Babel runtime (original source: https://github.com/babel/babel/blob/9e0f5235b1ca5167c368a576ad7c5af62d20b0e3/packages/babel-helpers/src/helpers.js#L240).
3
+ // As part of the Rollup bundling process, it's injected once into workbox-core
4
+ // and reused throughout all of the other modules, avoiding code duplication.
5
+ // See https://github.com/GoogleChrome/workbox/pull/1048#issuecomment-344698046
6
+ // for further background.
7
+ self.babelHelpers = {
8
+ asyncToGenerator: function(fn) {
9
+ return function() {
10
+ var gen = fn.apply(this, arguments);
11
+ return new Promise(function(resolve, reject) {
12
+ function step(key, arg) {
13
+ try {
14
+ var info = gen[key](arg);
15
+ var value = info.value;
16
+ } catch (error) {
17
+ reject(error);
18
+ return;
19
+ }
20
+
21
+ if (info.done) {
22
+ resolve(value);
23
+ } else {
24
+ return Promise.resolve(value).then(function(value) {
25
+ step('next', value);
26
+ }, function(err) {
27
+ step('throw', err);
28
+ });
29
+ }
30
+ }
31
+
32
+ return step('next');
33
+ });
34
+ };
35
+ },
36
+ };
37
+
38
+ this.workbox = this.workbox || {};
39
+ this.workbox.core = (function () {
40
+ 'use strict';
41
+
42
+ try {
43
+ self.workbox.v['workbox:core:3.3.1'] = 1;
44
+ } catch (e) {} // eslint-disable-line
45
+
46
+ /*
47
+ Copyright 2017 Google Inc.
48
+
49
+ Licensed under the Apache License, Version 2.0 (the "License");
50
+ you may not use this file except in compliance with the License.
51
+ You may obtain a copy of the License at
52
+
53
+ https://www.apache.org/licenses/LICENSE-2.0
54
+
55
+ Unless required by applicable law or agreed to in writing, software
56
+ distributed under the License is distributed on an "AS IS" BASIS,
57
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
58
+ See the License for the specific language governing permissions and
59
+ limitations under the License.
60
+ */
61
+
62
+ /**
63
+ * The available log levels in Workbox: debug, log, warn, error and silent.
64
+ *
65
+ * @property {int} debug Prints all logs from Workbox. Useful for debugging.
66
+ * @property {int} log Prints console log, warn, error and groups. Default for
67
+ * debug builds.
68
+ * @property {int} warn Prints console warn, error and groups. Default for
69
+ * non-debug builds.
70
+ * @property {int} error Print console error and groups.
71
+ * @property {int} silent Force no logging from Workbox.
72
+ *
73
+ * @alias workbox.core.LOG_LEVELS
74
+ */
75
+
76
+ var LOG_LEVELS = {
77
+ debug: 0,
78
+ log: 1,
79
+ warn: 2,
80
+ error: 3,
81
+ silent: 4
82
+ };
83
+
84
+ /*
85
+ Copyright 2017 Google Inc.
86
+
87
+ Licensed under the Apache License, Version 2.0 (the "License");
88
+ you may not use this file except in compliance with the License.
89
+ You may obtain a copy of the License at
90
+
91
+ https://www.apache.org/licenses/LICENSE-2.0
92
+
93
+ Unless required by applicable law or agreed to in writing, software
94
+ distributed under the License is distributed on an "AS IS" BASIS,
95
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
96
+ See the License for the specific language governing permissions and
97
+ limitations under the License.
98
+ */
99
+
100
+ var messages = {
101
+ 'invalid-value': ({ paramName, validValueDescription, value }) => {
102
+ if (!paramName || !validValueDescription) {
103
+ throw new Error(`Unexpected input to 'invalid-value' error.`);
104
+ }
105
+ return `The '${paramName}' parameter was given a value with an ` + `unexpected value. ${validValueDescription} Received a value of ` + `${JSON.stringify(value)}.`;
106
+ },
107
+
108
+ 'not-in-sw': ({ moduleName }) => {
109
+ if (!moduleName) {
110
+ throw new Error(`Unexpected input to 'not-in-sw' error.`);
111
+ }
112
+ return `The '${moduleName}' must be used in a service worker.`;
113
+ },
114
+
115
+ 'not-an-array': ({ moduleName, className, funcName, paramName }) => {
116
+ if (!moduleName || !className || !funcName || !paramName) {
117
+ throw new Error(`Unexpected input to 'not-an-array' error.`);
118
+ }
119
+ return `The parameter '${paramName}' passed into ` + `'${moduleName}.${className}.${funcName}()' must be an array.`;
120
+ },
121
+
122
+ 'incorrect-type': ({ expectedType, paramName, moduleName, className,
123
+ funcName }) => {
124
+ if (!expectedType || !paramName || !moduleName || !funcName) {
125
+ throw new Error(`Unexpected input to 'incorrect-type' error.`);
126
+ }
127
+ return `The parameter '${paramName}' passed into ` + `'${moduleName}.${className ? className + '.' : ''}` + `${funcName}()' must be of type ${expectedType}.`;
128
+ },
129
+
130
+ 'incorrect-class': ({ expectedClass, paramName, moduleName, className,
131
+ funcName, isReturnValueProblem }) => {
132
+ if (!expectedClass || !moduleName || !funcName) {
133
+ throw new Error(`Unexpected input to 'incorrect-class' error.`);
134
+ }
135
+
136
+ if (isReturnValueProblem) {
137
+ return `The return value from ` + `'${moduleName}.${className ? className + '.' : ''}${funcName}()' ` + `must be an instance of class ${expectedClass.name}.`;
138
+ }
139
+
140
+ return `The parameter '${paramName}' passed into ` + `'${moduleName}.${className ? className + '.' : ''}${funcName}()' ` + `must be an instance of class ${expectedClass.name}.`;
141
+ },
142
+
143
+ 'missing-a-method': ({ expectedMethod, paramName, moduleName, className,
144
+ funcName }) => {
145
+ if (!expectedMethod || !paramName || !moduleName || !className || !funcName) {
146
+ throw new Error(`Unexpected input to 'missing-a-method' error.`);
147
+ }
148
+ return `${moduleName}.${className}.${funcName}() expected the ` + `'${paramName}' parameter to expose a '${expectedMethod}' method.`;
149
+ },
150
+
151
+ 'add-to-cache-list-unexpected-type': ({ entry }) => {
152
+ return `An unexpected entry was passed to ` + `'workbox-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.`;
153
+ },
154
+
155
+ 'add-to-cache-list-conflicting-entries': ({ firstEntry, secondEntry }) => {
156
+ if (!firstEntry || !secondEntry) {
157
+ throw new Error(`Unexpected input to ` + `'add-to-cache-list-duplicate-entries' error.`);
158
+ }
159
+
160
+ return `Two of the entries passed to ` + `'workbox-precaching.PrecacheController.addToCacheList()' had matching ` + `URLs but different revision details. This means workbox-precaching ` + `is unable to determine cache the asset correctly. Please remove one ` + `of the entries.`;
161
+ },
162
+
163
+ 'plugin-error-request-will-fetch': ({ thrownError }) => {
164
+ if (!thrownError) {
165
+ throw new Error(`Unexpected input to ` + `'plugin-error-request-will-fetch', error.`);
166
+ }
167
+
168
+ return `An error was thrown by a plugins 'requestWillFetch()' method. ` + `The thrown error message was: '${thrownError.message}'.`;
169
+ },
170
+
171
+ 'invalid-cache-name': ({ cacheNameId, value }) => {
172
+ if (!cacheNameId) {
173
+ throw new Error(`Expected a 'cacheNameId' for error 'invalid-cache-name'`);
174
+ }
175
+
176
+ return `You must provide a name containing at least one character for ` + `setCacheDeatils({${cacheNameId}: '...'}). Received a value of ` + `'${JSON.stringify(value)}'`;
177
+ },
178
+
179
+ 'unregister-route-but-not-found-with-method': ({ method }) => {
180
+ if (!method) {
181
+ throw new Error(`Unexpected input to ` + `'unregister-route-but-not-found-with-method' error.`);
182
+ }
183
+
184
+ return `The route you're trying to unregister was not previously ` + `registered for the method type '${method}'.`;
185
+ },
186
+
187
+ 'unregister-route-route-not-registered': () => {
188
+ return `The route you're trying to unregister was not previously ` + `registered.`;
189
+ },
190
+
191
+ 'queue-replay-failed': ({ name, count }) => {
192
+ return `${count} requests failed, while trying to replay Queue: ${name}.`;
193
+ },
194
+
195
+ 'duplicate-queue-name': ({ name }) => {
196
+ return `The Queue name '${name}' is already being used. ` + `All instances of backgroundSync.Queue must be given unique names.`;
197
+ },
198
+
199
+ 'expired-test-without-max-age': ({ methodName, paramName }) => {
200
+ return `The '${methodName}()' method can only be used when the ` + `'${paramName}' is used in the constructor.`;
201
+ },
202
+
203
+ 'unsupported-route-type': ({ moduleName, className, funcName, paramName }) => {
204
+ return `The supplied '${paramName}' parameter was an unsupported type. ` + `Please check the docs for ${moduleName}.${className}.${funcName} for ` + `valid input types.`;
205
+ },
206
+
207
+ 'not-array-of-class': ({ value, expectedClass,
208
+ moduleName, className, funcName, paramName }) => {
209
+ 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.`;
210
+ },
211
+
212
+ 'max-entries-or-age-required': ({ moduleName, className, funcName }) => {
213
+ return `You must define either config.maxEntries or config.maxAgeSeconds` + `in ${moduleName}.${className}.${funcName}`;
214
+ },
215
+
216
+ 'statuses-or-headers-required': ({ moduleName, className, funcName }) => {
217
+ return `You must define either config.statuses or config.headers` + `in ${moduleName}.${className}.${funcName}`;
218
+ },
219
+
220
+ 'invalid-string': ({ moduleName, className, funcName, paramName }) => {
221
+ if (!paramName || !moduleName || !className || !funcName) {
222
+ throw new Error(`Unexpected input to 'invalid-string' error.`);
223
+ }
224
+ 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}.${className}.${funcName}() for ` + `more info.`;
225
+ },
226
+ 'channel-name-required': () => {
227
+ return `You must provide a channelName to construct a ` + `BroadcastCacheUpdate instance.`;
228
+ },
229
+ 'invalid-responses-are-same-args': () => {
230
+ return `The arguments passed into responsesAreSame() appear to be ` + `invalid. Please ensure valid Responses are used.`;
231
+ },
232
+ 'expire-custom-caches-only': () => {
233
+ return `You must provide a 'cacheName' property when using the ` + `expiration plugin with a runtime caching strategy.`;
234
+ },
235
+ 'unit-must-be-bytes': ({ normalizedRangeHeader }) => {
236
+ if (!normalizedRangeHeader) {
237
+ throw new Error(`Unexpected input to 'unit-must-be-bytes' error.`);
238
+ }
239
+ return `The 'unit' portion of the Range header must be set to 'bytes'. ` + `The Range header provided was "${normalizedRangeHeader}"`;
240
+ },
241
+ 'single-range-only': ({ normalizedRangeHeader }) => {
242
+ if (!normalizedRangeHeader) {
243
+ throw new Error(`Unexpected input to 'single-range-only' error.`);
244
+ }
245
+ return `Multiple ranges are not supported. Please use a single start ` + `value, and optional end value. The Range header provided was ` + `"${normalizedRangeHeader}"`;
246
+ },
247
+ 'invalid-range-values': ({ normalizedRangeHeader }) => {
248
+ if (!normalizedRangeHeader) {
249
+ throw new Error(`Unexpected input to 'invalid-range-values' error.`);
250
+ }
251
+ 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}"`;
252
+ },
253
+ 'no-range-header': () => {
254
+ return `No Range header was found in the Request provided.`;
255
+ },
256
+ 'range-not-satisfiable': ({ size, start, end }) => {
257
+ return `The start (${start}) and end (${end}) values in the Range are ` + `not satisfiable by the cached response, which is ${size} bytes.`;
258
+ },
259
+ 'attempt-to-cache-non-get-request': ({ url, method }) => {
260
+ return `Unable to cache '${url}' because it is a '${method}' request and ` + `only 'GET' requests can be cached.`;
261
+ },
262
+ 'cache-put-with-no-response': ({ url }) => {
263
+ return `There was an attempt to cache '${url}' but the response was not ` + `defined.`;
264
+ }
265
+ };
266
+
267
+ /*
268
+ Copyright 2017 Google Inc.
269
+
270
+ Licensed under the Apache License, Version 2.0 (the "License");
271
+ you may not use this file except in compliance with the License.
272
+ You may obtain a copy of the License at
273
+
274
+ https://www.apache.org/licenses/LICENSE-2.0
275
+
276
+ Unless required by applicable law or agreed to in writing, software
277
+ distributed under the License is distributed on an "AS IS" BASIS,
278
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
279
+ See the License for the specific language governing permissions and
280
+ limitations under the License.
281
+ */
282
+
283
+ const generatorFunction = (code, ...args) => {
284
+ const message = messages[code];
285
+ if (!message) {
286
+ throw new Error(`Unable to find message for code '${code}'.`);
287
+ }
288
+
289
+ return message(...args);
290
+ };
291
+
292
+ const exportedValue = generatorFunction;
293
+
294
+ /*
295
+ Copyright 2017 Google Inc.
296
+
297
+ Licensed under the Apache License, Version 2.0 (the "License");
298
+ you may not use this file except in compliance with the License.
299
+ You may obtain a copy of the License at
300
+
301
+ https://www.apache.org/licenses/LICENSE-2.0
302
+
303
+ Unless required by applicable law or agreed to in writing, software
304
+ distributed under the License is distributed on an "AS IS" BASIS,
305
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
306
+ See the License for the specific language governing permissions and
307
+ limitations under the License.
308
+ */
309
+
310
+ /**
311
+ * Workbox errors should be thrown with this class.
312
+ * This allows use to ensure the type easily in tests,
313
+ * helps developers identify errors from workbox
314
+ * easily and allows use to optimise error
315
+ * messages correctly.
316
+ *
317
+ * @private
318
+ */
319
+ class WorkboxError extends Error {
320
+ /**
321
+ *
322
+ * @param {string} errorCode The error code that
323
+ * identifies this particular error.
324
+ * @param {Object=} details Any relevant arguments
325
+ * that will help developers identify issues should
326
+ * be added as a key on the context object.
327
+ */
328
+ constructor(errorCode, details) {
329
+ let message = exportedValue(errorCode, details);
330
+
331
+ super(message);
332
+
333
+ this.name = errorCode;
334
+ this.details = details;
335
+ }
336
+ }
337
+
338
+ /*
339
+ Copyright 2017 Google Inc.
340
+
341
+ Licensed under the Apache License, Version 2.0 (the "License");
342
+ you may not use this file except in compliance with the License.
343
+ You may obtain a copy of the License at
344
+
345
+ https://www.apache.org/licenses/LICENSE-2.0
346
+
347
+ Unless required by applicable law or agreed to in writing, software
348
+ distributed under the License is distributed on an "AS IS" BASIS,
349
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
350
+ See the License for the specific language governing permissions and
351
+ limitations under the License.
352
+ */
353
+
354
+ const _cacheNameDetails = {
355
+ prefix: 'workbox',
356
+ suffix: self.registration.scope,
357
+ googleAnalytics: 'googleAnalytics',
358
+ precache: 'precache',
359
+ runtime: 'runtime'
360
+ };
361
+
362
+ const _createCacheName = cacheName => {
363
+ return [_cacheNameDetails.prefix, cacheName, _cacheNameDetails.suffix].filter(value => value.length > 0).join('-');
364
+ };
365
+
366
+ const cacheNames = {
367
+ updateDetails: details => {
368
+ Object.keys(_cacheNameDetails).forEach(key => {
369
+ if (typeof details[key] !== 'undefined') {
370
+ _cacheNameDetails[key] = details[key];
371
+ }
372
+ });
373
+ },
374
+ getGoogleAnalyticsName: userCacheName => {
375
+ return userCacheName || _createCacheName(_cacheNameDetails.googleAnalytics);
376
+ },
377
+ getPrecacheName: userCacheName => {
378
+ return userCacheName || _createCacheName(_cacheNameDetails.precache);
379
+ },
380
+ getRuntimeName: userCacheName => {
381
+ return userCacheName || _createCacheName(_cacheNameDetails.runtime);
382
+ }
383
+ };
384
+
385
+ /*
386
+ Copyright 2017 Google Inc.
387
+
388
+ Licensed under the Apache License, Version 2.0 (the "License");
389
+ you may not use this file except in compliance with the License.
390
+ You may obtain a copy of the License at
391
+
392
+ https://www.apache.org/licenses/LICENSE-2.0
393
+
394
+ Unless required by applicable law or agreed to in writing, software
395
+ distributed under the License is distributed on an "AS IS" BASIS,
396
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
397
+ See the License for the specific language governing permissions and
398
+ limitations under the License.
399
+ */
400
+
401
+ // Safari doesn't print all console.groupCollapsed() arguments.
402
+ // Related bug: https://bugs.webkit.org/show_bug.cgi?id=182754
403
+ const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
404
+
405
+ const GREY = `#7f8c8d`;
406
+ const GREEN = `#2ecc71`;
407
+ const YELLOW = `#f39c12`;
408
+ const RED = `#c0392b`;
409
+ const BLUE = `#3498db`;
410
+
411
+ const getDefaultLogLevel = () => LOG_LEVELS.log;
412
+
413
+ let logLevel = getDefaultLogLevel();
414
+ const shouldPrint = minLevel => logLevel <= minLevel;
415
+ const setLoggerLevel = newLogLevel => logLevel = newLogLevel;
416
+ const getLoggerLevel = () => logLevel;
417
+
418
+ // We always want groups to be logged unless logLevel is silent.
419
+ const groupLevel = LOG_LEVELS.error;
420
+
421
+ const _print = function (keyName, logArgs, levelColor) {
422
+ const logLevel = keyName.indexOf('group') === 0 ? groupLevel : LOG_LEVELS[keyName];
423
+ if (!shouldPrint(logLevel)) {
424
+ return;
425
+ }
426
+
427
+ if (!levelColor || keyName === 'groupCollapsed' && isSafari) {
428
+ console[keyName](...logArgs);
429
+ return;
430
+ }
431
+
432
+ const logPrefix = ['%cworkbox', `background: ${levelColor}; color: white; padding: 2px 0.5em; ` + `border-radius: 0.5em;`];
433
+ console[keyName](...logPrefix, ...logArgs);
434
+ };
435
+
436
+ const groupEnd = () => {
437
+ if (shouldPrint(groupLevel)) {
438
+ console.groupEnd();
439
+ }
440
+ };
441
+
442
+ const defaultExport = {
443
+ groupEnd,
444
+ unprefixed: {
445
+ groupEnd
446
+ }
447
+ };
448
+
449
+ const setupLogs = (keyName, color) => {
450
+ defaultExport[keyName] = (...args) => _print(keyName, args, color);
451
+ defaultExport.unprefixed[keyName] = (...args) => _print(keyName, args);
452
+ };
453
+
454
+ const levelToColor = {
455
+ debug: GREY,
456
+ log: GREEN,
457
+ warn: YELLOW,
458
+ error: RED,
459
+ groupCollapsed: BLUE
460
+ };
461
+ Object.keys(levelToColor).forEach(keyName => setupLogs(keyName, levelToColor[keyName]));
462
+
463
+ /*
464
+ Copyright 2017 Google Inc.
465
+
466
+ Licensed under the Apache License, Version 2.0 (the "License");
467
+ you may not use this file except in compliance with the License.
468
+ You may obtain a copy of the License at
469
+
470
+ https://www.apache.org/licenses/LICENSE-2.0
471
+
472
+ Unless required by applicable law or agreed to in writing, software
473
+ distributed under the License is distributed on an "AS IS" BASIS,
474
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
475
+ See the License for the specific language governing permissions and
476
+ limitations under the License.
477
+ */
478
+
479
+ /*
480
+ * This method returns true if the current context is a service worker.
481
+ */
482
+ const isSwEnv = moduleName => {
483
+ if (!('ServiceWorkerGlobalScope' in self)) {
484
+ throw new WorkboxError('not-in-sw', { moduleName });
485
+ }
486
+ };
487
+
488
+ /*
489
+ * This method throws if the supplied value is not an array.
490
+ * The destructed values are required to produce a meaningful error for users.
491
+ * The destructed and restructured object is so it's clear what is
492
+ * needed.
493
+ */
494
+ const isArray = (value, { moduleName, className, funcName, paramName }) => {
495
+ if (!Array.isArray(value)) {
496
+ throw new WorkboxError('not-an-array', {
497
+ moduleName,
498
+ className,
499
+ funcName,
500
+ paramName
501
+ });
502
+ }
503
+ };
504
+
505
+ const hasMethod = (object, expectedMethod, { moduleName, className, funcName, paramName }) => {
506
+ const type = typeof object[expectedMethod];
507
+ if (type !== 'function') {
508
+ throw new WorkboxError('missing-a-method', { paramName, expectedMethod,
509
+ moduleName, className, funcName });
510
+ }
511
+ };
512
+
513
+ const isType = (object, expectedType, { moduleName, className, funcName, paramName }) => {
514
+ if (typeof object !== expectedType) {
515
+ throw new WorkboxError('incorrect-type', { paramName, expectedType,
516
+ moduleName, className, funcName });
517
+ }
518
+ };
519
+
520
+ const isInstance = (object, expectedClass, { moduleName, className, funcName,
521
+ paramName, isReturnValueProblem }) => {
522
+ if (!(object instanceof expectedClass)) {
523
+ throw new WorkboxError('incorrect-class', { paramName, expectedClass,
524
+ moduleName, className, funcName, isReturnValueProblem });
525
+ }
526
+ };
527
+
528
+ const isOneOf = (value, validValues, { paramName }) => {
529
+ if (!validValues.includes(value)) {
530
+ throw new WorkboxError('invalid-value', {
531
+ paramName,
532
+ value,
533
+ validValueDescription: `Valid values are ${JSON.stringify(validValues)}.`
534
+ });
535
+ }
536
+ };
537
+
538
+ const isArrayOfClass = (value, expectedClass, { moduleName, className, funcName, paramName }) => {
539
+ const error = new WorkboxError('not-array-of-class', {
540
+ value, expectedClass,
541
+ moduleName, className, funcName, paramName
542
+ });
543
+ if (!Array.isArray(value)) {
544
+ throw error;
545
+ }
546
+
547
+ for (let item of value) {
548
+ if (!(item instanceof expectedClass)) {
549
+ throw error;
550
+ }
551
+ }
552
+ };
553
+
554
+ const finalAssertExports = {
555
+ hasMethod,
556
+ isArray,
557
+ isInstance,
558
+ isOneOf,
559
+ isSwEnv,
560
+ isType,
561
+ isArrayOfClass
562
+ };
563
+
564
+ /*
565
+ Copyright 2017 Google Inc.
566
+
567
+ Licensed under the Apache License, Version 2.0 (the "License");
568
+ you may not use this file except in compliance with the License.
569
+ You may obtain a copy of the License at
570
+
571
+ https://www.apache.org/licenses/LICENSE-2.0
572
+
573
+ Unless required by applicable law or agreed to in writing, software
574
+ distributed under the License is distributed on an "AS IS" BASIS,
575
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
576
+ See the License for the specific language governing permissions and
577
+ limitations under the License.
578
+ */
579
+
580
+ /**
581
+ * Logs a warning to the user recommending changing
582
+ * to max-age=0 or no-cache.
583
+ *
584
+ * @param {string} cacheControlHeader
585
+ *
586
+ * @private
587
+ */
588
+ function showWarning(cacheControlHeader) {
589
+ const docsUrl = 'https://developers.google.com/web/tools/workbox/guides/service-worker-checklist#cache-control_of_your_service_worker_file';
590
+ defaultExport.warn(`You are setting a 'cache-control' header of ` + `'${cacheControlHeader}' on your service worker file. This should be ` + `set to 'max-age=0' or 'no-cache' to ensure the latest service worker ` + `is served to your users. Learn more here: ${docsUrl}`);
591
+ }
592
+
593
+ /**
594
+ * Checks for cache-control header on SW file and
595
+ * warns the developer if it exists with a value
596
+ * other than max-age=0 or no-cache.
597
+ *
598
+ * @return {Promise}
599
+ * @private
600
+ */
601
+ function checkSWFileCacheHeaders() {
602
+ // This is wrapped as an iife to allow async/await while making
603
+ // rollup exclude it in builds.
604
+ return babelHelpers.asyncToGenerator(function* () {
605
+ try {
606
+ const swFile = self.location.href;
607
+ const response = yield fetch(swFile);
608
+ if (!response.ok) {
609
+ // Response failed so nothing we can check;
610
+ return;
611
+ }
612
+
613
+ if (!response.headers.has('cache-control')) {
614
+ // No cache control header.
615
+ return;
616
+ }
617
+
618
+ const cacheControlHeader = response.headers.get('cache-control');
619
+ const maxAgeResult = /max-age\s*=\s*(\d*)/g.exec(cacheControlHeader);
620
+ if (maxAgeResult) {
621
+ if (parseInt(maxAgeResult[1], 10) === 0) {
622
+ return;
623
+ }
624
+ }
625
+
626
+ if (cacheControlHeader.indexOf('no-cache') !== -1) {
627
+ return;
628
+ }
629
+
630
+ if (cacheControlHeader.indexOf('no-store') !== -1) {
631
+ return;
632
+ }
633
+
634
+ showWarning(cacheControlHeader);
635
+ } catch (err) {
636
+ // NOOP
637
+ }
638
+ })();
639
+ }
640
+
641
+ const finalCheckSWFileCacheHeaders = checkSWFileCacheHeaders;
642
+
643
+ /*
644
+ Copyright 2017 Google Inc.
645
+
646
+ Licensed under the Apache License, Version 2.0 (the "License");
647
+ you may not use this file except in compliance with the License.
648
+ You may obtain a copy of the License at
649
+
650
+ https://www.apache.org/licenses/LICENSE-2.0
651
+
652
+ Unless required by applicable law or agreed to in writing, software
653
+ distributed under the License is distributed on an "AS IS" BASIS,
654
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
655
+ See the License for the specific language governing permissions and
656
+ limitations under the License.
657
+ */
658
+
659
+ /**
660
+ * This class is never exposed publicly. Inidividual methods are exposed
661
+ * using jsdoc alias commands.
662
+ *
663
+ * @memberof workbox.core
664
+ * @private
665
+ */
666
+ class WorkboxCore {
667
+ /**
668
+ * You should not instantiate this object directly.
669
+ *
670
+ * @private
671
+ */
672
+ constructor() {
673
+ // Give our version strings something to hang off of.
674
+ try {
675
+ self.workbox.v = self.workbox.v || {};
676
+ } catch (err) {}
677
+ // NOOP
678
+
679
+
680
+ // A WorkboxCore instance must be exported before we can use the logger.
681
+ // This is so it can get the current log level.
682
+ {
683
+ const padding = ' ';
684
+ defaultExport.groupCollapsed('Welcome to Workbox!');
685
+ defaultExport.unprefixed.log(`You are currently using a development build. ` + `By default this will switch to prod builds when not on localhost. ` + `You can force this with workbox.setConfig({debug: true|false}).`);
686
+ defaultExport.unprefixed.log(`📖 Read the guides and documentation\n` + `${padding}https://developers.google.com/web/tools/workbox/`);
687
+ defaultExport.unprefixed.log(`❓ Use the [workbox] tag on Stack Overflow to ask questions\n` + `${padding}https://stackoverflow.com/questions/ask?tags=workbox`);
688
+ defaultExport.unprefixed.log(`🐛 Found a bug? Report it on GitHub\n` + `${padding}https://github.com/GoogleChrome/workbox/issues/new`);
689
+ defaultExport.groupEnd();
690
+
691
+ if (typeof finalCheckSWFileCacheHeaders === 'function') {
692
+ finalCheckSWFileCacheHeaders();
693
+ }
694
+ }
695
+ }
696
+
697
+ /**
698
+ * Get the current cache names used by Workbox.
699
+ *
700
+ * `cacheNames.precache` is used for precached assets,
701
+ * `cacheNames.googleAnalytics` is used by `workbox-google-analytics` to
702
+ * store `analytics.js`,
703
+ * and `cacheNames.runtime` is used for everything else.
704
+ *
705
+ * @return {Object} An object with `precache` and `runtime` cache names.
706
+ *
707
+ * @alias workbox.core.cacheNames
708
+ */
709
+ get cacheNames() {
710
+ return {
711
+ googleAnalytics: cacheNames.getGoogleAnalyticsName(),
712
+ precache: cacheNames.getPrecacheName(),
713
+ runtime: cacheNames.getRuntimeName()
714
+ };
715
+ }
716
+
717
+ /**
718
+ * You can alter the default cache names used by the Workbox modules by
719
+ * changing the cache name details.
720
+ *
721
+ * Cache names are generated as `<prefix>-<Cache Name>-<suffix>`.
722
+ *
723
+ * @param {Object} details
724
+ * @param {Object} details.prefix The string to add to the beginning of
725
+ * the precache and runtime cache names.
726
+ * @param {Object} details.suffix The string to add to the end of
727
+ * the precache and runtime cache names.
728
+ * @param {Object} details.precache The cache name to use for precache
729
+ * caching.
730
+ * @param {Object} details.runtime The cache name to use for runtime caching.
731
+ * @param {Object} details.googleAnalytics The cache name to use for
732
+ * `workbox-google-analytics` caching.
733
+ *
734
+ * @alias workbox.core.setCacheNameDetails
735
+ */
736
+ setCacheNameDetails(details) {
737
+ {
738
+ Object.keys(details).forEach(key => {
739
+ finalAssertExports.isType(details[key], 'string', {
740
+ moduleName: 'workbox-core',
741
+ className: 'WorkboxCore',
742
+ funcName: 'setCacheNameDetails',
743
+ paramName: `details.${key}`
744
+ });
745
+ });
746
+
747
+ if ('precache' in details && details.precache.length === 0) {
748
+ throw new WorkboxError('invalid-cache-name', {
749
+ cacheNameId: 'precache',
750
+ value: details.precache
751
+ });
752
+ }
753
+
754
+ if ('runtime' in details && details.runtime.length === 0) {
755
+ throw new WorkboxError('invalid-cache-name', {
756
+ cacheNameId: 'runtime',
757
+ value: details.runtime
758
+ });
759
+ }
760
+
761
+ if ('googleAnalytics' in details && details.googleAnalytics.length === 0) {
762
+ throw new WorkboxError('invalid-cache-name', {
763
+ cacheNameId: 'googleAnalytics',
764
+ value: details.googleAnalytics
765
+ });
766
+ }
767
+ }
768
+
769
+ cacheNames.updateDetails(details);
770
+ }
771
+
772
+ /**
773
+ * Get the current log level.
774
+ *
775
+ * @return {number}.
776
+ *
777
+ * @alias workbox.core.logLevel
778
+ */
779
+ get logLevel() {
780
+ return getLoggerLevel();
781
+ }
782
+
783
+ /**
784
+ * Set the current log level passing in one of the values from
785
+ * [LOG_LEVELS]{@link module:workbox-core.LOG_LEVELS}.
786
+ *
787
+ * @param {number} newLevel The new log level to use.
788
+ *
789
+ * @alias workbox.core.setLogLevel
790
+ */
791
+ setLogLevel(newLevel) {
792
+ {
793
+ finalAssertExports.isType(newLevel, 'number', {
794
+ moduleName: 'workbox-core',
795
+ className: 'WorkboxCore',
796
+ funcName: 'logLevel [setter]',
797
+ paramName: `logLevel`
798
+ });
799
+ }
800
+
801
+ if (newLevel > LOG_LEVELS.silent || newLevel < LOG_LEVELS.debug) {
802
+ throw new WorkboxError('invalid-value', {
803
+ paramName: 'logLevel',
804
+ validValueDescription: `Please use a value from LOG_LEVELS, i.e ` + `'logLevel = workbox.core.LOG_LEVELS.debug'.`,
805
+ value: newLevel
806
+ });
807
+ }
808
+
809
+ setLoggerLevel(newLevel);
810
+ }
811
+ }
812
+
813
+ var defaultExport$1 = new WorkboxCore();
814
+
815
+ /*
816
+ Copyright 2017 Google Inc.
817
+
818
+ Licensed under the Apache License, Version 2.0 (the "License");
819
+ you may not use this file except in compliance with the License.
820
+ You may obtain a copy of the License at
821
+
822
+ https://www.apache.org/licenses/LICENSE-2.0
823
+
824
+ Unless required by applicable law or agreed to in writing, software
825
+ distributed under the License is distributed on an "AS IS" BASIS,
826
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
827
+ See the License for the specific language governing permissions and
828
+ limitations under the License.
829
+ */
830
+
831
+ /**
832
+ * A class that wraps common IndexedDB functionality in a promise-based API.
833
+ * It exposes all the underlying power and functionality of IndexedDB, but
834
+ * wraps the most commonly used features in a way that's much simpler to use.
835
+ *
836
+ * @private
837
+ */
838
+ class DBWrapper {
839
+ /**
840
+ * @param {string} name
841
+ * @param {number} version
842
+ * @param {Object=} [callback]
843
+ * @param {function(this:DBWrapper, Event)} [callbacks.onupgradeneeded]
844
+ * @param {function(this:DBWrapper, Event)} [callbacks.onversionchange]
845
+ * Defaults to DBWrapper.prototype._onversionchange when not specified.
846
+ */
847
+ constructor(name, version, {
848
+ onupgradeneeded,
849
+ onversionchange = this._onversionchange
850
+ } = {}) {
851
+ this._name = name;
852
+ this._version = version;
853
+ this._onupgradeneeded = onupgradeneeded;
854
+ this._onversionchange = onversionchange;
855
+
856
+ // If this is null, it means the database isn't open.
857
+ this._db = null;
858
+ }
859
+
860
+ /**
861
+ * Opens a connected to an IDBDatabase, invokes any onupgradedneeded
862
+ * callback, and added an onversionchange callback to the database.
863
+ *
864
+ * @return {IDBDatabase}
865
+ *
866
+ * @private
867
+ */
868
+ open() {
869
+ var _this = this;
870
+
871
+ return babelHelpers.asyncToGenerator(function* () {
872
+ if (_this._db) return;
873
+
874
+ _this._db = yield new Promise(function (resolve, reject) {
875
+ // This flag is flipped to true if the timeout callback runs prior
876
+ // to the request failing or succeeding. Note: we use a timeout instead
877
+ // of an onblocked handler since there are cases where onblocked will
878
+ // never never run. A timeout better handles all possible scenarios:
879
+ // https://github.com/w3c/IndexedDB/issues/223
880
+ let openRequestTimedOut = false;
881
+ setTimeout(function () {
882
+ openRequestTimedOut = true;
883
+ reject(new Error('The open request was blocked and timed out'));
884
+ }, _this.OPEN_TIMEOUT);
885
+
886
+ const openRequest = indexedDB.open(_this._name, _this._version);
887
+ openRequest.onerror = function (evt) {
888
+ return reject(openRequest.error);
889
+ };
890
+ openRequest.onupgradeneeded = function (evt) {
891
+ if (openRequestTimedOut) {
892
+ openRequest.transaction.abort();
893
+ evt.target.result.close();
894
+ } else if (_this._onupgradeneeded) {
895
+ _this._onupgradeneeded(evt);
896
+ }
897
+ };
898
+ openRequest.onsuccess = function (evt) {
899
+ const db = evt.target.result;
900
+ if (openRequestTimedOut) {
901
+ db.close();
902
+ } else {
903
+ db.onversionchange = _this._onversionchange;
904
+ resolve(db);
905
+ }
906
+ };
907
+ });
908
+
909
+ return _this;
910
+ })();
911
+ }
912
+
913
+ /**
914
+ * Delegates to the native `get()` method for the object store.
915
+ *
916
+ * @param {string} storeName The name of the object store to put the value.
917
+ * @param {...*} args The values passed to the delegated method.
918
+ * @return {*} The key of the entry.
919
+ *
920
+ * @private
921
+ */
922
+ get(storeName, ...args) {
923
+ var _this2 = this;
924
+
925
+ return babelHelpers.asyncToGenerator(function* () {
926
+ return yield _this2._call('get', storeName, 'readonly', ...args);
927
+ })();
928
+ }
929
+
930
+ /**
931
+ * Delegates to the native `add()` method for the object store.
932
+ *
933
+ * @param {string} storeName The name of the object store to put the value.
934
+ * @param {...*} args The values passed to the delegated method.
935
+ * @return {*} The key of the entry.
936
+ *
937
+ * @private
938
+ */
939
+ add(storeName, ...args) {
940
+ var _this3 = this;
941
+
942
+ return babelHelpers.asyncToGenerator(function* () {
943
+ return yield _this3._call('add', storeName, 'readwrite', ...args);
944
+ })();
945
+ }
946
+
947
+ /**
948
+ * Delegates to the native `put()` method for the object store.
949
+ *
950
+ * @param {string} storeName The name of the object store to put the value.
951
+ * @param {...*} args The values passed to the delegated method.
952
+ * @return {*} The key of the entry.
953
+ *
954
+ * @private
955
+ */
956
+ put(storeName, ...args) {
957
+ var _this4 = this;
958
+
959
+ return babelHelpers.asyncToGenerator(function* () {
960
+ return yield _this4._call('put', storeName, 'readwrite', ...args);
961
+ })();
962
+ }
963
+
964
+ /**
965
+ * Delegates to the native `delete()` method for the object store.
966
+ *
967
+ * @param {string} storeName
968
+ * @param {...*} args The values passed to the delegated method.
969
+ *
970
+ * @private
971
+ */
972
+ delete(storeName, ...args) {
973
+ var _this5 = this;
974
+
975
+ return babelHelpers.asyncToGenerator(function* () {
976
+ yield _this5._call('delete', storeName, 'readwrite', ...args);
977
+ })();
978
+ }
979
+
980
+ /**
981
+ * Deletes the underlying database, ensuring that any open connections are
982
+ * closed first.
983
+ *
984
+ * @private
985
+ */
986
+ deleteDatabase() {
987
+ var _this6 = this;
988
+
989
+ return babelHelpers.asyncToGenerator(function* () {
990
+ _this6.close();
991
+ _this6._db = null;
992
+ yield new Promise(function (resolve, reject) {
993
+ const request = indexedDB.deleteDatabase(_this6._name);
994
+ request.onerror = function (evt) {
995
+ return reject(evt.target.error);
996
+ };
997
+ request.onblocked = function () {
998
+ return reject(new Error('Deletion was blocked.'));
999
+ };
1000
+ request.onsuccess = function () {
1001
+ return resolve();
1002
+ };
1003
+ });
1004
+ })();
1005
+ }
1006
+
1007
+ /**
1008
+ * Delegates to the native `getAll()` or polyfills it via the `find()`
1009
+ * method in older browsers.
1010
+ *
1011
+ * @param {string} storeName
1012
+ * @param {*} query
1013
+ * @param {number} count
1014
+ * @return {Array}
1015
+ *
1016
+ * @private
1017
+ */
1018
+ getAll(storeName, query, count) {
1019
+ var _this7 = this;
1020
+
1021
+ return babelHelpers.asyncToGenerator(function* () {
1022
+ if ('getAll' in IDBObjectStore.prototype) {
1023
+ return yield _this7._call('getAll', storeName, 'readonly', query, count);
1024
+ } else {
1025
+ return yield _this7.getAllMatching(storeName, { query, count });
1026
+ }
1027
+ })();
1028
+ }
1029
+
1030
+ /**
1031
+ * Supports flexible lookup in an object store by specifying an index,
1032
+ * query, direction, and count. This method returns an array of objects
1033
+ * with the signature .
1034
+ *
1035
+ * @param {string} storeName
1036
+ * @param {Object} [opts]
1037
+ * @param {IDBCursorDirection} [opts.direction]
1038
+ * @param {*} [opts.query]
1039
+ * @param {string} [opts.index] The index to use (if specified).
1040
+ * @param {number} [opts.count] The max number of results to return.
1041
+ * @param {boolean} [opts.includeKeys] When true, the structure of the
1042
+ * returned objects is changed from an array of values to an array of
1043
+ * objects in the form {key, primaryKey, value}.
1044
+ * @return {Array}
1045
+ *
1046
+ * @private
1047
+ */
1048
+ getAllMatching(storeName, opts = {}) {
1049
+ var _this8 = this;
1050
+
1051
+ return babelHelpers.asyncToGenerator(function* () {
1052
+ return yield _this8.transaction([storeName], 'readonly', function (stores, done) {
1053
+ const store = stores[storeName];
1054
+ const target = opts.index ? store.index(opts.index) : store;
1055
+ const results = [];
1056
+
1057
+ target.openCursor(opts.query, opts.direction).onsuccess = function (evt) {
1058
+ const cursor = evt.target.result;
1059
+ if (cursor) {
1060
+ const { primaryKey, key, value } = cursor;
1061
+ results.push(opts.includeKeys ? { primaryKey, key, value } : value);
1062
+ if (opts.count && results.length >= opts.count) {
1063
+ done(results);
1064
+ } else {
1065
+ cursor.continue();
1066
+ }
1067
+ } else {
1068
+ done(results);
1069
+ }
1070
+ };
1071
+ });
1072
+ })();
1073
+ }
1074
+
1075
+ /**
1076
+ * Accepts a list of stores, a transaction type, and a callback and
1077
+ * performs a transaction. A promise is returned that resolves to whatever
1078
+ * value the callback chooses. The callback holds all the transaction logic
1079
+ * and is invoked with three arguments:
1080
+ * 1. An object mapping object store names to IDBObjectStore values.
1081
+ * 2. A `done` function, that's used to resolve the promise when
1082
+ * when the transaction is done.
1083
+ * 3. An `abort` function that can be called to abort the transaction
1084
+ * at any time.
1085
+ *
1086
+ * @param {Array<string>} storeNames An array of object store names
1087
+ * involved in the transaction.
1088
+ * @param {string} type Can be `readonly` or `readwrite`.
1089
+ * @param {function(Object, function(), function(*)):?IDBRequest} callback
1090
+ * @return {*} The result of the transaction ran by the callback.
1091
+ *
1092
+ * @private
1093
+ */
1094
+ transaction(storeNames, type, callback) {
1095
+ var _this9 = this;
1096
+
1097
+ return babelHelpers.asyncToGenerator(function* () {
1098
+ yield _this9.open();
1099
+ const result = yield new Promise(function (resolve, reject) {
1100
+ const txn = _this9._db.transaction(storeNames, type);
1101
+ const done = function (value) {
1102
+ return resolve(value);
1103
+ };
1104
+ const abort = function () {
1105
+ reject(new Error('The transaction was manually aborted'));
1106
+ txn.abort();
1107
+ };
1108
+ txn.onerror = function (evt) {
1109
+ return reject(evt.target.error);
1110
+ };
1111
+ txn.onabort = function (evt) {
1112
+ return reject(evt.target.error);
1113
+ };
1114
+ txn.oncomplete = function () {
1115
+ return resolve();
1116
+ };
1117
+
1118
+ const stores = {};
1119
+ for (const storeName of storeNames) {
1120
+ stores[storeName] = txn.objectStore(storeName);
1121
+ }
1122
+ callback(stores, done, abort);
1123
+ });
1124
+ return result;
1125
+ })();
1126
+ }
1127
+
1128
+ /**
1129
+ * Delegates async to a native IDBObjectStore method.
1130
+ *
1131
+ * @param {string} method The method name.
1132
+ * @param {string} storeName The object store name.
1133
+ * @param {string} type Can be `readonly` or `readwrite`.
1134
+ * @param {...*} args The list of args to pass to the native method.
1135
+ * @return {*} The result of the transaction.
1136
+ *
1137
+ * @private
1138
+ */
1139
+ _call(method, storeName, type, ...args) {
1140
+ var _this10 = this;
1141
+
1142
+ return babelHelpers.asyncToGenerator(function* () {
1143
+ yield _this10.open();
1144
+ const callback = function (stores, done) {
1145
+ stores[storeName][method](...args).onsuccess = function (evt) {
1146
+ done(evt.target.result);
1147
+ };
1148
+ };
1149
+
1150
+ return yield _this10.transaction([storeName], type, callback);
1151
+ })();
1152
+ }
1153
+
1154
+ /**
1155
+ * The default onversionchange handler, which closes the database so other
1156
+ * connections can open without being blocked.
1157
+ *
1158
+ * @param {Event} evt
1159
+ *
1160
+ * @private
1161
+ */
1162
+ _onversionchange(evt) {
1163
+ this.close();
1164
+ }
1165
+
1166
+ /**
1167
+ * Closes the connection opened by `DBWrapper.open()`. Generally this method
1168
+ * doesn't need to be called since:
1169
+ * 1. It's usually better to keep a connection open since opening
1170
+ * a new connection is somewhat slow.
1171
+ * 2. Connections are automatically closed when the reference is
1172
+ * garbage collected.
1173
+ * The primary use case for needing to close a connection is when another
1174
+ * reference (typically in another tab) needs to upgrade it and would be
1175
+ * blocked by the current, open connection.
1176
+ *
1177
+ * @private
1178
+ */
1179
+ close() {
1180
+ if (this._db) this._db.close();
1181
+ }
1182
+ }
1183
+
1184
+ // Exposed to let users modify the default timeout on a per-instance
1185
+ // or global basis.
1186
+ DBWrapper.prototype.OPEN_TIMEOUT = 2000;
1187
+
1188
+ /*
1189
+ Copyright 2017 Google Inc.
1190
+
1191
+ Licensed under the Apache License, Version 2.0 (the "License");
1192
+ you may not use this file except in compliance with the License.
1193
+ You may obtain a copy of the License at
1194
+
1195
+ https://www.apache.org/licenses/LICENSE-2.0
1196
+
1197
+ Unless required by applicable law or agreed to in writing, software
1198
+ distributed under the License is distributed on an "AS IS" BASIS,
1199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1200
+ See the License for the specific language governing permissions and
1201
+ limitations under the License.
1202
+ */
1203
+
1204
+ var pluginEvents = {
1205
+ CACHE_DID_UPDATE: 'cacheDidUpdate',
1206
+ CACHE_WILL_UPDATE: 'cacheWillUpdate',
1207
+ CACHED_RESPONSE_WILL_BE_USED: 'cachedResponseWillBeUsed',
1208
+ FETCH_DID_FAIL: 'fetchDidFail',
1209
+ REQUEST_WILL_FETCH: 'requestWillFetch'
1210
+ };
1211
+
1212
+ /*
1213
+ Copyright 2017 Google Inc.
1214
+
1215
+ Licensed under the Apache License, Version 2.0 (the "License");
1216
+ you may not use this file except in compliance with the License.
1217
+ You may obtain a copy of the License at
1218
+
1219
+ https://www.apache.org/licenses/LICENSE-2.0
1220
+
1221
+ Unless required by applicable law or agreed to in writing, software
1222
+ distributed under the License is distributed on an "AS IS" BASIS,
1223
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1224
+ See the License for the specific language governing permissions and
1225
+ limitations under the License.
1226
+ */
1227
+
1228
+ var pluginUtils = {
1229
+ filter: (plugins, callbackname) => {
1230
+ return plugins.filter(plugin => callbackname in plugin);
1231
+ }
1232
+ };
1233
+
1234
+ /**
1235
+ * Runs all of the callback functions, one at a time sequentially, in the order
1236
+ * in which they were registered.
1237
+ *
1238
+ * @memberof workbox.core
1239
+ * @private
1240
+ */
1241
+ let executeQuotaErrorCallbacks = (() => {
1242
+ var _ref = babelHelpers.asyncToGenerator(function* () {
1243
+ {
1244
+ defaultExport.log(`About to run ${callbacks.size} callbacks to clean up caches.`);
1245
+ }
1246
+
1247
+ for (const callback of callbacks) {
1248
+ yield callback();
1249
+ {
1250
+ defaultExport.log(callback, 'is complete.');
1251
+ }
1252
+ }
1253
+
1254
+ {
1255
+ defaultExport.log('Finished running callbacks.');
1256
+ }
1257
+ });
1258
+
1259
+ return function executeQuotaErrorCallbacks() {
1260
+ return _ref.apply(this, arguments);
1261
+ };
1262
+ })();
1263
+
1264
+ const callbacks = new Set();
1265
+
1266
+ /**
1267
+ * Adds a function to the set of callbacks that will be executed when there's
1268
+ * a quota error.
1269
+ *
1270
+ * @param {Function} callback
1271
+ * @memberof workbox.core
1272
+ */
1273
+ function registerQuotaErrorCallback(callback) {
1274
+ {
1275
+ finalAssertExports.isType(callback, 'function', {
1276
+ moduleName: 'workbox-core',
1277
+ funcName: 'register',
1278
+ paramName: 'callback'
1279
+ });
1280
+ }
1281
+
1282
+ callbacks.add(callback);
1283
+
1284
+ {
1285
+ defaultExport.log('Registered a callback to respond to quota errors.', callback);
1286
+ }
1287
+ }
1288
+
1289
+ /*
1290
+ Copyright 2017 Google Inc.
1291
+
1292
+ Licensed under the Apache License, Version 2.0 (the "License");
1293
+ you may not use this file except in compliance with the License.
1294
+ You may obtain a copy of the License at
1295
+
1296
+ https://www.apache.org/licenses/LICENSE-2.0
1297
+
1298
+ Unless required by applicable law or agreed to in writing, software
1299
+ distributed under the License is distributed on an "AS IS" BASIS,
1300
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1301
+ See the License for the specific language governing permissions and
1302
+ limitations under the License.
1303
+ */
1304
+
1305
+ const getFriendlyURL = url => {
1306
+ const urlObj = new URL(url, location);
1307
+ if (urlObj.origin === location.origin) {
1308
+ return urlObj.pathname;
1309
+ }
1310
+ return urlObj.href;
1311
+ };
1312
+
1313
+ /*
1314
+ Copyright 2017 Google Inc.
1315
+
1316
+ Licensed under the Apache License, Version 2.0 (the "License");
1317
+ you may not use this file except in compliance with the License.
1318
+ You may obtain a copy of the License at
1319
+
1320
+ https://www.apache.org/licenses/LICENSE-2.0
1321
+
1322
+ Unless required by applicable law or agreed to in writing, software
1323
+ distributed under the License is distributed on an "AS IS" BASIS,
1324
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1325
+ See the License for the specific language governing permissions and
1326
+ limitations under the License.
1327
+ */
1328
+
1329
+ /**
1330
+ * Wrapper around cache.put().
1331
+ *
1332
+ * Will call `cacheDidUpdate` on plugins if the cache was updated.
1333
+ *
1334
+ * @param {string} cacheName
1335
+ * @param {Request} request
1336
+ * @param {Response} response
1337
+ * @param {Array<Object>} [plugins]
1338
+ *
1339
+ * @private
1340
+ * @memberof module:workbox-core
1341
+ */
1342
+ const putWrapper = (() => {
1343
+ var _ref = babelHelpers.asyncToGenerator(function* (cacheName, request, response, plugins = []) {
1344
+ if (!response) {
1345
+ {
1346
+ defaultExport.error(`Cannot cache non-existent response for ` + `'${getFriendlyURL(request.url)}'.`);
1347
+ }
1348
+
1349
+ throw new WorkboxError('cache-put-with-no-response', {
1350
+ url: getFriendlyURL(request.url)
1351
+ });
1352
+ }
1353
+
1354
+ let responseToCache = yield _isResponseSafeToCache(request, response, plugins);
1355
+
1356
+ if (!responseToCache) {
1357
+ {
1358
+ defaultExport.debug(`Response '${getFriendlyURL(request.url)}' will not be ` + `cached.`, responseToCache);
1359
+ }
1360
+ return;
1361
+ }
1362
+
1363
+ {
1364
+ if (responseToCache.method && responseToCache.method !== 'GET') {
1365
+ throw new WorkboxError('attempt-to-cache-non-get-request', {
1366
+ url: getFriendlyURL(request.url),
1367
+ method: responseToCache.method
1368
+ });
1369
+ }
1370
+ }
1371
+
1372
+ const cache = yield caches.open(cacheName);
1373
+
1374
+ const updatePlugins = pluginUtils.filter(plugins, pluginEvents.CACHE_DID_UPDATE);
1375
+
1376
+ let oldResponse = updatePlugins.length > 0 ? yield matchWrapper(cacheName, request) : null;
1377
+
1378
+ {
1379
+ defaultExport.debug(`Updating the '${cacheName}' cache with a new Response for ` + `${getFriendlyURL(request.url)}.`);
1380
+ }
1381
+
1382
+ try {
1383
+ yield cache.put(request, responseToCache);
1384
+ } catch (error) {
1385
+ // See https://developer.mozilla.org/en-US/docs/Web/API/DOMException#exception-QuotaExceededError
1386
+ if (error.name === 'QuotaExceededError') {
1387
+ yield executeQuotaErrorCallbacks();
1388
+ }
1389
+ throw error;
1390
+ }
1391
+
1392
+ for (let plugin of updatePlugins) {
1393
+ yield plugin[pluginEvents.CACHE_DID_UPDATE].call(plugin, {
1394
+ cacheName,
1395
+ request,
1396
+ oldResponse,
1397
+ newResponse: responseToCache
1398
+ });
1399
+ }
1400
+ });
1401
+
1402
+ return function putWrapper(_x, _x2, _x3) {
1403
+ return _ref.apply(this, arguments);
1404
+ };
1405
+ })();
1406
+
1407
+ /**
1408
+ * This is a wrapper around cache.match().
1409
+ *
1410
+ * @param {string} cacheName Name of the cache to match against.
1411
+ * @param {Request} request The Request that will be used to look up cache
1412
+ * entries.
1413
+ * @param {Object} matchOptions Options passed to cache.match().
1414
+ * @param {Array<Object>} [plugins] Array of plugins.
1415
+ * @return {Response} A cached response if available.
1416
+ *
1417
+ * @private
1418
+ * @memberof module:workbox-core
1419
+ */
1420
+ const matchWrapper = (() => {
1421
+ var _ref2 = babelHelpers.asyncToGenerator(function* (cacheName, request, matchOptions, plugins = []) {
1422
+ const cache = yield caches.open(cacheName);
1423
+ let cachedResponse = yield cache.match(request, matchOptions);
1424
+ {
1425
+ if (cachedResponse) {
1426
+ defaultExport.debug(`Found a cached response in '${cacheName}'.`);
1427
+ } else {
1428
+ defaultExport.debug(`No cached response found in '${cacheName}'.`);
1429
+ }
1430
+ }
1431
+ for (let plugin of plugins) {
1432
+ if (pluginEvents.CACHED_RESPONSE_WILL_BE_USED in plugin) {
1433
+ cachedResponse = yield plugin[pluginEvents.CACHED_RESPONSE_WILL_BE_USED].call(plugin, {
1434
+ cacheName,
1435
+ request,
1436
+ matchOptions,
1437
+ cachedResponse
1438
+ });
1439
+ {
1440
+ if (cachedResponse) {
1441
+ finalAssertExports.isInstance(cachedResponse, Response, {
1442
+ moduleName: 'Plugin',
1443
+ funcName: pluginEvents.CACHED_RESPONSE_WILL_BE_USED,
1444
+ isReturnValueProblem: true
1445
+ });
1446
+ }
1447
+ }
1448
+ }
1449
+ }
1450
+ return cachedResponse;
1451
+ });
1452
+
1453
+ return function matchWrapper(_x4, _x5, _x6) {
1454
+ return _ref2.apply(this, arguments);
1455
+ };
1456
+ })();
1457
+
1458
+ /**
1459
+ * This method will call cacheWillUpdate on the available plugins (or use
1460
+ * response.ok) to determine if the Response is safe and valid to cache.
1461
+ *
1462
+ * @param {Request} request
1463
+ * @param {Response} response
1464
+ * @param {Array<Object>} plugins
1465
+ * @return {Promise<Response>}
1466
+ *
1467
+ * @private
1468
+ * @memberof module:workbox-core
1469
+ */
1470
+ const _isResponseSafeToCache = (() => {
1471
+ var _ref3 = babelHelpers.asyncToGenerator(function* (request, response, plugins) {
1472
+ let responseToCache = response;
1473
+ let pluginsUsed = false;
1474
+ for (let plugin of plugins) {
1475
+ if (pluginEvents.CACHE_WILL_UPDATE in plugin) {
1476
+ pluginsUsed = true;
1477
+ responseToCache = yield plugin[pluginEvents.CACHE_WILL_UPDATE].call(plugin, {
1478
+ request,
1479
+ response: responseToCache
1480
+ });
1481
+
1482
+ {
1483
+ if (responseToCache) {
1484
+ finalAssertExports.isInstance(responseToCache, Response, {
1485
+ moduleName: 'Plugin',
1486
+ funcName: pluginEvents.CACHE_WILL_UPDATE,
1487
+ isReturnValueProblem: true
1488
+ });
1489
+ }
1490
+ }
1491
+
1492
+ if (!responseToCache) {
1493
+ break;
1494
+ }
1495
+ }
1496
+ }
1497
+
1498
+ if (!pluginsUsed) {
1499
+ {
1500
+ if (!responseToCache.ok) {
1501
+ if (responseToCache.status === 0) {
1502
+ defaultExport.warn(`The response for '${request.url}' is an opaque ` + `response. The caching strategy that you're using will not ` + `cache opaque responses by default.`);
1503
+ } else {
1504
+ defaultExport.debug(`The response for '${request.url}' returned ` + `a status code of '${response.status}' and won't be cached as a ` + `result.`);
1505
+ }
1506
+ }
1507
+ }
1508
+ responseToCache = responseToCache.ok ? responseToCache : null;
1509
+ }
1510
+
1511
+ return responseToCache ? responseToCache : null;
1512
+ });
1513
+
1514
+ return function _isResponseSafeToCache(_x7, _x8, _x9) {
1515
+ return _ref3.apply(this, arguments);
1516
+ };
1517
+ })();
1518
+
1519
+ const cacheWrapper = {
1520
+ put: putWrapper,
1521
+ match: matchWrapper
1522
+ };
1523
+
1524
+ /*
1525
+ Copyright 2017 Google Inc.
1526
+
1527
+ Licensed under the Apache License, Version 2.0 (the "License");
1528
+ you may not use this file except in compliance with the License.
1529
+ You may obtain a copy of the License at
1530
+
1531
+ https://www.apache.org/licenses/LICENSE-2.0
1532
+
1533
+ Unless required by applicable law or agreed to in writing, software
1534
+ distributed under the License is distributed on an "AS IS" BASIS,
1535
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1536
+ See the License for the specific language governing permissions and
1537
+ limitations under the License.
1538
+ */
1539
+
1540
+ /**
1541
+ * Wrapper around the fetch API.
1542
+ *
1543
+ * Will call requestWillFetch on available plugins.
1544
+ *
1545
+ * @param {Request|string} request
1546
+ * @param {Object} fetchOptions
1547
+ * @param {Array<Object>} [plugins]
1548
+ * @return {Promise<Response>}
1549
+ *
1550
+ * @private
1551
+ * @memberof module:workbox-core
1552
+ */
1553
+ const wrappedFetch = (() => {
1554
+ var _ref = babelHelpers.asyncToGenerator(function* (request, fetchOptions, plugins = []) {
1555
+ if (typeof request === 'string') {
1556
+ request = new Request(request);
1557
+ }
1558
+
1559
+ {
1560
+ finalAssertExports.isInstance(request, Request, {
1561
+ paramName: request,
1562
+ expectedClass: 'Request',
1563
+ moduleName: 'workbox-core',
1564
+ className: 'fetchWrapper',
1565
+ funcName: 'wrappedFetch'
1566
+ });
1567
+ }
1568
+
1569
+ const failedFetchPlugins = pluginUtils.filter(plugins, pluginEvents.FETCH_DID_FAIL);
1570
+
1571
+ // If there is a fetchDidFail plugin, we need to save a clone of the
1572
+ // original request before it's either modified by a requestWillFetch
1573
+ // plugin or before the original request's body is consumed via fetch().
1574
+ const originalRequest = failedFetchPlugins.length > 0 ? request.clone() : null;
1575
+
1576
+ try {
1577
+ for (let plugin of plugins) {
1578
+ if (pluginEvents.REQUEST_WILL_FETCH in plugin) {
1579
+ request = yield plugin[pluginEvents.REQUEST_WILL_FETCH].call(plugin, {
1580
+ request: request.clone()
1581
+ });
1582
+
1583
+ {
1584
+ if (request) {
1585
+ finalAssertExports.isInstance(request, Request, {
1586
+ moduleName: 'Plugin',
1587
+ funcName: pluginEvents.CACHED_RESPONSE_WILL_BE_USED,
1588
+ isReturnValueProblem: true
1589
+ });
1590
+ }
1591
+ }
1592
+ }
1593
+ }
1594
+ } catch (err) {
1595
+ throw new WorkboxError('plugin-error-request-will-fetch', {
1596
+ thrownError: err
1597
+ });
1598
+ }
1599
+
1600
+ // The request can be altered by plugins with `requestWillFetch` making
1601
+ // the original request (Most likely from a `fetch` event) to be different
1602
+ // to the Request we make. Pass both to `fetchDidFail` to aid debugging.
1603
+ const pluginFilteredRequest = request.clone();
1604
+
1605
+ try {
1606
+ const response = yield fetch(request, fetchOptions);
1607
+ {
1608
+ defaultExport.debug(`Network request for ` + `'${getFriendlyURL(request.url)}' returned a response with ` + `status '${response.status}'.`);
1609
+ }
1610
+ return response;
1611
+ } catch (error) {
1612
+ {
1613
+ defaultExport.error(`Network request for ` + `'${getFriendlyURL(request.url)}' threw an error.`, error);
1614
+ }
1615
+
1616
+ for (let plugin of failedFetchPlugins) {
1617
+ yield plugin[pluginEvents.FETCH_DID_FAIL].call(plugin, {
1618
+ error,
1619
+ originalRequest: originalRequest.clone(),
1620
+ request: pluginFilteredRequest.clone()
1621
+ });
1622
+ }
1623
+
1624
+ throw error;
1625
+ }
1626
+ });
1627
+
1628
+ return function wrappedFetch(_x, _x2) {
1629
+ return _ref.apply(this, arguments);
1630
+ };
1631
+ })();
1632
+
1633
+ const fetchWrapper = {
1634
+ fetch: wrappedFetch
1635
+ };
1636
+
1637
+ /*
1638
+ Copyright 2017 Google Inc.
1639
+
1640
+ Licensed under the Apache License, Version 2.0 (the "License");
1641
+ you may not use this file except in compliance with the License.
1642
+ You may obtain a copy of the License at
1643
+
1644
+ https://www.apache.org/licenses/LICENSE-2.0
1645
+
1646
+ Unless required by applicable law or agreed to in writing, software
1647
+ distributed under the License is distributed on an "AS IS" BASIS,
1648
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1649
+ See the License for the specific language governing permissions and
1650
+ limitations under the License.
1651
+ */
1652
+
1653
+ var _private = /*#__PURE__*/Object.freeze({
1654
+ DBWrapper: DBWrapper,
1655
+ WorkboxError: WorkboxError,
1656
+ assert: finalAssertExports,
1657
+ cacheNames: cacheNames,
1658
+ cacheWrapper: cacheWrapper,
1659
+ fetchWrapper: fetchWrapper,
1660
+ getFriendlyURL: getFriendlyURL,
1661
+ logger: defaultExport,
1662
+ registerQuotaErrorCallback: registerQuotaErrorCallback
1663
+ });
1664
+
1665
+ /*
1666
+ Copyright 2017 Google Inc.
1667
+
1668
+ Licensed under the Apache License, Version 2.0 (the "License");
1669
+ you may not use this file except in compliance with the License.
1670
+ You may obtain a copy of the License at
1671
+
1672
+ https://www.apache.org/licenses/LICENSE-2.0
1673
+
1674
+ Unless required by applicable law or agreed to in writing, software
1675
+ distributed under the License is distributed on an "AS IS" BASIS,
1676
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1677
+ See the License for the specific language governing permissions and
1678
+ limitations under the License.
1679
+ */
1680
+
1681
+ const finalExports = Object.assign(defaultExport$1, {
1682
+ LOG_LEVELS,
1683
+ _private
1684
+ });
1685
+
1686
+ return finalExports;
1687
+
1688
+ }());
1689
+
1690
+ //# sourceMappingURL=workbox-core.dev.js.map