jekyll-pwa-plugin 2.2.3 → 5.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +5 -5
  2. data/lib/jekyll-pwa-plugin.rb +11 -3
  3. data/lib/vendor/workbox-v5.1.4/workbox-background-sync.dev.js +818 -0
  4. data/lib/vendor/workbox-v5.1.4/workbox-background-sync.dev.js.map +1 -0
  5. data/lib/vendor/workbox-v5.1.4/workbox-background-sync.prod.js +2 -0
  6. data/lib/vendor/workbox-v5.1.4/workbox-background-sync.prod.js.map +1 -0
  7. data/lib/vendor/workbox-v5.1.4/workbox-broadcast-update.dev.js +288 -0
  8. data/lib/vendor/workbox-v5.1.4/workbox-broadcast-update.dev.js.map +1 -0
  9. data/lib/vendor/workbox-v5.1.4/workbox-broadcast-update.prod.js +2 -0
  10. data/lib/vendor/workbox-v5.1.4/workbox-broadcast-update.prod.js.map +1 -0
  11. data/lib/vendor/workbox-v5.1.4/workbox-cacheable-response.dev.js +191 -0
  12. data/lib/vendor/workbox-v5.1.4/workbox-cacheable-response.dev.js.map +1 -0
  13. data/lib/vendor/workbox-v5.1.4/workbox-cacheable-response.prod.js +2 -0
  14. data/lib/vendor/workbox-v5.1.4/workbox-cacheable-response.prod.js.map +1 -0
  15. data/lib/vendor/workbox-v5.1.4/workbox-core.dev.js +1858 -0
  16. data/lib/vendor/workbox-v5.1.4/workbox-core.dev.js.map +1 -0
  17. data/lib/vendor/workbox-v5.1.4/workbox-core.prod.js +2 -0
  18. data/lib/vendor/workbox-v5.1.4/workbox-core.prod.js.map +1 -0
  19. data/lib/vendor/workbox-v5.1.4/workbox-expiration.dev.js +649 -0
  20. data/lib/vendor/workbox-v5.1.4/workbox-expiration.dev.js.map +1 -0
  21. data/lib/vendor/workbox-v5.1.4/workbox-expiration.prod.js +2 -0
  22. data/lib/vendor/workbox-v5.1.4/workbox-expiration.prod.js.map +1 -0
  23. data/lib/vendor/workbox-v5.1.4/workbox-navigation-preload.dev.js +102 -0
  24. data/lib/vendor/workbox-v5.1.4/workbox-navigation-preload.dev.js.map +1 -0
  25. data/lib/vendor/workbox-v5.1.4/workbox-navigation-preload.prod.js +2 -0
  26. data/lib/vendor/workbox-v5.1.4/workbox-navigation-preload.prod.js.map +1 -0
  27. data/lib/vendor/workbox-v5.1.4/workbox-offline-ga.dev.js +235 -0
  28. data/lib/vendor/workbox-v5.1.4/workbox-offline-ga.dev.js.map +1 -0
  29. data/lib/vendor/workbox-v5.1.4/workbox-offline-ga.prod.js +2 -0
  30. data/lib/vendor/workbox-v5.1.4/workbox-offline-ga.prod.js.map +1 -0
  31. data/lib/vendor/workbox-v5.1.4/workbox-precaching.dev.js +1210 -0
  32. data/lib/vendor/workbox-v5.1.4/workbox-precaching.dev.js.map +1 -0
  33. data/lib/vendor/workbox-v5.1.4/workbox-precaching.prod.js +2 -0
  34. data/lib/vendor/workbox-v5.1.4/workbox-precaching.prod.js.map +1 -0
  35. data/lib/vendor/workbox-v5.1.4/workbox-range-requests.dev.js +262 -0
  36. data/lib/vendor/workbox-v5.1.4/workbox-range-requests.dev.js.map +1 -0
  37. data/lib/vendor/workbox-v5.1.4/workbox-range-requests.prod.js +2 -0
  38. data/lib/vendor/workbox-v5.1.4/workbox-range-requests.prod.js.map +1 -0
  39. data/lib/vendor/workbox-v5.1.4/workbox-routing.dev.js +923 -0
  40. data/lib/vendor/workbox-v5.1.4/workbox-routing.dev.js.map +1 -0
  41. data/lib/vendor/workbox-v5.1.4/workbox-routing.prod.js +2 -0
  42. data/lib/vendor/workbox-v5.1.4/workbox-routing.prod.js.map +1 -0
  43. data/lib/vendor/workbox-v5.1.4/workbox-strategies.dev.js +923 -0
  44. data/lib/vendor/workbox-v5.1.4/workbox-strategies.dev.js.map +1 -0
  45. data/lib/vendor/workbox-v5.1.4/workbox-strategies.prod.js +2 -0
  46. data/lib/vendor/workbox-v5.1.4/workbox-strategies.prod.js.map +1 -0
  47. data/lib/vendor/workbox-v5.1.4/workbox-streams.dev.js +318 -0
  48. data/lib/vendor/workbox-v5.1.4/workbox-streams.dev.js.map +1 -0
  49. data/lib/vendor/workbox-v5.1.4/workbox-streams.prod.js +2 -0
  50. data/lib/vendor/workbox-v5.1.4/workbox-streams.prod.js.map +1 -0
  51. data/lib/vendor/workbox-v5.1.4/workbox-sw.js +2 -0
  52. data/lib/vendor/workbox-v5.1.4/workbox-sw.js.map +1 -0
  53. data/lib/vendor/workbox-v5.1.4/workbox-window.dev.es5.mjs +1125 -0
  54. data/lib/vendor/workbox-v5.1.4/workbox-window.dev.es5.mjs.map +1 -0
  55. data/lib/vendor/workbox-v5.1.4/workbox-window.dev.mjs +943 -0
  56. data/lib/vendor/workbox-v5.1.4/workbox-window.dev.mjs.map +1 -0
  57. data/lib/vendor/workbox-v5.1.4/workbox-window.dev.umd.js +1136 -0
  58. data/lib/vendor/workbox-v5.1.4/workbox-window.dev.umd.js.map +1 -0
  59. data/lib/vendor/workbox-v5.1.4/workbox-window.prod.es5.mjs +2 -0
  60. data/lib/vendor/workbox-v5.1.4/workbox-window.prod.es5.mjs.map +1 -0
  61. data/lib/vendor/workbox-v5.1.4/workbox-window.prod.mjs +2 -0
  62. data/lib/vendor/workbox-v5.1.4/workbox-window.prod.mjs.map +1 -0
  63. data/lib/vendor/workbox-v5.1.4/workbox-window.prod.umd.js +2 -0
  64. data/lib/vendor/workbox-v5.1.4/workbox-window.prod.umd.js.map +1 -0
  65. metadata +65 -55
  66. data/lib/vendor/workbox-v3.6.3/workbox-background-sync.dev.js +0 -593
  67. data/lib/vendor/workbox-v3.6.3/workbox-background-sync.dev.js.map +0 -1
  68. data/lib/vendor/workbox-v3.6.3/workbox-background-sync.prod.js +0 -3
  69. data/lib/vendor/workbox-v3.6.3/workbox-background-sync.prod.js.map +0 -1
  70. data/lib/vendor/workbox-v3.6.3/workbox-broadcast-cache-update.dev.js +0 -395
  71. data/lib/vendor/workbox-v3.6.3/workbox-broadcast-cache-update.dev.js.map +0 -1
  72. data/lib/vendor/workbox-v3.6.3/workbox-broadcast-cache-update.prod.js +0 -3
  73. data/lib/vendor/workbox-v3.6.3/workbox-broadcast-cache-update.prod.js.map +0 -1
  74. data/lib/vendor/workbox-v3.6.3/workbox-cache-expiration.dev.js +0 -740
  75. data/lib/vendor/workbox-v3.6.3/workbox-cache-expiration.dev.js.map +0 -1
  76. data/lib/vendor/workbox-v3.6.3/workbox-cache-expiration.prod.js +0 -3
  77. data/lib/vendor/workbox-v3.6.3/workbox-cache-expiration.prod.js.map +0 -1
  78. data/lib/vendor/workbox-v3.6.3/workbox-cacheable-response.dev.js +0 -236
  79. data/lib/vendor/workbox-v3.6.3/workbox-cacheable-response.dev.js.map +0 -1
  80. data/lib/vendor/workbox-v3.6.3/workbox-cacheable-response.prod.js +0 -3
  81. data/lib/vendor/workbox-v3.6.3/workbox-cacheable-response.prod.js.map +0 -1
  82. data/lib/vendor/workbox-v3.6.3/workbox-core.dev.js +0 -1736
  83. data/lib/vendor/workbox-v3.6.3/workbox-core.dev.js.map +0 -1
  84. data/lib/vendor/workbox-v3.6.3/workbox-core.prod.js +0 -3
  85. data/lib/vendor/workbox-v3.6.3/workbox-core.prod.js.map +0 -1
  86. data/lib/vendor/workbox-v3.6.3/workbox-google-analytics.dev.js +0 -255
  87. data/lib/vendor/workbox-v3.6.3/workbox-google-analytics.dev.js.map +0 -1
  88. data/lib/vendor/workbox-v3.6.3/workbox-google-analytics.prod.js +0 -3
  89. data/lib/vendor/workbox-v3.6.3/workbox-google-analytics.prod.js.map +0 -1
  90. data/lib/vendor/workbox-v3.6.3/workbox-navigation-preload.dev.js +0 -159
  91. data/lib/vendor/workbox-v3.6.3/workbox-navigation-preload.dev.js.map +0 -1
  92. data/lib/vendor/workbox-v3.6.3/workbox-navigation-preload.prod.js +0 -3
  93. data/lib/vendor/workbox-v3.6.3/workbox-navigation-preload.prod.js.map +0 -1
  94. data/lib/vendor/workbox-v3.6.3/workbox-precaching.dev.js +0 -1171
  95. data/lib/vendor/workbox-v3.6.3/workbox-precaching.dev.js.map +0 -1
  96. data/lib/vendor/workbox-v3.6.3/workbox-precaching.prod.js +0 -3
  97. data/lib/vendor/workbox-v3.6.3/workbox-precaching.prod.js.map +0 -1
  98. data/lib/vendor/workbox-v3.6.3/workbox-range-requests.dev.js +0 -299
  99. data/lib/vendor/workbox-v3.6.3/workbox-range-requests.dev.js.map +0 -1
  100. data/lib/vendor/workbox-v3.6.3/workbox-range-requests.prod.js +0 -3
  101. data/lib/vendor/workbox-v3.6.3/workbox-range-requests.prod.js.map +0 -1
  102. data/lib/vendor/workbox-v3.6.3/workbox-routing.dev.js +0 -863
  103. data/lib/vendor/workbox-v3.6.3/workbox-routing.dev.js.map +0 -1
  104. data/lib/vendor/workbox-v3.6.3/workbox-routing.prod.js +0 -3
  105. data/lib/vendor/workbox-v3.6.3/workbox-routing.prod.js.map +0 -1
  106. data/lib/vendor/workbox-v3.6.3/workbox-strategies.dev.js +0 -1172
  107. data/lib/vendor/workbox-v3.6.3/workbox-strategies.dev.js.map +0 -1
  108. data/lib/vendor/workbox-v3.6.3/workbox-strategies.prod.js +0 -3
  109. data/lib/vendor/workbox-v3.6.3/workbox-strategies.prod.js.map +0 -1
  110. data/lib/vendor/workbox-v3.6.3/workbox-streams.dev.js +0 -380
  111. data/lib/vendor/workbox-v3.6.3/workbox-streams.dev.js.map +0 -1
  112. data/lib/vendor/workbox-v3.6.3/workbox-streams.prod.js +0 -3
  113. data/lib/vendor/workbox-v3.6.3/workbox-streams.prod.js.map +0 -1
  114. data/lib/vendor/workbox-v3.6.3/workbox-sw.js +0 -3
  115. data/lib/vendor/workbox-v3.6.3/workbox-sw.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"mappings":"","sources":["packages/workbox-background-sync/browser.mjs"],"sourcesContent":["this.workbox = this.workbox || {};\nthis.workbox.backgroundSync = (function (DBWrapper_mjs,WorkboxError_mjs,logger_mjs,assert_mjs,getFriendlyURL_mjs) {\n 'use strict';\n\n try {\n self.workbox.v['workbox:background-sync:3.6.3'] = 1;\n } catch (e) {} // eslint-disable-line\n\n /*\n Copyright 2017 Google Inc. All Rights Reserved.\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n */\n\n const serializableProperties = ['method', 'referrer', 'referrerPolicy', 'mode', 'credentials', 'cache', 'redirect', 'integrity', 'keepalive'];\n\n /**\n * A class to make it easier to serialize and de-serialize requests so they\n * can be stored in IndexedDB.\n *\n * @private\n */\n class StorableRequest {\n /**\n * Converts a Request object to a plain object that can be structured\n * cloned or JSON-stringified.\n *\n * @param {Request} request\n * @return {Promise<StorableRequest>}\n *\n * @private\n */\n static fromRequest(request) {\n return babelHelpers.asyncToGenerator(function* () {\n const requestInit = { headers: {} };\n\n // Set the body if present.\n if (request.method !== 'GET') {\n // Use blob to support non-text request bodies,\n // and clone first in case the caller still needs the request.\n requestInit.body = yield request.clone().blob();\n }\n\n // Convert the headers from an iterable to an object.\n for (const [key, value] of request.headers.entries()) {\n requestInit.headers[key] = value;\n }\n\n // Add all other serializable request properties\n for (const prop of serializableProperties) {\n if (request[prop] !== undefined) {\n requestInit[prop] = request[prop];\n }\n }\n\n return new StorableRequest({ url: request.url, requestInit });\n })();\n }\n\n /**\n * Accepts a URL and RequestInit dictionary that can be used to create a\n * new Request object. A timestamp is also generated so consumers can\n * reference when the object was created.\n *\n * @param {Object} param1\n * @param {string} param1.url\n * @param {Object} param1.requestInit\n * See: https://fetch.spec.whatwg.org/#requestinit\n * @param {number} param1.timestamp The time the request was created,\n * defaulting to the current time if not specified.\n *\n * @private\n */\n constructor({ url, requestInit, timestamp = Date.now() }) {\n this.url = url;\n this.requestInit = requestInit;\n\n // \"Private\"\n this._timestamp = timestamp;\n }\n\n /**\n * Gets the private _timestamp property.\n *\n * @return {number}\n *\n * @private\n */\n get timestamp() {\n return this._timestamp;\n }\n\n /**\n * Coverts this instance to a plain Object.\n *\n * @return {Object}\n *\n * @private\n */\n toObject() {\n return {\n url: this.url,\n timestamp: this.timestamp,\n requestInit: this.requestInit\n };\n }\n\n /**\n * Converts this instance to a Request.\n *\n * @return {Request}\n *\n * @private\n */\n toRequest() {\n return new Request(this.url, this.requestInit);\n }\n\n /**\n * Creates and returns a deep clone of the instance.\n *\n * @return {StorableRequest}\n *\n * @private\n */\n clone() {\n const requestInit = Object.assign({}, this.requestInit);\n requestInit.headers = Object.assign({}, this.requestInit.headers);\n if (this.requestInit.body) {\n requestInit.body = this.requestInit.body.slice();\n }\n\n return new StorableRequest({\n url: this.url,\n timestamp: this.timestamp,\n requestInit\n });\n }\n }\n\n /*\n Copyright 2017 Google Inc. All Rights Reserved.\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n */\n\n const DB_NAME = 'workbox-background-sync';\n const OBJECT_STORE_NAME = 'requests';\n const INDEXED_PROP = 'queueName';\n const TAG_PREFIX = 'workbox-background-sync';\n const MAX_RETENTION_TIME = 60 * 24 * 7; // 7 days in minutes\n\n /*\n Copyright 2017 Google Inc. All Rights Reserved.\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n */\n\n /**\n * A class to manage storing requests from a Queue in IndexedbDB,\n * indexed by their queue name for easier access.\n *\n * @private\n */\n class QueueStore {\n /**\n * Associates this instance with a Queue instance, so entries added can be\n * identified by their queue name.\n *\n * @param {Queue} queue\n *\n * @private\n */\n constructor(queue) {\n this._queue = queue;\n this._db = new DBWrapper_mjs.DBWrapper(DB_NAME, 1, {\n onupgradeneeded: evt => evt.target.result.createObjectStore(OBJECT_STORE_NAME, { autoIncrement: true }).createIndex(INDEXED_PROP, INDEXED_PROP, { unique: false })\n });\n }\n\n /**\n * Takes a StorableRequest instance, converts it to an object and adds it\n * as an entry in the object store.\n *\n * @param {StorableRequest} storableRequest\n *\n * @private\n */\n addEntry(storableRequest) {\n var _this = this;\n\n return babelHelpers.asyncToGenerator(function* () {\n yield _this._db.add(OBJECT_STORE_NAME, {\n queueName: _this._queue.name,\n storableRequest: storableRequest.toObject()\n });\n })();\n }\n\n /**\n * Gets the oldest entry in the object store, removes it, and returns the\n * value as a StorableRequest instance. If no entry exists, it returns\n * undefined.\n *\n * @return {StorableRequest|undefined}\n *\n * @private\n */\n getAndRemoveOldestEntry() {\n var _this2 = this;\n\n return babelHelpers.asyncToGenerator(function* () {\n const [entry] = yield _this2._db.getAllMatching(OBJECT_STORE_NAME, {\n index: INDEXED_PROP,\n query: IDBKeyRange.only(_this2._queue.name),\n count: 1,\n includeKeys: true\n });\n\n if (entry) {\n yield _this2._db.delete(OBJECT_STORE_NAME, entry.primaryKey);\n return new StorableRequest(entry.value.storableRequest);\n }\n })();\n }\n }\n\n /*\n Copyright 2017 Google Inc. All Rights Reserved.\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n */\n\n const queueNames = new Set();\n\n /**\n * A class to manage storing failed requests in IndexedDB and retrying them\n * later. All parts of the storing and replaying process are observable via\n * callbacks.\n *\n * @memberof workbox.backgroundSync\n */\n class Queue {\n /**\n * Creates an instance of Queue with the given options\n *\n * @param {string} name The unique name for this queue. This name must be\n * unique as it's used to register sync events and store requests\n * in IndexedDB specific to this instance. An error will be thrown if\n * a duplicate name is detected.\n * @param {Object} [options]\n * @param {Object} [options.callbacks] Callbacks to observe the lifecycle of\n * queued requests. Use these to respond to or modify the requests\n * during the replay process.\n * @param {function(StorableRequest):undefined}\n * [options.callbacks.requestWillEnqueue]\n * Invoked immediately before the request is stored to IndexedDB. Use\n * this callback to modify request data at store time.\n * @param {function(StorableRequest):undefined}\n * [options.callbacks.requestWillReplay]\n * Invoked immediately before the request is re-fetched. Use this\n * callback to modify request data at fetch time.\n * @param {function(Array<StorableRequest>):undefined}\n * [options.callbacks.queueDidReplay]\n * Invoked after all requests in the queue have successfully replayed.\n * @param {number} [options.maxRetentionTime = 7 days] The amount of time (in\n * minutes) a request may be retried. After this amount of time has\n * passed, the request will be deleted from the queue.\n */\n constructor(name, {\n callbacks = {},\n maxRetentionTime = MAX_RETENTION_TIME\n } = {}) {\n // Ensure the store name is not already being used\n if (queueNames.has(name)) {\n throw new WorkboxError_mjs.WorkboxError('duplicate-queue-name', { name });\n } else {\n queueNames.add(name);\n }\n\n this._name = name;\n this._callbacks = callbacks;\n this._maxRetentionTime = maxRetentionTime;\n this._queueStore = new QueueStore(this);\n\n this._addSyncListener();\n }\n\n /**\n * @return {string}\n */\n get name() {\n return this._name;\n }\n\n /**\n * Stores the passed request into IndexedDB. The database used is\n * `workbox-background-sync` and the object store name is the same as\n * the name this instance was created with (to guarantee it's unique).\n *\n * @param {Request} request The request object to store.\n */\n addRequest(request) {\n var _this = this;\n\n return babelHelpers.asyncToGenerator(function* () {\n {\n assert_mjs.assert.isInstance(request, Request, {\n moduleName: 'workbox-background-sync',\n className: 'Queue',\n funcName: 'addRequest',\n paramName: 'request'\n });\n }\n\n const storableRequest = yield StorableRequest.fromRequest(request.clone());\n yield _this._runCallback('requestWillEnqueue', storableRequest);\n yield _this._queueStore.addEntry(storableRequest);\n yield _this._registerSync();\n {\n logger_mjs.logger.log(`Request for '${getFriendlyURL_mjs.getFriendlyURL(storableRequest.url)}' has been\n added to background sync queue '${_this._name}'.`);\n }\n })();\n }\n\n /**\n * Retrieves all stored requests in IndexedDB and retries them. If the\n * queue contained requests that were successfully replayed, the\n * `queueDidReplay` callback is invoked (which implies the queue is\n * now empty). If any of the requests fail, a new sync registration is\n * created to retry again later.\n */\n replayRequests() {\n var _this2 = this;\n\n return babelHelpers.asyncToGenerator(function* () {\n const now = Date.now();\n const replayedRequests = [];\n const failedRequests = [];\n\n let storableRequest;\n while (storableRequest = yield _this2._queueStore.getAndRemoveOldestEntry()) {\n // Make a copy so the unmodified request can be stored\n // in the event of a replay failure.\n const storableRequestClone = storableRequest.clone();\n\n // Ignore requests older than maxRetentionTime.\n const maxRetentionTimeInMs = _this2._maxRetentionTime * 60 * 1000;\n if (now - storableRequest.timestamp > maxRetentionTimeInMs) {\n continue;\n }\n\n yield _this2._runCallback('requestWillReplay', storableRequest);\n\n const replay = { request: storableRequest.toRequest() };\n\n try {\n // Clone the request before fetching so callbacks get an unused one.\n replay.response = yield fetch(replay.request.clone());\n {\n logger_mjs.logger.log(`Request for '${getFriendlyURL_mjs.getFriendlyURL(storableRequest.url)}'\n has been replayed`);\n }\n } catch (err) {\n {\n logger_mjs.logger.log(`Request for '${getFriendlyURL_mjs.getFriendlyURL(storableRequest.url)}'\n failed to replay`);\n }\n replay.error = err;\n failedRequests.push(storableRequestClone);\n }\n\n replayedRequests.push(replay);\n }\n\n yield _this2._runCallback('queueDidReplay', replayedRequests);\n\n // If any requests failed, put the failed requests back in the queue\n // and rethrow the failed requests count.\n if (failedRequests.length) {\n yield Promise.all(failedRequests.map(function (storableRequest) {\n return _this2._queueStore.addEntry(storableRequest);\n }));\n\n throw new WorkboxError_mjs.WorkboxError('queue-replay-failed', { name: _this2._name, count: failedRequests.length });\n }\n })();\n }\n\n /**\n * Runs the passed callback if it exists.\n *\n * @private\n * @param {string} name The name of the callback on this._callbacks.\n * @param {...*} args The arguments to invoke the callback with.\n */\n _runCallback(name, ...args) {\n var _this3 = this;\n\n return babelHelpers.asyncToGenerator(function* () {\n if (typeof _this3._callbacks[name] === 'function') {\n yield _this3._callbacks[name].apply(null, args);\n }\n })();\n }\n\n /**\n * In sync-supporting browsers, this adds a listener for the sync event.\n * In non-sync-supporting browsers, this will retry the queue on service\n * worker startup.\n *\n * @private\n */\n _addSyncListener() {\n if ('sync' in registration) {\n self.addEventListener('sync', event => {\n if (event.tag === `${TAG_PREFIX}:${this._name}`) {\n {\n logger_mjs.logger.log(`Background sync for tag '${event.tag}'\n has been received, starting replay now`);\n }\n event.waitUntil(this.replayRequests());\n }\n });\n } else {\n {\n logger_mjs.logger.log(`Background sync replaying without background sync event`);\n }\n // If the browser doesn't support background sync, retry\n // every time the service worker starts up as a fallback.\n this.replayRequests();\n }\n }\n\n /**\n * Registers a sync event with a tag unique to this instance.\n *\n * @private\n */\n _registerSync() {\n var _this4 = this;\n\n return babelHelpers.asyncToGenerator(function* () {\n if ('sync' in registration) {\n try {\n yield registration.sync.register(`${TAG_PREFIX}:${_this4._name}`);\n } catch (err) {\n // This means the registration failed for some reason, possibly due to\n // the user disabling it.\n {\n logger_mjs.logger.warn(`Unable to register sync event for '${_this4._name}'.`, err);\n }\n }\n }\n })();\n }\n\n /**\n * Returns the set of queue names. This is primarily used to reset the list\n * of queue names in tests.\n *\n * @return {Set}\n *\n * @private\n */\n static get _queueNames() {\n return queueNames;\n }\n }\n\n /*\n Copyright 2017 Google Inc. All Rights Reserved.\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n */\n\n /**\n * A class implementing the `fetchDidFail` lifecycle callback. This makes it\n * easier to add failed requests to a background sync Queue.\n *\n * @memberof workbox.backgroundSync\n */\n class Plugin {\n /**\n * @param {...*} queueArgs Args to forward to the composed Queue instance.\n * See the [Queue]{@link workbox.backgroundSync.Queue} documentation for\n * parameter details.\n */\n constructor(...queueArgs) {\n this._queue = new Queue(...queueArgs);\n this.fetchDidFail = this.fetchDidFail.bind(this);\n }\n\n /**\n * @param {Object} options\n * @param {Request} options.request\n * @private\n */\n fetchDidFail({ request }) {\n var _this = this;\n\n return babelHelpers.asyncToGenerator(function* () {\n yield _this._queue.addRequest(request);\n })();\n }\n }\n\n /*\n Copyright 2017 Google Inc. All Rights Reserved.\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n */\n\n var publicAPI = /*#__PURE__*/Object.freeze({\n Queue: Queue,\n Plugin: Plugin\n });\n\n /*\n Copyright 2017 Google Inc. All Rights Reserved.\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n */\n\n return publicAPI;\n\n}(workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private));\n"],"file":"workbox-background-sync.dev.js"}
@@ -1,3 +0,0 @@
1
- this.workbox=this.workbox||{},this.workbox.backgroundSync=function(e,t){"use strict";try{self.workbox.v["workbox:background-sync:3.6.3"]=1}catch(e){}const r=["method","referrer","referrerPolicy","mode","credentials","cache","redirect","integrity","keepalive"];class s{static fromRequest(e){return babelHelpers.asyncToGenerator(function*(){const t={headers:{}};"GET"!==e.method&&(t.body=yield e.clone().blob());for(const[r,s]of e.headers.entries())t.headers[r]=s;for(const s of r)void 0!==e[s]&&(t[s]=e[s]);return new s({url:e.url,requestInit:t})})()}constructor({url:e,requestInit:t,timestamp:r=Date.now()}){this.url=e,this.requestInit=t,this.e=r}get timestamp(){return this.e}toObject(){return{url:this.url,timestamp:this.timestamp,requestInit:this.requestInit}}toRequest(){return new Request(this.url,this.requestInit)}clone(){const e=Object.assign({},this.requestInit);return e.headers=Object.assign({},this.requestInit.headers),this.requestInit.body&&(e.body=this.requestInit.body.slice()),new s({url:this.url,timestamp:this.timestamp,requestInit:e})}}const i="workbox-background-sync",n="requests",u="queueName",c="workbox-background-sync",o=10080;class l{constructor(t){this.t=t,this.r=new e.DBWrapper(i,1,{onupgradeneeded:e=>e.target.result.createObjectStore(n,{autoIncrement:!0}).createIndex(u,u,{unique:!1})})}addEntry(e){var t=this;return babelHelpers.asyncToGenerator(function*(){yield t.r.add(n,{queueName:t.t.name,storableRequest:e.toObject()})})()}getAndRemoveOldestEntry(){var e=this;return babelHelpers.asyncToGenerator(function*(){const[t]=yield e.r.getAllMatching(n,{index:u,query:IDBKeyRange.only(e.t.name),count:1,includeKeys:!0});if(t)return yield e.r.delete(n,t.primaryKey),new s(t.value.storableRequest)})()}}const a=new Set;class h{constructor(e,{callbacks:r={},maxRetentionTime:s=o}={}){if(a.has(e))throw new t.WorkboxError("duplicate-queue-name",{name:e});a.add(e),this.s=e,this.i=r,this.n=s,this.u=new l(this),this.c()}get name(){return this.s}addRequest(e){var t=this;return babelHelpers.asyncToGenerator(function*(){const r=yield s.fromRequest(e.clone());yield t.o("requestWillEnqueue",r),yield t.u.addEntry(r),yield t.l()})()}replayRequests(){var e=this;return babelHelpers.asyncToGenerator(function*(){const r=Date.now(),s=[],i=[];let n;for(;n=yield e.u.getAndRemoveOldestEntry();){const t=n.clone(),u=60*e.n*1e3;if(r-n.timestamp>u)continue;yield e.o("requestWillReplay",n);const c={request:n.toRequest()};try{c.response=yield fetch(c.request.clone())}catch(e){c.error=e,i.push(t)}s.push(c)}if(yield e.o("queueDidReplay",s),i.length)throw yield Promise.all(i.map(function(t){return e.u.addEntry(t)})),new t.WorkboxError("queue-replay-failed",{name:e.s,count:i.length})})()}o(e,...t){var r=this;return babelHelpers.asyncToGenerator(function*(){"function"==typeof r.i[e]&&(yield r.i[e].apply(null,t))})()}c(){"sync"in registration?self.addEventListener("sync",e=>{e.tag===`${c}:${this.s}`&&e.waitUntil(this.replayRequests())}):this.replayRequests()}l(){var e=this;return babelHelpers.asyncToGenerator(function*(){if("sync"in registration)try{yield registration.sync.register(`${c}:${e.s}`)}catch(e){}})()}static get a(){return a}}return Object.freeze({Queue:h,Plugin:class{constructor(...e){this.t=new h(...e),this.fetchDidFail=this.fetchDidFail.bind(this)}fetchDidFail({request:e}){var t=this;return babelHelpers.asyncToGenerator(function*(){yield t.t.addRequest(e)})()}}})}(workbox.core._private,workbox.core._private);
2
-
3
- //# sourceMappingURL=workbox-background-sync.prod.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"mappings":"","sources":["packages/workbox-background-sync/browser.mjs"],"sourcesContent":["this.workbox=this.workbox||{},this.workbox.backgroundSync=function(e,t){\"use strict\";try{self.workbox.v[\"workbox:background-sync:3.6.3\"]=1}catch(e){}const r=[\"method\",\"referrer\",\"referrerPolicy\",\"mode\",\"credentials\",\"cache\",\"redirect\",\"integrity\",\"keepalive\"];class s{static fromRequest(e){return babelHelpers.asyncToGenerator(function*(){const t={headers:{}};\"GET\"!==e.method&&(t.body=yield e.clone().blob());for(const[r,s]of e.headers.entries())t.headers[r]=s;for(const s of r)void 0!==e[s]&&(t[s]=e[s]);return new s({url:e.url,requestInit:t})})()}constructor({url:e,requestInit:t,timestamp:r=Date.now()}){this.url=e,this.requestInit=t,this.e=r}get timestamp(){return this.e}toObject(){return{url:this.url,timestamp:this.timestamp,requestInit:this.requestInit}}toRequest(){return new Request(this.url,this.requestInit)}clone(){const e=Object.assign({},this.requestInit);return e.headers=Object.assign({},this.requestInit.headers),this.requestInit.body&&(e.body=this.requestInit.body.slice()),new s({url:this.url,timestamp:this.timestamp,requestInit:e})}}const i=\"workbox-background-sync\",n=\"requests\",u=\"queueName\",c=\"workbox-background-sync\",o=10080;class l{constructor(t){this.t=t,this.r=new e.DBWrapper(i,1,{onupgradeneeded:e=>e.target.result.createObjectStore(n,{autoIncrement:!0}).createIndex(u,u,{unique:!1})})}addEntry(e){var t=this;return babelHelpers.asyncToGenerator(function*(){yield t.r.add(n,{queueName:t.t.name,storableRequest:e.toObject()})})()}getAndRemoveOldestEntry(){var e=this;return babelHelpers.asyncToGenerator(function*(){const[t]=yield e.r.getAllMatching(n,{index:u,query:IDBKeyRange.only(e.t.name),count:1,includeKeys:!0});if(t)return yield e.r.delete(n,t.primaryKey),new s(t.value.storableRequest)})()}}const a=new Set;class h{constructor(e,{callbacks:r={},maxRetentionTime:s=o}={}){if(a.has(e))throw new t.WorkboxError(\"duplicate-queue-name\",{name:e});a.add(e),this.s=e,this.i=r,this.n=s,this.u=new l(this),this.c()}get name(){return this.s}addRequest(e){var t=this;return babelHelpers.asyncToGenerator(function*(){const r=yield s.fromRequest(e.clone());yield t.o(\"requestWillEnqueue\",r),yield t.u.addEntry(r),yield t.l()})()}replayRequests(){var e=this;return babelHelpers.asyncToGenerator(function*(){const r=Date.now(),s=[],i=[];let n;for(;n=yield e.u.getAndRemoveOldestEntry();){const t=n.clone(),u=60*e.n*1e3;if(r-n.timestamp>u)continue;yield e.o(\"requestWillReplay\",n);const c={request:n.toRequest()};try{c.response=yield fetch(c.request.clone())}catch(e){c.error=e,i.push(t)}s.push(c)}if(yield e.o(\"queueDidReplay\",s),i.length)throw yield Promise.all(i.map(function(t){return e.u.addEntry(t)})),new t.WorkboxError(\"queue-replay-failed\",{name:e.s,count:i.length})})()}o(e,...t){var r=this;return babelHelpers.asyncToGenerator(function*(){\"function\"==typeof r.i[e]&&(yield r.i[e].apply(null,t))})()}c(){\"sync\"in registration?self.addEventListener(\"sync\",e=>{e.tag===`${c}:${this.s}`&&e.waitUntil(this.replayRequests())}):this.replayRequests()}l(){var e=this;return babelHelpers.asyncToGenerator(function*(){if(\"sync\"in registration)try{yield registration.sync.register(`${c}:${e.s}`)}catch(e){}})()}static get a(){return a}}return Object.freeze({Queue:h,Plugin:class{constructor(...e){this.t=new h(...e),this.fetchDidFail=this.fetchDidFail.bind(this)}fetchDidFail({request:e}){var t=this;return babelHelpers.asyncToGenerator(function*(){yield t.t.addRequest(e)})()}}})}(workbox.core._private,workbox.core._private);\n"],"file":"workbox-background-sync.prod.js"}
@@ -1,395 +0,0 @@
1
- this.workbox = this.workbox || {};
2
- this.workbox.broadcastUpdate = (function (exports,WorkboxError_mjs,logger_mjs,assert_mjs) {
3
- 'use strict';
4
-
5
- try {
6
- self.workbox.v['workbox:broadcast-cache-update:3.6.3'] = 1;
7
- } catch (e) {} // eslint-disable-line
8
-
9
- /*
10
- Copyright 2016 Google Inc. All Rights Reserved.
11
- Licensed under the Apache License, Version 2.0 (the "License");
12
- you may not use this file except in compliance with the License.
13
- You may obtain a copy of the License at
14
-
15
- http://www.apache.org/licenses/LICENSE-2.0
16
-
17
- Unless required by applicable law or agreed to in writing, software
18
- distributed under the License is distributed on an "AS IS" BASIS,
19
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
- See the License for the specific language governing permissions and
21
- limitations under the License.
22
- */
23
-
24
- /**
25
- * Given two `Response's`, compares several header values to see if they are
26
- * the same or not.
27
- *
28
- * @param {Response} firstResponse
29
- * @param {Response} secondResponse
30
- * @param {Array<string>} headersToCheck
31
- * @return {boolean}
32
- *
33
- * @memberof workbox.broadcastUpdate
34
- * @private
35
- */
36
- const responsesAreSame = (firstResponse, secondResponse, headersToCheck) => {
37
- {
38
- if (!(firstResponse instanceof Response && secondResponse instanceof Response)) {
39
- throw new WorkboxError_mjs.WorkboxError('invalid-responses-are-same-args');
40
- }
41
- }
42
-
43
- const atLeastOneHeaderAvailable = headersToCheck.some(header => {
44
- return firstResponse.headers.has(header) && secondResponse.headers.has(header);
45
- });
46
-
47
- if (!atLeastOneHeaderAvailable) {
48
- {
49
- logger_mjs.logger.warn(`Unable to determine where the response has been updated ` + `because none of the headers that would be checked are present.`);
50
- logger_mjs.logger.debug(`Attempting to compare the following: `, firstResponse, secondResponse, headersToCheck);
51
- }
52
-
53
- // Just return true, indicating the that responses are the same, since we
54
- // can't determine otherwise.
55
- return true;
56
- }
57
-
58
- return headersToCheck.every(header => {
59
- const headerStateComparison = firstResponse.headers.has(header) === secondResponse.headers.has(header);
60
- const headerValueComparison = firstResponse.headers.get(header) === secondResponse.headers.get(header);
61
-
62
- return headerStateComparison && headerValueComparison;
63
- });
64
- };
65
-
66
- /*
67
- Copyright 2016 Google Inc. All Rights Reserved.
68
- Licensed under the Apache License, Version 2.0 (the "License");
69
- you may not use this file except in compliance with the License.
70
- You may obtain a copy of the License at
71
-
72
- http://www.apache.org/licenses/LICENSE-2.0
73
-
74
- Unless required by applicable law or agreed to in writing, software
75
- distributed under the License is distributed on an "AS IS" BASIS,
76
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
77
- See the License for the specific language governing permissions and
78
- limitations under the License.
79
- */
80
-
81
- var messageTypes = {
82
- CACHE_UPDATED: 'CACHE_UPDATED'
83
- };
84
-
85
- /*
86
- Copyright 2016 Google Inc. All Rights Reserved.
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
- http://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
- /**
101
- * You would not normally call this method directly; it's called automatically
102
- * by an instance of the {@link BroadcastCacheUpdate} class. It's exposed here
103
- * for the benefit of developers who would rather not use the full
104
- * `BroadcastCacheUpdate` implementation.
105
- *
106
- * Calling this will dispatch a message on the provided
107
- * {@link https://developers.google.com/web/updates/2016/09/broadcastchannel|Broadcast Channel}
108
- * to notify interested subscribers about a change to a cached resource.
109
- *
110
- * The message that's posted has a formation inspired by the
111
- * [Flux standard action](https://github.com/acdlite/flux-standard-action#introduction)
112
- * format like so:
113
- *
114
- * ```
115
- * {
116
- * type: 'CACHE_UPDATED',
117
- * meta: 'workbox-broadcast-cache-update',
118
- * payload: {
119
- * cacheName: 'the-cache-name',
120
- * updatedUrl: 'https://example.com/'
121
- * }
122
- * }
123
- * ```
124
- *
125
- * (Usage of [Flux](https://facebook.github.io/flux/) itself is not at
126
- * all required.)
127
- *
128
- * @param {BroadcastChannel} channel The `BroadcastChannel` to use.
129
- * @param {string} cacheName The name of the cache in which the updated
130
- * `Response` was stored.
131
- * @param {string} url The URL associated with the updated `Response`.
132
- * @param {string} source A string identifying this library as the source
133
- * of the update message.
134
- *
135
- * @memberof workbox.broadcastUpdate
136
- */
137
- const broadcastUpdate = (channel, cacheName, url, source) => {
138
- // There are browsers which support service workers but don't support the
139
- // Broadcast Channel API.
140
- // See https://github.com/GoogleChrome/workbox/issues/1304
141
- if (!('BroadcastChannel' in self && channel)) {
142
- {
143
- logger_mjs.logger.debug(`${url} was updated, but the Broadcast Channel API is not ` + `available in the current browser.`);
144
- }
145
- return;
146
- }
147
-
148
- {
149
- assert_mjs.assert.isInstance(channel, BroadcastChannel, {
150
- moduleName: 'workbox-broadcast-cache-update',
151
- className: '~',
152
- funcName: 'broadcastUpdate',
153
- paramName: 'channel'
154
- });
155
- assert_mjs.assert.isType(cacheName, 'string', {
156
- moduleName: 'workbox-broadcast-cache-update',
157
- className: '~',
158
- funcName: 'broadcastUpdate',
159
- paramName: 'cacheName'
160
- });
161
- assert_mjs.assert.isType(url, 'string', {
162
- moduleName: 'workbox-broadcast-cache-update',
163
- className: '~',
164
- funcName: 'broadcastUpdate',
165
- paramName: 'url'
166
- });
167
- assert_mjs.assert.isType(source, 'string', {
168
- moduleName: 'workbox-broadcast-cache-update',
169
- className: '~',
170
- funcName: 'broadcastUpdate',
171
- paramName: 'source'
172
- });
173
- }
174
-
175
- channel.postMessage({
176
- type: messageTypes.CACHE_UPDATED,
177
- meta: source,
178
- payload: {
179
- cacheName: cacheName,
180
- updatedUrl: url
181
- }
182
- });
183
- };
184
-
185
- /*
186
- Copyright 2016 Google Inc. All Rights Reserved.
187
- Licensed under the Apache License, Version 2.0 (the "License");
188
- you may not use this file except in compliance with the License.
189
- You may obtain a copy of the License at
190
-
191
- http://www.apache.org/licenses/LICENSE-2.0
192
-
193
- Unless required by applicable law or agreed to in writing, software
194
- distributed under the License is distributed on an "AS IS" BASIS,
195
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
196
- See the License for the specific language governing permissions and
197
- limitations under the License.
198
- */
199
-
200
- /**
201
- * Uses the [Broadcast Channel API]{@link https://developers.google.com/web/updates/2016/09/broadcastchannel}
202
- * to notify interested parties when a cached response has been updated.
203
- *
204
- * For efficiency's sake, the underlying response bodies are not compared;
205
- * only specific response headers are checked.
206
- *
207
- * @memberof workbox.broadcastUpdate
208
- */
209
- class BroadcastCacheUpdate {
210
- /**
211
- * Construct a BroadcastCacheUpdate instance with a specific `channelName` to
212
- * broadcast messages on
213
- *
214
- * @param {string} channelName The name that will be used when creating
215
- * the `BroadcastChannel`.
216
- * @param {Object} options
217
- * @param {Array<string>}
218
- * [options.headersToCheck=['content-length', 'etag', 'last-modified']] A
219
- * list of headers that will be used to determine whether the responses
220
- * differ.
221
- * @param {string} [options.source='workbox-broadcast-cache-update'] An
222
- * attribution value that indicates where the update originated.
223
- */
224
- constructor(channelName, { headersToCheck, source } = {}) {
225
- {
226
- if (typeof channelName !== 'string' || channelName.length === 0) {
227
- throw new WorkboxError_mjs.WorkboxError('channel-name-required');
228
- }
229
- }
230
-
231
- this._channelName = channelName;
232
- this._headersToCheck = headersToCheck || ['content-length', 'etag', 'last-modified'];
233
- this._source = source || 'workbox-broadcast-cache-update';
234
-
235
- // TODO assert typeof headersToCheck instanceof Array
236
- }
237
-
238
- /**
239
- * @return {BroadcastChannel|undefined} The BroadcastChannel instance used for
240
- * broadcasting updates, or undefined if the browser doesn't support the
241
- * Broadcast Channel API.
242
- *
243
- * @private
244
- */
245
- _getChannel() {
246
- if ('BroadcastChannel' in self && !this._channel) {
247
- this._channel = new BroadcastChannel(this._channelName);
248
- }
249
- return this._channel;
250
- }
251
-
252
- /**
253
- * Compare two [Responses](https://developer.mozilla.org/en-US/docs/Web/API/Response)
254
- * and send a message via the
255
- * {@link https://developers.google.com/web/updates/2016/09/broadcastchannel|Broadcast Channel API}
256
- * if they differ.
257
- *
258
- * Neither of the Responses can be {@link http://stackoverflow.com/questions/39109789|opaque}.
259
- *
260
- * @param {Response} firstResponse First responses to compare.
261
- * @param {Response} secondResponse Second responses to compare.
262
- * @param {string} url The URL of the updated request.
263
- * @param {string} cacheName Name of the cache the responses belong to.
264
- * This is included in the message posted on the broadcast channel.
265
- */
266
- notifyIfUpdated(firstResponse, secondResponse, url, cacheName) {
267
- if (!responsesAreSame(firstResponse, secondResponse, this._headersToCheck)) {
268
- broadcastUpdate(this._getChannel(), cacheName, url, this._source);
269
- }
270
- }
271
- }
272
-
273
- /*
274
- Copyright 2016 Google Inc. All Rights Reserved.
275
- Licensed under the Apache License, Version 2.0 (the "License");
276
- you may not use this file except in compliance with the License.
277
- You may obtain a copy of the License at
278
-
279
- http://www.apache.org/licenses/LICENSE-2.0
280
-
281
- Unless required by applicable law or agreed to in writing, software
282
- distributed under the License is distributed on an "AS IS" BASIS,
283
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
284
- See the License for the specific language governing permissions and
285
- limitations under the License.
286
- */
287
-
288
- /**
289
- * This plugin will automatically broadcast a message whenever a cached response
290
- * is updated.
291
- *
292
- * @memberof workbox.broadcastUpdate
293
- */
294
- class Plugin {
295
- /**
296
- * Construct a new instance with a specific `channelName` to
297
- * broadcast messages on
298
- *
299
- * @param {string} channelName The name that will be used when creating
300
- * the `BroadcastChannel`.
301
- * @param {Object} options
302
- * @param {Array<string>}
303
- * [options.headersToCheck=['content-length', 'etag', 'last-modified']] A
304
- * list of headers that will be used to determine whether the responses
305
- * differ.
306
- * @param {string} [options.source='workbox-broadcast-cache-update'] An
307
- * attribution value that indicates where the update originated.
308
- */
309
- constructor(channelName, options) {
310
- this._broadcastUpdate = new BroadcastCacheUpdate(channelName, options);
311
- }
312
- /**
313
- * A "lifecycle" callback that will be triggered automatically by the
314
- * `workbox-sw` and `workbox-runtime-caching` handlers when an entry is
315
- * added to a cache.
316
- *
317
- * @private
318
- * @param {Object} options The input object to this function.
319
- * @param {string} options.cacheName Name of the cache being updated.
320
- * @param {Response} [options.oldResponse] The previous cached value, if any.
321
- * @param {Response} options.newResponse The new value in the cache.
322
- */
323
- cacheDidUpdate({ cacheName, oldResponse, newResponse, request }) {
324
- {
325
- assert_mjs.assert.isType(cacheName, 'string', {
326
- moduleName: 'workbox-broadcast-cache-update',
327
- className: 'Plugin',
328
- funcName: 'cacheDidUpdate',
329
- paramName: 'cacheName'
330
- });
331
- assert_mjs.assert.isInstance(newResponse, Response, {
332
- moduleName: 'workbox-broadcast-cache-update',
333
- className: 'Plugin',
334
- funcName: 'cacheDidUpdate',
335
- paramName: 'newResponse'
336
- });
337
- assert_mjs.assert.isInstance(request, Request, {
338
- moduleName: 'workbox-broadcast-cache-update',
339
- className: 'Plugin',
340
- funcName: 'cacheDidUpdate',
341
- paramName: 'request'
342
- });
343
- }
344
-
345
- if (!oldResponse) {
346
- // Without a two responses there is nothing to compare.
347
- return;
348
- }
349
-
350
- this._broadcastUpdate.notifyIfUpdated(oldResponse, newResponse, request.url, cacheName);
351
- }
352
- }
353
-
354
- /*
355
- Copyright 2017 Google Inc.
356
-
357
- Licensed under the Apache License, Version 2.0 (the "License");
358
- you may not use this file except in compliance with the License.
359
- You may obtain a copy of the License at
360
-
361
- https://www.apache.org/licenses/LICENSE-2.0
362
-
363
- Unless required by applicable law or agreed to in writing, software
364
- distributed under the License is distributed on an "AS IS" BASIS,
365
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
366
- See the License for the specific language governing permissions and
367
- limitations under the License.
368
- */
369
-
370
- /*
371
- Copyright 2017 Google Inc.
372
-
373
- Licensed under the Apache License, Version 2.0 (the "License");
374
- you may not use this file except in compliance with the License.
375
- You may obtain a copy of the License at
376
-
377
- https://www.apache.org/licenses/LICENSE-2.0
378
-
379
- Unless required by applicable law or agreed to in writing, software
380
- distributed under the License is distributed on an "AS IS" BASIS,
381
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
382
- See the License for the specific language governing permissions and
383
- limitations under the License.
384
- */
385
-
386
- exports.BroadcastCacheUpdate = BroadcastCacheUpdate;
387
- exports.Plugin = Plugin;
388
- exports.broadcastUpdate = broadcastUpdate;
389
- exports.messageTypes = messageTypes;
390
-
391
- return exports;
392
-
393
- }({},workbox.core._private,workbox.core._private,workbox.core._private));
394
-
395
- //# sourceMappingURL=workbox-broadcast-cache-update.dev.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"mappings":"","sources":["packages/workbox-broadcast-cache-update/browser.mjs"],"sourcesContent":["this.workbox = this.workbox || {};\nthis.workbox.broadcastUpdate = (function (exports,WorkboxError_mjs,logger_mjs,assert_mjs) {\n 'use strict';\n\n try {\n self.workbox.v['workbox:broadcast-cache-update:3.6.3'] = 1;\n } catch (e) {} // eslint-disable-line\n\n /*\n Copyright 2016 Google Inc. All Rights Reserved.\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n */\n\n /**\n * Given two `Response's`, compares several header values to see if they are\n * the same or not.\n *\n * @param {Response} firstResponse\n * @param {Response} secondResponse\n * @param {Array<string>} headersToCheck\n * @return {boolean}\n *\n * @memberof workbox.broadcastUpdate\n * @private\n */\n const responsesAreSame = (firstResponse, secondResponse, headersToCheck) => {\n {\n if (!(firstResponse instanceof Response && secondResponse instanceof Response)) {\n throw new WorkboxError_mjs.WorkboxError('invalid-responses-are-same-args');\n }\n }\n\n const atLeastOneHeaderAvailable = headersToCheck.some(header => {\n return firstResponse.headers.has(header) && secondResponse.headers.has(header);\n });\n\n if (!atLeastOneHeaderAvailable) {\n {\n logger_mjs.logger.warn(`Unable to determine where the response has been updated ` + `because none of the headers that would be checked are present.`);\n logger_mjs.logger.debug(`Attempting to compare the following: `, firstResponse, secondResponse, headersToCheck);\n }\n\n // Just return true, indicating the that responses are the same, since we\n // can't determine otherwise.\n return true;\n }\n\n return headersToCheck.every(header => {\n const headerStateComparison = firstResponse.headers.has(header) === secondResponse.headers.has(header);\n const headerValueComparison = firstResponse.headers.get(header) === secondResponse.headers.get(header);\n\n return headerStateComparison && headerValueComparison;\n });\n };\n\n /*\n Copyright 2016 Google Inc. All Rights Reserved.\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n */\n\n var messageTypes = {\n CACHE_UPDATED: 'CACHE_UPDATED'\n };\n\n /*\n Copyright 2016 Google Inc. All Rights Reserved.\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n */\n\n /**\n * You would not normally call this method directly; it's called automatically\n * by an instance of the {@link BroadcastCacheUpdate} class. It's exposed here\n * for the benefit of developers who would rather not use the full\n * `BroadcastCacheUpdate` implementation.\n *\n * Calling this will dispatch a message on the provided\n * {@link https://developers.google.com/web/updates/2016/09/broadcastchannel|Broadcast Channel}\n * to notify interested subscribers about a change to a cached resource.\n *\n * The message that's posted has a formation inspired by the\n * [Flux standard action](https://github.com/acdlite/flux-standard-action#introduction)\n * format like so:\n *\n * ```\n * {\n * type: 'CACHE_UPDATED',\n * meta: 'workbox-broadcast-cache-update',\n * payload: {\n * cacheName: 'the-cache-name',\n * updatedUrl: 'https://example.com/'\n * }\n * }\n * ```\n *\n * (Usage of [Flux](https://facebook.github.io/flux/) itself is not at\n * all required.)\n *\n * @param {BroadcastChannel} channel The `BroadcastChannel` to use.\n * @param {string} cacheName The name of the cache in which the updated\n * `Response` was stored.\n * @param {string} url The URL associated with the updated `Response`.\n * @param {string} source A string identifying this library as the source\n * of the update message.\n *\n * @memberof workbox.broadcastUpdate\n */\n const broadcastUpdate = (channel, cacheName, url, source) => {\n // There are browsers which support service workers but don't support the\n // Broadcast Channel API.\n // See https://github.com/GoogleChrome/workbox/issues/1304\n if (!('BroadcastChannel' in self && channel)) {\n {\n logger_mjs.logger.debug(`${url} was updated, but the Broadcast Channel API is not ` + `available in the current browser.`);\n }\n return;\n }\n\n {\n assert_mjs.assert.isInstance(channel, BroadcastChannel, {\n moduleName: 'workbox-broadcast-cache-update',\n className: '~',\n funcName: 'broadcastUpdate',\n paramName: 'channel'\n });\n assert_mjs.assert.isType(cacheName, 'string', {\n moduleName: 'workbox-broadcast-cache-update',\n className: '~',\n funcName: 'broadcastUpdate',\n paramName: 'cacheName'\n });\n assert_mjs.assert.isType(url, 'string', {\n moduleName: 'workbox-broadcast-cache-update',\n className: '~',\n funcName: 'broadcastUpdate',\n paramName: 'url'\n });\n assert_mjs.assert.isType(source, 'string', {\n moduleName: 'workbox-broadcast-cache-update',\n className: '~',\n funcName: 'broadcastUpdate',\n paramName: 'source'\n });\n }\n\n channel.postMessage({\n type: messageTypes.CACHE_UPDATED,\n meta: source,\n payload: {\n cacheName: cacheName,\n updatedUrl: url\n }\n });\n };\n\n /*\n Copyright 2016 Google Inc. All Rights Reserved.\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n */\n\n /**\n * Uses the [Broadcast Channel API]{@link https://developers.google.com/web/updates/2016/09/broadcastchannel}\n * to notify interested parties when a cached response has been updated.\n *\n * For efficiency's sake, the underlying response bodies are not compared;\n * only specific response headers are checked.\n *\n * @memberof workbox.broadcastUpdate\n */\n class BroadcastCacheUpdate {\n /**\n * Construct a BroadcastCacheUpdate instance with a specific `channelName` to\n * broadcast messages on\n *\n * @param {string} channelName The name that will be used when creating\n * the `BroadcastChannel`.\n * @param {Object} options\n * @param {Array<string>}\n * [options.headersToCheck=['content-length', 'etag', 'last-modified']] A\n * list of headers that will be used to determine whether the responses\n * differ.\n * @param {string} [options.source='workbox-broadcast-cache-update'] An\n * attribution value that indicates where the update originated.\n */\n constructor(channelName, { headersToCheck, source } = {}) {\n {\n if (typeof channelName !== 'string' || channelName.length === 0) {\n throw new WorkboxError_mjs.WorkboxError('channel-name-required');\n }\n }\n\n this._channelName = channelName;\n this._headersToCheck = headersToCheck || ['content-length', 'etag', 'last-modified'];\n this._source = source || 'workbox-broadcast-cache-update';\n\n // TODO assert typeof headersToCheck instanceof Array\n }\n\n /**\n * @return {BroadcastChannel|undefined} The BroadcastChannel instance used for\n * broadcasting updates, or undefined if the browser doesn't support the\n * Broadcast Channel API.\n *\n * @private\n */\n _getChannel() {\n if ('BroadcastChannel' in self && !this._channel) {\n this._channel = new BroadcastChannel(this._channelName);\n }\n return this._channel;\n }\n\n /**\n * Compare two [Responses](https://developer.mozilla.org/en-US/docs/Web/API/Response)\n * and send a message via the\n * {@link https://developers.google.com/web/updates/2016/09/broadcastchannel|Broadcast Channel API}\n * if they differ.\n *\n * Neither of the Responses can be {@link http://stackoverflow.com/questions/39109789|opaque}.\n *\n * @param {Response} firstResponse First responses to compare.\n * @param {Response} secondResponse Second responses to compare.\n * @param {string} url The URL of the updated request.\n * @param {string} cacheName Name of the cache the responses belong to.\n * This is included in the message posted on the broadcast channel.\n */\n notifyIfUpdated(firstResponse, secondResponse, url, cacheName) {\n if (!responsesAreSame(firstResponse, secondResponse, this._headersToCheck)) {\n broadcastUpdate(this._getChannel(), cacheName, url, this._source);\n }\n }\n }\n\n /*\n Copyright 2016 Google Inc. All Rights Reserved.\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n */\n\n /**\n * This plugin will automatically broadcast a message whenever a cached response\n * is updated.\n *\n * @memberof workbox.broadcastUpdate\n */\n class Plugin {\n /**\n * Construct a new instance with a specific `channelName` to\n * broadcast messages on\n *\n * @param {string} channelName The name that will be used when creating\n * the `BroadcastChannel`.\n * @param {Object} options\n * @param {Array<string>}\n * [options.headersToCheck=['content-length', 'etag', 'last-modified']] A\n * list of headers that will be used to determine whether the responses\n * differ.\n * @param {string} [options.source='workbox-broadcast-cache-update'] An\n * attribution value that indicates where the update originated.\n */\n constructor(channelName, options) {\n this._broadcastUpdate = new BroadcastCacheUpdate(channelName, options);\n }\n /**\n * A \"lifecycle\" callback that will be triggered automatically by the\n * `workbox-sw` and `workbox-runtime-caching` handlers when an entry is\n * added to a cache.\n *\n * @private\n * @param {Object} options The input object to this function.\n * @param {string} options.cacheName Name of the cache being updated.\n * @param {Response} [options.oldResponse] The previous cached value, if any.\n * @param {Response} options.newResponse The new value in the cache.\n */\n cacheDidUpdate({ cacheName, oldResponse, newResponse, request }) {\n {\n assert_mjs.assert.isType(cacheName, 'string', {\n moduleName: 'workbox-broadcast-cache-update',\n className: 'Plugin',\n funcName: 'cacheDidUpdate',\n paramName: 'cacheName'\n });\n assert_mjs.assert.isInstance(newResponse, Response, {\n moduleName: 'workbox-broadcast-cache-update',\n className: 'Plugin',\n funcName: 'cacheDidUpdate',\n paramName: 'newResponse'\n });\n assert_mjs.assert.isInstance(request, Request, {\n moduleName: 'workbox-broadcast-cache-update',\n className: 'Plugin',\n funcName: 'cacheDidUpdate',\n paramName: 'request'\n });\n }\n\n if (!oldResponse) {\n // Without a two responses there is nothing to compare.\n return;\n }\n\n this._broadcastUpdate.notifyIfUpdated(oldResponse, newResponse, request.url, cacheName);\n }\n }\n\n /*\n Copyright 2017 Google Inc.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n https://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n */\n\n /*\n Copyright 2017 Google Inc.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n https://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n */\n\n exports.BroadcastCacheUpdate = BroadcastCacheUpdate;\n exports.Plugin = Plugin;\n exports.broadcastUpdate = broadcastUpdate;\n exports.messageTypes = messageTypes;\n\n return exports;\n\n}({},workbox.core._private,workbox.core._private,workbox.core._private));\n"],"file":"workbox-broadcast-cache-update.dev.js"}
@@ -1,3 +0,0 @@
1
- this.workbox=this.workbox||{},this.workbox.broadcastUpdate=function(t){"use strict";try{self.workbox.v["workbox:broadcast-cache-update:3.6.3"]=1}catch(t){}const e=(t,e,s)=>{return!s.some(s=>t.headers.has(s)&&e.headers.has(s))||s.every(s=>{const a=t.headers.has(s)===e.headers.has(s),n=t.headers.get(s)===e.headers.get(s);return a&&n})};var s={CACHE_UPDATED:"CACHE_UPDATED"};const a=(t,e,a,n)=>{"BroadcastChannel"in self&&t&&t.postMessage({type:s.CACHE_UPDATED,meta:n,payload:{cacheName:e,updatedUrl:a}})};class n{constructor(t,{headersToCheck:e,source:s}={}){this.t=t,this.e=e||["content-length","etag","last-modified"],this.s=s||"workbox-broadcast-cache-update"}a(){return"BroadcastChannel"in self&&!this.n&&(this.n=new BroadcastChannel(this.t)),this.n}notifyIfUpdated(t,s,n,c){e(t,s,this.e)||a(this.a(),c,n,this.s)}}return t.BroadcastCacheUpdate=n,t.Plugin=class{constructor(t,e){this.c=new n(t,e)}cacheDidUpdate({cacheName:t,oldResponse:e,newResponse:s,request:a}){e&&this.c.notifyIfUpdated(e,s,a.url,t)}},t.broadcastUpdate=a,t.messageTypes=s,t}({});
2
-
3
- //# sourceMappingURL=workbox-broadcast-cache-update.prod.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"mappings":"","sources":["packages/workbox-broadcast-cache-update/browser.mjs"],"sourcesContent":["this.workbox=this.workbox||{},this.workbox.broadcastUpdate=function(t){\"use strict\";try{self.workbox.v[\"workbox:broadcast-cache-update:3.6.3\"]=1}catch(t){}const e=(t,e,s)=>{return!s.some(s=>t.headers.has(s)&&e.headers.has(s))||s.every(s=>{const a=t.headers.has(s)===e.headers.has(s),n=t.headers.get(s)===e.headers.get(s);return a&&n})};var s={CACHE_UPDATED:\"CACHE_UPDATED\"};const a=(t,e,a,n)=>{\"BroadcastChannel\"in self&&t&&t.postMessage({type:s.CACHE_UPDATED,meta:n,payload:{cacheName:e,updatedUrl:a}})};class n{constructor(t,{headersToCheck:e,source:s}={}){this.t=t,this.e=e||[\"content-length\",\"etag\",\"last-modified\"],this.s=s||\"workbox-broadcast-cache-update\"}a(){return\"BroadcastChannel\"in self&&!this.n&&(this.n=new BroadcastChannel(this.t)),this.n}notifyIfUpdated(t,s,n,c){e(t,s,this.e)||a(this.a(),c,n,this.s)}}return t.BroadcastCacheUpdate=n,t.Plugin=class{constructor(t,e){this.c=new n(t,e)}cacheDidUpdate({cacheName:t,oldResponse:e,newResponse:s,request:a}){e&&this.c.notifyIfUpdated(e,s,a.url,t)}},t.broadcastUpdate=a,t.messageTypes=s,t}({});\n"],"file":"workbox-broadcast-cache-update.prod.js"}
@@ -1,740 +0,0 @@
1
- this.workbox = this.workbox || {};
2
- this.workbox.expiration = (function (exports,DBWrapper_mjs,WorkboxError_mjs,assert_mjs,logger_mjs,cacheNames_mjs,index_mjs) {
3
- 'use strict';
4
-
5
- try {
6
- self.workbox.v['workbox:cache-expiration:3.6.3'] = 1;
7
- } catch (e) {} // eslint-disable-line
8
-
9
- /*
10
- Copyright 2017 Google Inc.
11
-
12
- Licensed under the Apache License, Version 2.0 (the "License");
13
- you may not use this file except in compliance with the License.
14
- You may obtain a copy of the License at
15
-
16
- https://www.apache.org/licenses/LICENSE-2.0
17
-
18
- Unless required by applicable law or agreed to in writing, software
19
- distributed under the License is distributed on an "AS IS" BASIS,
20
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
- See the License for the specific language governing permissions and
22
- limitations under the License.
23
- */
24
-
25
- const URL_KEY = 'url';
26
- const TIMESTAMP_KEY = 'timestamp';
27
-
28
- /**
29
- * Returns the timestamp model.
30
- *
31
- * @private
32
- */
33
- class CacheTimestampsModel {
34
- /**
35
- *
36
- * @param {string} cacheName
37
- *
38
- * @private
39
- */
40
- constructor(cacheName) {
41
- // TODO Check cacheName
42
-
43
- this._cacheName = cacheName;
44
- this._storeName = cacheName;
45
-
46
- this._db = new DBWrapper_mjs.DBWrapper(this._cacheName, 2, {
47
- onupgradeneeded: evt => this._handleUpgrade(evt)
48
- });
49
- }
50
-
51
- /**
52
- * Should perform an upgrade of indexedDB.
53
- *
54
- * @param {Event} evt
55
- *
56
- * @private
57
- */
58
- _handleUpgrade(evt) {
59
- const db = evt.target.result;
60
- if (evt.oldVersion < 2) {
61
- // Remove old databases.
62
- if (db.objectStoreNames.contains('workbox-cache-expiration')) {
63
- db.deleteObjectStore('workbox-cache-expiration');
64
- }
65
- }
66
-
67
- db.createObjectStore(this._storeName, { keyPath: URL_KEY }).createIndex(TIMESTAMP_KEY, TIMESTAMP_KEY, { unique: false });
68
- }
69
-
70
- /**
71
- * @param {string} url
72
- * @param {number} timestamp
73
- *
74
- * @private
75
- */
76
- setTimestamp(url, timestamp) {
77
- var _this = this;
78
-
79
- return babelHelpers.asyncToGenerator(function* () {
80
- yield _this._db.put(_this._storeName, {
81
- [URL_KEY]: new URL(url, location).href,
82
- [TIMESTAMP_KEY]: timestamp
83
- });
84
- })();
85
- }
86
-
87
- /**
88
- * Get all of the timestamps in the indexedDB.
89
- *
90
- * @return {Array<Objects>}
91
- *
92
- * @private
93
- */
94
- getAllTimestamps() {
95
- var _this2 = this;
96
-
97
- return babelHelpers.asyncToGenerator(function* () {
98
- return yield _this2._db.getAllMatching(_this2._storeName, {
99
- index: TIMESTAMP_KEY
100
- });
101
- })();
102
- }
103
-
104
- /**
105
- * Returns the timestamp stored for a given URL.
106
- *
107
- * @param {string} url
108
- * @return {number}
109
- *
110
- * @private
111
- */
112
- getTimestamp(url) {
113
- var _this3 = this;
114
-
115
- return babelHelpers.asyncToGenerator(function* () {
116
- const timestampObject = yield _this3._db.get(_this3._storeName, url);
117
- return timestampObject.timestamp;
118
- })();
119
- }
120
-
121
- /**
122
- * @param {string} url
123
- *
124
- * @private
125
- */
126
- deleteUrl(url) {
127
- var _this4 = this;
128
-
129
- return babelHelpers.asyncToGenerator(function* () {
130
- yield _this4._db.delete(_this4._storeName, new URL(url, location).href);
131
- })();
132
- }
133
-
134
- /**
135
- * Removes the underlying IndexedDB object store entirely.
136
- */
137
- delete() {
138
- var _this5 = this;
139
-
140
- return babelHelpers.asyncToGenerator(function* () {
141
- yield _this5._db.deleteDatabase();
142
- _this5._db = null;
143
- })();
144
- }
145
- }
146
-
147
- /*
148
- Copyright 2017 Google Inc.
149
-
150
- Licensed under the Apache License, Version 2.0 (the "License");
151
- you may not use this file except in compliance with the License.
152
- You may obtain a copy of the License at
153
-
154
- https://www.apache.org/licenses/LICENSE-2.0
155
-
156
- Unless required by applicable law or agreed to in writing, software
157
- distributed under the License is distributed on an "AS IS" BASIS,
158
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
159
- See the License for the specific language governing permissions and
160
- limitations under the License.
161
- */
162
-
163
- /**
164
- * The `CacheExpiration` class allows you define an expiration and / or
165
- * limit on the number of responses stored in a
166
- * [`Cache`](https://developer.mozilla.org/en-US/docs/Web/API/Cache).
167
- *
168
- * @memberof workbox.expiration
169
- */
170
- class CacheExpiration {
171
- /**
172
- * To construct a new CacheExpiration instance you must provide at least
173
- * one of the `config` properties.
174
- *
175
- * @param {string} cacheName Name of the cache to apply restrictions to.
176
- * @param {Object} config
177
- * @param {number} [config.maxEntries] The maximum number of entries to cache.
178
- * Entries used the least will be removed as the maximum is reached.
179
- * @param {number} [config.maxAgeSeconds] The maximum age of an entry before
180
- * it's treated as stale and removed.
181
- */
182
- constructor(cacheName, config = {}) {
183
- {
184
- assert_mjs.assert.isType(cacheName, 'string', {
185
- moduleName: 'workbox-cache-expiration',
186
- className: 'CacheExpiration',
187
- funcName: 'constructor',
188
- paramName: 'cacheName'
189
- });
190
-
191
- if (!(config.maxEntries || config.maxAgeSeconds)) {
192
- throw new WorkboxError_mjs.WorkboxError('max-entries-or-age-required', {
193
- moduleName: 'workbox-cache-expiration',
194
- className: 'CacheExpiration',
195
- funcName: 'constructor'
196
- });
197
- }
198
-
199
- if (config.maxEntries) {
200
- assert_mjs.assert.isType(config.maxEntries, 'number', {
201
- moduleName: 'workbox-cache-expiration',
202
- className: 'CacheExpiration',
203
- funcName: 'constructor',
204
- paramName: 'config.maxEntries'
205
- });
206
-
207
- // TODO: Assert is positive
208
- }
209
-
210
- if (config.maxAgeSeconds) {
211
- assert_mjs.assert.isType(config.maxAgeSeconds, 'number', {
212
- moduleName: 'workbox-cache-expiration',
213
- className: 'CacheExpiration',
214
- funcName: 'constructor',
215
- paramName: 'config.maxAgeSeconds'
216
- });
217
-
218
- // TODO: Assert is positive
219
- }
220
- }
221
-
222
- this._isRunning = false;
223
- this._rerunRequested = false;
224
- this._maxEntries = config.maxEntries;
225
- this._maxAgeSeconds = config.maxAgeSeconds;
226
- this._cacheName = cacheName;
227
- this._timestampModel = new CacheTimestampsModel(cacheName);
228
- }
229
-
230
- /**
231
- * Expires entries for the given cache and given criteria.
232
- */
233
- expireEntries() {
234
- var _this = this;
235
-
236
- return babelHelpers.asyncToGenerator(function* () {
237
- if (_this._isRunning) {
238
- _this._rerunRequested = true;
239
- return;
240
- }
241
- _this._isRunning = true;
242
-
243
- const now = Date.now();
244
-
245
- // First, expire old entries, if maxAgeSeconds is set.
246
- const oldEntries = yield _this._findOldEntries(now);
247
-
248
- // Once that's done, check for the maximum size.
249
- const extraEntries = yield _this._findExtraEntries();
250
-
251
- // Use a Set to remove any duplicates following the concatenation, then
252
- // convert back into an array.
253
- const allUrls = [...new Set(oldEntries.concat(extraEntries))];
254
-
255
- yield Promise.all([_this._deleteFromCache(allUrls), _this._deleteFromIDB(allUrls)]);
256
-
257
- {
258
- // TODO: break apart entries deleted due to expiration vs size restraints
259
- if (allUrls.length > 0) {
260
- logger_mjs.logger.groupCollapsed(`Expired ${allUrls.length} ` + `${allUrls.length === 1 ? 'entry' : 'entries'} and removed ` + `${allUrls.length === 1 ? 'it' : 'them'} from the ` + `'${_this._cacheName}' cache.`);
261
- logger_mjs.logger.log(`Expired the following ${allUrls.length === 1 ? 'URL' : 'URLs'}:`);
262
- allUrls.forEach(function (url) {
263
- return logger_mjs.logger.log(` ${url}`);
264
- });
265
- logger_mjs.logger.groupEnd();
266
- } else {
267
- logger_mjs.logger.debug(`Cache expiration ran and found no entries to remove.`);
268
- }
269
- }
270
-
271
- _this._isRunning = false;
272
- if (_this._rerunRequested) {
273
- _this._rerunRequested = false;
274
- _this.expireEntries();
275
- }
276
- })();
277
- }
278
-
279
- /**
280
- * Expires entries based on the maximum age.
281
- *
282
- * @param {number} expireFromTimestamp A timestamp.
283
- * @return {Promise<Array<string>>} A list of the URLs that were expired.
284
- *
285
- * @private
286
- */
287
- _findOldEntries(expireFromTimestamp) {
288
- var _this2 = this;
289
-
290
- return babelHelpers.asyncToGenerator(function* () {
291
- {
292
- assert_mjs.assert.isType(expireFromTimestamp, 'number', {
293
- moduleName: 'workbox-cache-expiration',
294
- className: 'CacheExpiration',
295
- funcName: '_findOldEntries',
296
- paramName: 'expireFromTimestamp'
297
- });
298
- }
299
-
300
- if (!_this2._maxAgeSeconds) {
301
- return [];
302
- }
303
-
304
- const expireOlderThan = expireFromTimestamp - _this2._maxAgeSeconds * 1000;
305
- const timestamps = yield _this2._timestampModel.getAllTimestamps();
306
- const expiredUrls = [];
307
- timestamps.forEach(function (timestampDetails) {
308
- if (timestampDetails.timestamp < expireOlderThan) {
309
- expiredUrls.push(timestampDetails.url);
310
- }
311
- });
312
-
313
- return expiredUrls;
314
- })();
315
- }
316
-
317
- /**
318
- * @return {Promise<Array>}
319
- *
320
- * @private
321
- */
322
- _findExtraEntries() {
323
- var _this3 = this;
324
-
325
- return babelHelpers.asyncToGenerator(function* () {
326
- const extraUrls = [];
327
-
328
- if (!_this3._maxEntries) {
329
- return [];
330
- }
331
-
332
- const timestamps = yield _this3._timestampModel.getAllTimestamps();
333
- while (timestamps.length > _this3._maxEntries) {
334
- const lastUsed = timestamps.shift();
335
- extraUrls.push(lastUsed.url);
336
- }
337
-
338
- return extraUrls;
339
- })();
340
- }
341
-
342
- /**
343
- * @param {Array<string>} urls Array of URLs to delete from cache.
344
- *
345
- * @private
346
- */
347
- _deleteFromCache(urls) {
348
- var _this4 = this;
349
-
350
- return babelHelpers.asyncToGenerator(function* () {
351
- const cache = yield caches.open(_this4._cacheName);
352
- for (const url of urls) {
353
- yield cache.delete(url);
354
- }
355
- })();
356
- }
357
-
358
- /**
359
- * @param {Array<string>} urls Array of URLs to delete from IDB
360
- *
361
- * @private
362
- */
363
- _deleteFromIDB(urls) {
364
- var _this5 = this;
365
-
366
- return babelHelpers.asyncToGenerator(function* () {
367
- for (const url of urls) {
368
- yield _this5._timestampModel.deleteUrl(url);
369
- }
370
- })();
371
- }
372
-
373
- /**
374
- * Update the timestamp for the given URL. This ensures the when
375
- * removing entries based on maximum entries, most recently used
376
- * is accurate or when expiring, the timestamp is up-to-date.
377
- *
378
- * @param {string} url
379
- */
380
- updateTimestamp(url) {
381
- var _this6 = this;
382
-
383
- return babelHelpers.asyncToGenerator(function* () {
384
- {
385
- assert_mjs.assert.isType(url, 'string', {
386
- moduleName: 'workbox-cache-expiration',
387
- className: 'CacheExpiration',
388
- funcName: 'updateTimestamp',
389
- paramName: 'url'
390
- });
391
- }
392
-
393
- const urlObject = new URL(url, location);
394
- urlObject.hash = '';
395
-
396
- yield _this6._timestampModel.setTimestamp(urlObject.href, Date.now());
397
- })();
398
- }
399
-
400
- /**
401
- * Can be used to check if a URL has expired or not before it's used.
402
- *
403
- * This requires a look up from IndexedDB, so can be slow.
404
- *
405
- * Note: This method will not remove the cached entry, call
406
- * `expireEntries()` to remove indexedDB and Cache entries.
407
- *
408
- * @param {string} url
409
- * @return {boolean}
410
- */
411
- isURLExpired(url) {
412
- var _this7 = this;
413
-
414
- return babelHelpers.asyncToGenerator(function* () {
415
- if (!_this7._maxAgeSeconds) {
416
- throw new WorkboxError_mjs.WorkboxError(`expired-test-without-max-age`, {
417
- methodName: 'isURLExpired',
418
- paramName: 'maxAgeSeconds'
419
- });
420
- }
421
- const urlObject = new URL(url, location);
422
- urlObject.hash = '';
423
-
424
- const timestamp = yield _this7._timestampModel.getTimestamp(urlObject.href);
425
- const expireOlderThan = Date.now() - _this7._maxAgeSeconds * 1000;
426
- return timestamp < expireOlderThan;
427
- })();
428
- }
429
-
430
- /**
431
- * Removes the IndexedDB object store used to keep track of cache expiration
432
- * metadata.
433
- */
434
- delete() {
435
- var _this8 = this;
436
-
437
- return babelHelpers.asyncToGenerator(function* () {
438
- // Make sure we don't attempt another rerun if we're called in the middle of
439
- // a cache expiration.
440
- _this8._rerunRequested = false;
441
- yield _this8._timestampModel.delete();
442
- })();
443
- }
444
- }
445
-
446
- /*
447
- Copyright 2016 Google Inc. All Rights Reserved.
448
- Licensed under the Apache License, Version 2.0 (the "License");
449
- you may not use this file except in compliance with the License.
450
- You may obtain a copy of the License at
451
- http://www.apache.org/licenses/LICENSE-2.0
452
- Unless required by applicable law or agreed to in writing, software
453
- distributed under the License is distributed on an "AS IS" BASIS,
454
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
455
- See the License for the specific language governing permissions and
456
- limitations under the License.
457
- */
458
-
459
- /**
460
- * This plugin can be used in the Workbox APIs to regularly enforce a
461
- * limit on the age and / or the number of cached requests.
462
- *
463
- * Whenever a cached request is used or updated, this plugin will look
464
- * at the used Cache and remove any old or extra requests.
465
- *
466
- * When using `maxAgeSeconds`, requests may be used *once* after expiring
467
- * because the expiration clean up will not have occurred until *after* the
468
- * cached request has been used. If the request has a "Date" header, then
469
- * a light weight expiration check is performed and the request will not be
470
- * used immediately.
471
- *
472
- * When using `maxEntries`, the last request to be used will be the request
473
- * that is removed from the Cache.
474
- *
475
- * @memberof workbox.expiration
476
- */
477
- class Plugin {
478
- /**
479
- * @param {Object} config
480
- * @param {number} [config.maxEntries] The maximum number of entries to cache.
481
- * Entries used the least will be removed as the maximum is reached.
482
- * @param {number} [config.maxAgeSeconds] The maximum age of an entry before
483
- * it's treated as stale and removed.
484
- * @param {boolean} [config.purgeOnQuotaError] Whether to opt this cache in to
485
- * automatic deletion if the available storage quota has been exceeded.
486
- */
487
- constructor(config = {}) {
488
- {
489
- if (!(config.maxEntries || config.maxAgeSeconds)) {
490
- throw new WorkboxError_mjs.WorkboxError('max-entries-or-age-required', {
491
- moduleName: 'workbox-cache-expiration',
492
- className: 'Plugin',
493
- funcName: 'constructor'
494
- });
495
- }
496
-
497
- if (config.maxEntries) {
498
- assert_mjs.assert.isType(config.maxEntries, 'number', {
499
- moduleName: 'workbox-cache-expiration',
500
- className: 'Plugin',
501
- funcName: 'constructor',
502
- paramName: 'config.maxEntries'
503
- });
504
- }
505
-
506
- if (config.maxAgeSeconds) {
507
- assert_mjs.assert.isType(config.maxAgeSeconds, 'number', {
508
- moduleName: 'workbox-cache-expiration',
509
- className: 'Plugin',
510
- funcName: 'constructor',
511
- paramName: 'config.maxAgeSeconds'
512
- });
513
- }
514
- }
515
-
516
- this._config = config;
517
- this._maxAgeSeconds = config.maxAgeSeconds;
518
- this._cacheExpirations = new Map();
519
-
520
- if (config.purgeOnQuotaError) {
521
- index_mjs.registerQuotaErrorCallback(() => this.deleteCacheAndMetadata());
522
- }
523
- }
524
-
525
- /**
526
- * A simple helper method to return a CacheExpiration instance for a given
527
- * cache name.
528
- *
529
- * @param {string} cacheName
530
- * @return {CacheExpiration}
531
- *
532
- * @private
533
- */
534
- _getCacheExpiration(cacheName) {
535
- if (cacheName === cacheNames_mjs.cacheNames.getRuntimeName()) {
536
- throw new WorkboxError_mjs.WorkboxError('expire-custom-caches-only');
537
- }
538
-
539
- let cacheExpiration = this._cacheExpirations.get(cacheName);
540
- if (!cacheExpiration) {
541
- cacheExpiration = new CacheExpiration(cacheName, this._config);
542
- this._cacheExpirations.set(cacheName, cacheExpiration);
543
- }
544
- return cacheExpiration;
545
- }
546
-
547
- /**
548
- * A "lifecycle" callback that will be triggered automatically by the
549
- * `workbox.runtimeCaching` handlers when a `Response` is about to be returned
550
- * from a [Cache](https://developer.mozilla.org/en-US/docs/Web/API/Cache) to
551
- * the handler. It allows the `Response` to be inspected for freshness and
552
- * prevents it from being used if the `Response`'s `Date` header value is
553
- * older than the configured `maxAgeSeconds`.
554
- *
555
- * @param {Object} options
556
- * @param {string} options.cacheName Name of the cache the response is in.
557
- * @param {Response} options.cachedResponse The `Response` object that's been
558
- * read from a cache and whose freshness should be checked.
559
- * @return {Response} Either the `cachedResponse`, if it's
560
- * fresh, or `null` if the `Response` is older than `maxAgeSeconds`.
561
- *
562
- * @private
563
- */
564
- cachedResponseWillBeUsed({ cacheName, cachedResponse }) {
565
- if (!cachedResponse) {
566
- return null;
567
- }
568
-
569
- let isFresh = this._isResponseDateFresh(cachedResponse);
570
-
571
- // Expire entries to ensure that even if the expiration date has
572
- // expired, it'll only be used once.
573
- const cacheExpiration = this._getCacheExpiration(cacheName);
574
- cacheExpiration.expireEntries();
575
-
576
- return isFresh ? cachedResponse : null;
577
- }
578
-
579
- /**
580
- * @param {Response} cachedResponse
581
- * @return {boolean}
582
- *
583
- * @private
584
- */
585
- _isResponseDateFresh(cachedResponse) {
586
- if (!this._maxAgeSeconds) {
587
- // We aren't expiring by age, so return true, it's fresh
588
- return true;
589
- }
590
-
591
- // Check if the 'date' header will suffice a quick expiration check.
592
- // See https://github.com/GoogleChromeLabs/sw-toolbox/issues/164 for
593
- // discussion.
594
- const dateHeaderTimestamp = this._getDateHeaderTimestamp(cachedResponse);
595
- if (dateHeaderTimestamp === null) {
596
- // Unable to parse date, so assume it's fresh.
597
- return true;
598
- }
599
-
600
- // If we have a valid headerTime, then our response is fresh iff the
601
- // headerTime plus maxAgeSeconds is greater than the current time.
602
- const now = Date.now();
603
- return dateHeaderTimestamp >= now - this._maxAgeSeconds * 1000;
604
- }
605
-
606
- /**
607
- * This method will extract the data header and parse it into a useful
608
- * value.
609
- *
610
- * @param {Response} cachedResponse
611
- * @return {number}
612
- *
613
- * @private
614
- */
615
- _getDateHeaderTimestamp(cachedResponse) {
616
- if (!cachedResponse.headers.has('date')) {
617
- return null;
618
- }
619
-
620
- const dateHeader = cachedResponse.headers.get('date');
621
- const parsedDate = new Date(dateHeader);
622
- const headerTime = parsedDate.getTime();
623
-
624
- // If the Date header was invalid for some reason, parsedDate.getTime()
625
- // will return NaN.
626
- if (isNaN(headerTime)) {
627
- return null;
628
- }
629
-
630
- return headerTime;
631
- }
632
-
633
- /**
634
- * A "lifecycle" callback that will be triggered automatically by the
635
- * `workbox.runtimeCaching` handlers when an entry is added to a cache.
636
- *
637
- * @param {Object} options
638
- * @param {string} options.cacheName Name of the cache that was updated.
639
- * @param {string} options.request The Request for the cached entry.
640
- *
641
- * @private
642
- */
643
- cacheDidUpdate({ cacheName, request }) {
644
- var _this = this;
645
-
646
- return babelHelpers.asyncToGenerator(function* () {
647
- {
648
- assert_mjs.assert.isType(cacheName, 'string', {
649
- moduleName: 'workbox-cache-expiration',
650
- className: 'Plugin',
651
- funcName: 'cacheDidUpdate',
652
- paramName: 'cacheName'
653
- });
654
- assert_mjs.assert.isInstance(request, Request, {
655
- moduleName: 'workbox-cache-expiration',
656
- className: 'Plugin',
657
- funcName: 'cacheDidUpdate',
658
- paramName: 'request'
659
- });
660
- }
661
-
662
- const cacheExpiration = _this._getCacheExpiration(cacheName);
663
- yield cacheExpiration.updateTimestamp(request.url);
664
- yield cacheExpiration.expireEntries();
665
- })();
666
- }
667
-
668
- /**
669
- * This is a helper method that performs two operations:
670
- *
671
- * - Deletes *all* the underlying Cache instances associated with this plugin
672
- * instance, by calling caches.delete() on you behalf.
673
- * - Deletes the metadata from IndexedDB used to keep track of expiration
674
- * details for each Cache instance.
675
- *
676
- * When using cache expiration, calling this method is preferable to calling
677
- * `caches.delete()` directly, since this will ensure that the IndexedDB
678
- * metadata is also cleanly removed and open IndexedDB instances are deleted.
679
- *
680
- * Note that if you're *not* using cache expiration for a given cache, calling
681
- * `caches.delete()` and passing in the cache's name should be sufficient.
682
- * There is no Workbox-specific method needed for cleanup in that case.
683
- */
684
- deleteCacheAndMetadata() {
685
- var _this2 = this;
686
-
687
- return babelHelpers.asyncToGenerator(function* () {
688
- // Do this one at a time instead of all at once via `Promise.all()` to
689
- // reduce the chance of inconsistency if a promise rejects.
690
- for (const [cacheName, cacheExpiration] of _this2._cacheExpirations) {
691
- yield caches.delete(cacheName);
692
- yield cacheExpiration.delete();
693
- }
694
-
695
- // Reset this._cacheExpirations to its initial state.
696
- _this2._cacheExpirations = new Map();
697
- })();
698
- }
699
- }
700
-
701
- /*
702
- Copyright 2017 Google Inc.
703
-
704
- Licensed under the Apache License, Version 2.0 (the "License");
705
- you may not use this file except in compliance with the License.
706
- You may obtain a copy of the License at
707
-
708
- https://www.apache.org/licenses/LICENSE-2.0
709
-
710
- Unless required by applicable law or agreed to in writing, software
711
- distributed under the License is distributed on an "AS IS" BASIS,
712
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
713
- See the License for the specific language governing permissions and
714
- limitations under the License.
715
- */
716
-
717
- /*
718
- Copyright 2017 Google Inc.
719
-
720
- Licensed under the Apache License, Version 2.0 (the "License");
721
- you may not use this file except in compliance with the License.
722
- You may obtain a copy of the License at
723
-
724
- https://www.apache.org/licenses/LICENSE-2.0
725
-
726
- Unless required by applicable law or agreed to in writing, software
727
- distributed under the License is distributed on an "AS IS" BASIS,
728
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
729
- See the License for the specific language governing permissions and
730
- limitations under the License.
731
- */
732
-
733
- exports.CacheExpiration = CacheExpiration;
734
- exports.Plugin = Plugin;
735
-
736
- return exports;
737
-
738
- }({},workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private,workbox.core));
739
-
740
- //# sourceMappingURL=workbox-cache-expiration.dev.js.map