jekyll-pwa-workbox 0.0.1 → 0.0.3

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 (113) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jekyll-pwa-workbox.rb +125 -125
  3. data/lib/vendor/workbox-v4.1.1/workbox-background-sync.dev.js +729 -0
  4. data/lib/vendor/workbox-v4.1.1/workbox-background-sync.dev.js.map +1 -0
  5. data/lib/vendor/workbox-v4.1.1/workbox-background-sync.prod.js +2 -0
  6. data/lib/vendor/workbox-v4.1.1/workbox-background-sync.prod.js.map +1 -0
  7. data/lib/vendor/workbox-v4.1.1/workbox-broadcast-update.dev.js +482 -0
  8. data/lib/vendor/workbox-v4.1.1/workbox-broadcast-update.dev.js.map +1 -0
  9. data/lib/vendor/workbox-v4.1.1/workbox-broadcast-update.prod.js +2 -0
  10. data/lib/vendor/workbox-v4.1.1/workbox-broadcast-update.prod.js.map +1 -0
  11. data/lib/vendor/{workbox-v3.6.3 → workbox-v4.1.1}/workbox-cacheable-response.dev.js +34 -70
  12. data/lib/vendor/workbox-v4.1.1/workbox-cacheable-response.dev.js.map +1 -0
  13. data/lib/vendor/workbox-v4.1.1/workbox-cacheable-response.prod.js +2 -0
  14. data/lib/vendor/workbox-v4.1.1/workbox-cacheable-response.prod.js.map +1 -0
  15. data/lib/vendor/workbox-v4.1.1/workbox-core.dev.js +1584 -0
  16. data/lib/vendor/workbox-v4.1.1/workbox-core.dev.js.map +1 -0
  17. data/lib/vendor/workbox-v4.1.1/workbox-core.prod.js +2 -0
  18. data/lib/vendor/workbox-v4.1.1/workbox-core.prod.js.map +1 -0
  19. data/lib/vendor/workbox-v4.1.1/workbox-expiration.dev.js +633 -0
  20. data/lib/vendor/workbox-v4.1.1/workbox-expiration.dev.js.map +1 -0
  21. data/lib/vendor/workbox-v4.1.1/workbox-expiration.prod.js +2 -0
  22. data/lib/vendor/workbox-v4.1.1/workbox-expiration.prod.js.map +1 -0
  23. data/lib/vendor/workbox-v4.1.1/workbox-navigation-preload.dev.js +110 -0
  24. data/lib/vendor/workbox-v4.1.1/workbox-navigation-preload.dev.js.map +1 -0
  25. data/lib/vendor/workbox-v4.1.1/workbox-navigation-preload.prod.js +2 -0
  26. data/lib/vendor/workbox-v4.1.1/workbox-navigation-preload.prod.js.map +1 -0
  27. data/lib/vendor/workbox-v4.1.1/workbox-offline-ga.dev.js +243 -0
  28. data/lib/vendor/workbox-v4.1.1/workbox-offline-ga.dev.js.map +1 -0
  29. data/lib/vendor/workbox-v4.1.1/workbox-offline-ga.prod.js +2 -0
  30. data/lib/vendor/workbox-v4.1.1/workbox-offline-ga.prod.js.map +1 -0
  31. data/lib/vendor/workbox-v4.1.1/workbox-precaching.dev.js +942 -0
  32. data/lib/vendor/workbox-v4.1.1/workbox-precaching.dev.js.map +1 -0
  33. data/lib/vendor/workbox-v4.1.1/workbox-precaching.prod.js +2 -0
  34. data/lib/vendor/workbox-v4.1.1/workbox-precaching.prod.js.map +1 -0
  35. data/lib/vendor/workbox-v4.1.1/workbox-range-requests.dev.js +268 -0
  36. data/lib/vendor/workbox-v4.1.1/workbox-range-requests.dev.js.map +1 -0
  37. data/lib/vendor/workbox-v4.1.1/workbox-range-requests.prod.js +2 -0
  38. data/lib/vendor/workbox-v4.1.1/workbox-range-requests.prod.js.map +1 -0
  39. data/lib/vendor/workbox-v4.1.1/workbox-routing.dev.js +1020 -0
  40. data/lib/vendor/workbox-v4.1.1/workbox-routing.dev.js.map +1 -0
  41. data/lib/vendor/workbox-v4.1.1/workbox-routing.prod.js +2 -0
  42. data/lib/vendor/workbox-v4.1.1/workbox-routing.prod.js.map +1 -0
  43. data/lib/vendor/workbox-v4.1.1/workbox-strategies.dev.js +1138 -0
  44. data/lib/vendor/workbox-v4.1.1/workbox-strategies.dev.js.map +1 -0
  45. data/lib/vendor/workbox-v4.1.1/workbox-strategies.prod.js +2 -0
  46. data/lib/vendor/workbox-v4.1.1/workbox-strategies.prod.js.map +1 -0
  47. data/lib/vendor/{workbox-v3.6.3 → workbox-v4.1.1}/workbox-streams.dev.js +108 -151
  48. data/lib/vendor/workbox-v4.1.1/workbox-streams.dev.js.map +1 -0
  49. data/lib/vendor/workbox-v4.1.1/workbox-streams.prod.js +2 -0
  50. data/lib/vendor/workbox-v4.1.1/workbox-streams.prod.js.map +1 -0
  51. data/lib/vendor/workbox-v4.1.1/workbox-sw.js +2 -0
  52. data/lib/vendor/workbox-v4.1.1/workbox-sw.js.map +1 -0
  53. data/lib/vendor/workbox-v4.1.1/workbox-window.dev.es5.mjs +879 -0
  54. data/lib/vendor/workbox-v4.1.1/workbox-window.dev.es5.mjs.map +1 -0
  55. data/lib/vendor/workbox-v4.1.1/workbox-window.dev.mjs +745 -0
  56. data/lib/vendor/workbox-v4.1.1/workbox-window.dev.mjs.map +1 -0
  57. data/lib/vendor/workbox-v4.1.1/workbox-window.dev.umd.js +890 -0
  58. data/lib/vendor/workbox-v4.1.1/workbox-window.dev.umd.js.map +1 -0
  59. data/lib/vendor/workbox-v4.1.1/workbox-window.prod.es5.mjs +2 -0
  60. data/lib/vendor/workbox-v4.1.1/workbox-window.prod.es5.mjs.map +1 -0
  61. data/lib/vendor/workbox-v4.1.1/workbox-window.prod.mjs +2 -0
  62. data/lib/vendor/workbox-v4.1.1/workbox-window.prod.mjs.map +1 -0
  63. data/lib/vendor/workbox-v4.1.1/workbox-window.prod.umd.js +2 -0
  64. data/lib/vendor/workbox-v4.1.1/workbox-window.prod.umd.js.map +1 -0
  65. metadata +70 -58
  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.map +0 -1
  79. data/lib/vendor/workbox-v3.6.3/workbox-cacheable-response.prod.js +0 -3
  80. data/lib/vendor/workbox-v3.6.3/workbox-cacheable-response.prod.js.map +0 -1
  81. data/lib/vendor/workbox-v3.6.3/workbox-core.dev.js +0 -1736
  82. data/lib/vendor/workbox-v3.6.3/workbox-core.dev.js.map +0 -1
  83. data/lib/vendor/workbox-v3.6.3/workbox-core.prod.js +0 -3
  84. data/lib/vendor/workbox-v3.6.3/workbox-core.prod.js.map +0 -1
  85. data/lib/vendor/workbox-v3.6.3/workbox-google-analytics.dev.js +0 -255
  86. data/lib/vendor/workbox-v3.6.3/workbox-google-analytics.dev.js.map +0 -1
  87. data/lib/vendor/workbox-v3.6.3/workbox-google-analytics.prod.js +0 -3
  88. data/lib/vendor/workbox-v3.6.3/workbox-google-analytics.prod.js.map +0 -1
  89. data/lib/vendor/workbox-v3.6.3/workbox-navigation-preload.dev.js +0 -159
  90. data/lib/vendor/workbox-v3.6.3/workbox-navigation-preload.dev.js.map +0 -1
  91. data/lib/vendor/workbox-v3.6.3/workbox-navigation-preload.prod.js +0 -3
  92. data/lib/vendor/workbox-v3.6.3/workbox-navigation-preload.prod.js.map +0 -1
  93. data/lib/vendor/workbox-v3.6.3/workbox-precaching.dev.js +0 -1171
  94. data/lib/vendor/workbox-v3.6.3/workbox-precaching.dev.js.map +0 -1
  95. data/lib/vendor/workbox-v3.6.3/workbox-precaching.prod.js +0 -3
  96. data/lib/vendor/workbox-v3.6.3/workbox-precaching.prod.js.map +0 -1
  97. data/lib/vendor/workbox-v3.6.3/workbox-range-requests.dev.js +0 -299
  98. data/lib/vendor/workbox-v3.6.3/workbox-range-requests.dev.js.map +0 -1
  99. data/lib/vendor/workbox-v3.6.3/workbox-range-requests.prod.js +0 -3
  100. data/lib/vendor/workbox-v3.6.3/workbox-range-requests.prod.js.map +0 -1
  101. data/lib/vendor/workbox-v3.6.3/workbox-routing.dev.js +0 -863
  102. data/lib/vendor/workbox-v3.6.3/workbox-routing.dev.js.map +0 -1
  103. data/lib/vendor/workbox-v3.6.3/workbox-routing.prod.js +0 -3
  104. data/lib/vendor/workbox-v3.6.3/workbox-routing.prod.js.map +0 -1
  105. data/lib/vendor/workbox-v3.6.3/workbox-strategies.dev.js +0 -1172
  106. data/lib/vendor/workbox-v3.6.3/workbox-strategies.dev.js.map +0 -1
  107. data/lib/vendor/workbox-v3.6.3/workbox-strategies.prod.js +0 -3
  108. data/lib/vendor/workbox-v3.6.3/workbox-strategies.prod.js.map +0 -1
  109. data/lib/vendor/workbox-v3.6.3/workbox-streams.dev.js.map +0 -1
  110. data/lib/vendor/workbox-v3.6.3/workbox-streams.prod.js +0 -3
  111. data/lib/vendor/workbox-v3.6.3/workbox-streams.prod.js.map +0 -1
  112. data/lib/vendor/workbox-v3.6.3/workbox-sw.js +0 -3
  113. data/lib/vendor/workbox-v3.6.3/workbox-sw.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workbox-background-sync.dev.js","sources":["../_version.mjs","../lib/QueueStore.mjs","../lib/StorableRequest.mjs","../Queue.mjs","../Plugin.mjs","../index.mjs"],"sourcesContent":["try{self['workbox:background-sync:4.1.1']&&_()}catch(e){}// eslint-disable-line","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\n\nimport {assert} from 'workbox-core/_private/assert.mjs';\nimport {DBWrapper} from 'workbox-core/_private/DBWrapper.mjs';\nimport '../_version.mjs';\n\n\nconst DB_VERSION = 3;\nconst DB_NAME = 'workbox-background-sync';\nconst OBJECT_STORE_NAME = 'requests';\nconst INDEXED_PROP = 'queueName';\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 */\nexport 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 {string} queueName\n * @private\n */\n constructor(queueName) {\n this._queueName = queueName;\n this._db = new DBWrapper(DB_NAME, DB_VERSION, {\n onupgradeneeded: (evt) => this._upgradeDb(evt),\n });\n }\n\n /**\n * Append an entry last in the queue.\n *\n * @param {Object} entry\n * @param {Object} entry.requestData\n * @param {number} [entry.timestamp]\n * @param {Object} [entry.metadata]\n */\n async pushEntry(entry) {\n if (process.env.NODE_ENV !== 'production') {\n assert.isType(entry, 'object', {\n moduleName: 'workbox-background-sync',\n className: 'QueueStore',\n funcName: 'pushEntry',\n paramName: 'entry',\n });\n assert.isType(entry.requestData, 'object', {\n moduleName: 'workbox-background-sync',\n className: 'QueueStore',\n funcName: 'pushEntry',\n paramName: 'entry.requestData',\n });\n }\n\n // Don't specify an ID since one is automatically generated.\n delete entry.id;\n entry.queueName = this._queueName;\n\n await this._db.add(OBJECT_STORE_NAME, entry);\n }\n\n /**\n * Preppend an entry first in the queue.\n *\n * @param {Object} entry\n * @param {Object} entry.requestData\n * @param {number} [entry.timestamp]\n * @param {Object} [entry.metadata]\n */\n async unshiftEntry(entry) {\n if (process.env.NODE_ENV !== 'production') {\n assert.isType(entry, 'object', {\n moduleName: 'workbox-background-sync',\n className: 'QueueStore',\n funcName: 'unshiftEntry',\n paramName: 'entry',\n });\n assert.isType(entry.requestData, 'object', {\n moduleName: 'workbox-background-sync',\n className: 'QueueStore',\n funcName: 'unshiftEntry',\n paramName: 'entry.requestData',\n });\n }\n\n const [firstEntry] = await this._db.getAllMatching(OBJECT_STORE_NAME, {\n count: 1,\n });\n\n if (firstEntry) {\n // Pick an ID one less than the lowest ID in the object store.\n entry.id = firstEntry.id - 1;\n } else {\n delete entry.id;\n }\n entry.queueName = this._queueName;\n\n await this._db.add(OBJECT_STORE_NAME, entry);\n }\n\n /**\n * Removes and returns the last entry in the queue matching the `queueName`.\n *\n * @return {Promise<Object>}\n */\n async popEntry() {\n return this._removeEntry({direction: 'prev'});\n }\n\n /**\n * Removes and returns the first entry in the queue matching the `queueName`.\n *\n * @return {Promise<Object>}\n */\n async shiftEntry() {\n return this._removeEntry({direction: 'next'});\n }\n\n /**\n * Removes and returns the first or last entry in the queue (based on the\n * `direction` argument) matching the `queueName`.\n *\n * @return {Promise<Object>}\n */\n async _removeEntry({direction}) {\n const [entry] = await this._db.getAllMatching(OBJECT_STORE_NAME, {\n direction,\n index: INDEXED_PROP,\n query: IDBKeyRange.only(this._queueName),\n count: 1,\n });\n\n if (entry) {\n await this._db.delete(OBJECT_STORE_NAME, entry.id);\n\n // Dont' expose the ID or queueName;\n delete entry.id;\n delete entry.queueName;\n return entry;\n }\n }\n\n /**\n * Upgrades the database given an `upgradeneeded` event.\n *\n * @param {Event} event\n */\n _upgradeDb(event) {\n const db = event.target.result;\n\n if (event.oldVersion > 0 && event.oldVersion < DB_VERSION) {\n db.deleteObjectStore(OBJECT_STORE_NAME);\n }\n\n const objStore = db.createObjectStore(OBJECT_STORE_NAME, {\n autoIncrement: true,\n keyPath: 'id',\n });\n objStore.createIndex(INDEXED_PROP, INDEXED_PROP, {unique: false});\n }\n}\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\n\nimport {assert} from 'workbox-core/_private/assert.mjs';\nimport '../_version.mjs';\n\n\nconst serializableProperties = [\n 'method',\n 'referrer',\n 'referrerPolicy',\n 'mode',\n 'credentials',\n 'cache',\n 'redirect',\n 'integrity',\n 'keepalive',\n];\n\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 */\nclass 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 async fromRequest(request) {\n const requestData = {\n url: request.url,\n headers: {},\n };\n\n // Set the body if present.\n if (request.method !== 'GET') {\n // Use ArrayBuffer to support non-text request bodies.\n // NOTE: we can't use Blobs becuse Safari doesn't support storing\n // Blobs in IndexedDB in some cases:\n // https://github.com/dfahlander/Dexie.js/issues/618#issuecomment-398348457\n requestData.body = await request.clone().arrayBuffer();\n }\n\n // Convert the headers from an iterable to an object.\n for (const [key, value] of request.headers.entries()) {\n requestData.headers[key] = value;\n }\n\n // Add all other serializable request properties\n for (const prop of serializableProperties) {\n if (request[prop] !== undefined) {\n requestData[prop] = request[prop];\n }\n }\n\n return new StorableRequest(requestData);\n }\n\n /**\n * Accepts an object of request data that can be used to construct a\n * `Request` but can also be stored in IndexedDB.\n *\n * @param {Object} requestData An object of request data that includes the\n * `url` plus any relevant properties of\n * [requestInit]{@link https://fetch.spec.whatwg.org/#requestinit}.\n * @private\n */\n constructor(requestData) {\n if (process.env.NODE_ENV !== 'production') {\n assert.isType(requestData, 'object', {\n moduleName: 'workbox-background-sync',\n className: 'StorableRequest',\n funcName: 'constructor',\n paramName: 'requestData',\n });\n assert.isType(requestData.url, 'string', {\n moduleName: 'workbox-background-sync',\n className: 'StorableRequest',\n funcName: 'constructor',\n paramName: 'requestData.url',\n });\n }\n\n this._requestData = requestData;\n }\n\n /**\n * Returns a deep clone of the instances `_requestData` object.\n *\n * @return {Object}\n *\n * @private\n */\n toObject() {\n const requestData = Object.assign({}, this._requestData);\n requestData.headers = Object.assign({}, this._requestData.headers);\n if (requestData.body) {\n requestData.body = requestData.body.slice(0);\n }\n\n return requestData;\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._requestData.url, this._requestData);\n }\n\n /**\n * Creates and returns a deep clone of the instance.\n *\n * @return {StorableRequest}\n *\n * @private\n */\n clone() {\n return new StorableRequest(this.toObject());\n }\n}\n\nexport {StorableRequest};\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\n\nimport {WorkboxError} from 'workbox-core/_private/WorkboxError.mjs';\nimport {logger} from 'workbox-core/_private/logger.mjs';\nimport {assert} from 'workbox-core/_private/assert.mjs';\nimport {getFriendlyURL} from 'workbox-core/_private/getFriendlyURL.mjs';\nimport {QueueStore} from './lib/QueueStore.mjs';\nimport {StorableRequest} from './lib/StorableRequest.mjs';\nimport './_version.mjs';\n\n\nconst TAG_PREFIX = 'workbox-background-sync';\nconst MAX_RETENTION_TIME = 60 * 24 * 7; // 7 days in minutes\n\nconst 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 */\nclass 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 {Function} [options.onSync] A function that gets invoked whenever\n * the 'sync' event fires. The function is invoked with an object\n * containing the `queue` property (referencing this instance), and you\n * can use the callback to customize the replay behavior of the queue.\n * When not set the `replayRequests()` method is called.\n * Note: if the replay fails after a sync event, make sure you throw an\n * error, so the browser knows to retry the sync event later.\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, {onSync, maxRetentionTime} = {}) {\n // Ensure the store name is not already being used\n if (queueNames.has(name)) {\n throw new WorkboxError('duplicate-queue-name', {name});\n } else {\n queueNames.add(name);\n }\n\n this._name = name;\n this._onSync = onSync || this.replayRequests;\n this._maxRetentionTime = maxRetentionTime || MAX_RETENTION_TIME;\n this._queueStore = new QueueStore(this._name);\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 in IndexedDB (with its timestamp and any\n * metadata) at the end of the queue.\n *\n * @param {Object} entry\n * @param {Request} entry.request The request to store in the queue.\n * @param {Object} [entry.metadata] Any metadata you want associated with the\n * stored request. When requests are replayed you'll have access to this\n * metadata object in case you need to modify the request beforehand.\n * @param {number} [entry.timestamp] The timestamp (Epoch time in\n * milliseconds) when the request was first added to the queue. This is\n * used along with `maxRetentionTime` to remove outdated requests. In\n * general you don't need to set this value, as it's automatically set\n * for you (defaulting to `Date.now()`), but you can update it if you\n * don't want particular requests to expire.\n */\n async pushRequest(entry) {\n if (process.env.NODE_ENV !== 'production') {\n assert.isType(entry, 'object', {\n moduleName: 'workbox-background-sync',\n className: 'Queue',\n funcName: 'pushRequest',\n paramName: 'entry',\n });\n assert.isInstance(entry.request, Request, {\n moduleName: 'workbox-background-sync',\n className: 'Queue',\n funcName: 'pushRequest',\n paramName: 'entry.request',\n });\n }\n\n await this._addRequest(entry, 'push');\n }\n\n /**\n * Stores the passed request in IndexedDB (with its timestamp and any\n * metadata) at the beginning of the queue.\n *\n * @param {Object} entry\n * @param {Request} entry.request The request to store in the queue.\n * @param {Object} [entry.metadata] Any metadata you want associated with the\n * stored request. When requests are replayed you'll have access to this\n * metadata object in case you need to modify the request beforehand.\n * @param {number} [entry.timestamp] The timestamp (Epoch time in\n * milliseconds) when the request was first added to the queue. This is\n * used along with `maxRetentionTime` to remove outdated requests. In\n * general you don't need to set this value, as it's automatically set\n * for you (defaulting to `Date.now()`), but you can update it if you\n * don't want particular requests to expire.\n */\n async unshiftRequest(entry) {\n if (process.env.NODE_ENV !== 'production') {\n assert.isType(entry, 'object', {\n moduleName: 'workbox-background-sync',\n className: 'Queue',\n funcName: 'unshiftRequest',\n paramName: 'entry',\n });\n assert.isInstance(entry.request, Request, {\n moduleName: 'workbox-background-sync',\n className: 'Queue',\n funcName: 'unshiftRequest',\n paramName: 'entry.request',\n });\n }\n\n await this._addRequest(entry, 'unshift');\n }\n\n /**\n * Removes and returns the last request in the queue (along with its\n * timestamp and any metadata). The returned object takes the form:\n * `{request, timestamp, metadata}`.\n *\n * @return {Promise<Object>}\n */\n async popRequest() {\n return this._removeRequest('pop');\n }\n\n /**\n * Removes and returns the first request in the queue (along with its\n * timestamp and any metadata). The returned object takes the form:\n * `{request, timestamp, metadata}`.\n *\n * @return {Promise<Object>}\n */\n async shiftRequest() {\n return this._removeRequest('shift');\n }\n\n /**\n * Adds the entry to the QueueStore and registers for a sync event.\n *\n * @param {Object} entry\n * @param {Request} entry.request\n * @param {Object} [entry.metadata]\n * @param {number} [entry.timestamp=Date.now()]\n * @param {string} operation ('push' or 'unshift')\n */\n async _addRequest(\n {request, metadata, timestamp = Date.now()}, operation) {\n const storableRequest = await StorableRequest.fromRequest(request.clone());\n const entry = {\n requestData: storableRequest.toObject(),\n timestamp,\n };\n\n // Only include metadata if it's present.\n if (metadata) {\n entry.metadata = metadata;\n }\n\n await this._queueStore[`${operation}Entry`](entry);\n\n if (process.env.NODE_ENV !== 'production') {\n logger.log(`Request for '${getFriendlyURL(request.url)}' has ` +\n `been added to background sync queue '${this._name}'.`);\n }\n\n // Don't register for a sync if we're in the middle of a sync. Instead,\n // we wait until the sync is complete and call register if\n // `this._requestsAddedDuringSync` is true.\n if (this._syncInProgress) {\n this._requestsAddedDuringSync = true;\n } else {\n await this.registerSync();\n }\n }\n\n /**\n * Removes and returns the first or last (depending on `operation`) entry\n * form the QueueStore that's not older than the `maxRetentionTime`.\n *\n * @param {string} operation ('pop' or 'shift')\n * @return {Object|undefined}\n */\n async _removeRequest(operation) {\n const now = Date.now();\n const entry = await this._queueStore[`${operation}Entry`]();\n\n if (entry ) {\n // Ignore requests older than maxRetentionTime. Call this function\n // recursively until an unexpired request is found.\n const maxRetentionTimeInMs = this._maxRetentionTime * 60 * 1000;\n if (now - entry.timestamp > maxRetentionTimeInMs) {\n return this._removeRequest(operation);\n }\n\n entry.request = new StorableRequest(entry.requestData).toRequest();\n delete entry.requestData;\n\n return entry;\n }\n }\n\n /**\n * Loops through each request in the queue and attempts to re-fetch it.\n * If any request fails to re-fetch, it's put back in the same position in\n * the queue (which registers a retry for the next sync event).\n */\n async replayRequests() {\n let entry;\n while (entry = await this.shiftRequest()) {\n try {\n await fetch(entry.request);\n\n if (process.env.NODE_ENV !== 'production') {\n logger.log(`Request for '${getFriendlyURL(entry.request.url)}'` +\n `has been replayed in queue '${this._name}'`);\n }\n } catch (error) {\n await this.unshiftRequest(entry);\n\n if (process.env.NODE_ENV !== 'production') {\n logger.log(`Request for '${getFriendlyURL(entry.request.url)}'` +\n `failed to replay, putting it back in queue '${this._name}'`);\n }\n throw new WorkboxError('queue-replay-failed', {name: this._name});\n }\n }\n if (process.env.NODE_ENV !== 'production') {\n logger.log(`All requests in queue '${this.name}' have successfully ` +\n `replayed; the queue is now empty!`);\n }\n }\n\n /**\n * Registers a sync event with a tag unique to this instance.\n */\n async registerSync() {\n if ('sync' in registration) {\n try {\n await registration.sync.register(`${TAG_PREFIX}:${this._name}`);\n } catch (err) {\n // This means the registration failed for some reason, possibly due to\n // the user disabling it.\n if (process.env.NODE_ENV !== 'production') {\n logger.warn(\n `Unable to register sync event for '${this._name}'.`, err);\n }\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 if (process.env.NODE_ENV !== 'production') {\n logger.log(`Background sync for tag '${event.tag}'` +\n `has been received`);\n }\n\n const syncComplete = async () => {\n this._syncInProgress = true;\n\n let syncError;\n try {\n await this._onSync({queue: this});\n } catch (error) {\n syncError = error;\n\n // Rethrow the error. Note: the logic in the finally clause\n // will run before this gets rethrown.\n throw syncError;\n } finally {\n // New items may have been added to the queue during the sync,\n // so we need to register for a new sync if that's happened...\n // Unless there was an error during the sync, in which\n // case the browser will automatically retry later, as long\n // as `event.lastChance` is not true.\n if (this._requestsAddedDuringSync &&\n !(syncError && !event.lastChance)) {\n await this.registerSync();\n }\n\n this._syncInProgress = false;\n this._requestsAddedDuringSync = false;\n }\n };\n event.waitUntil(syncComplete());\n }\n });\n } else {\n if (process.env.NODE_ENV !== 'production') {\n 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._onSync({queue: this});\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\nexport {Queue};\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\n\nimport {Queue} from './Queue.mjs';\nimport './_version.mjs';\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 */\nclass 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 async fetchDidFail({request}) {\n await this._queue.pushRequest({request});\n }\n}\n\nexport {Plugin};\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\n\nimport {Queue} from './Queue.mjs';\nimport {Plugin} from './Plugin.mjs';\nimport './_version.mjs';\n\n\n/**\n * @namespace workbox.backgroundSync\n */\n\nexport {\n Queue,\n Plugin,\n};\n"],"names":["self","_","e","DB_VERSION","DB_NAME","OBJECT_STORE_NAME","INDEXED_PROP","QueueStore","constructor","queueName","_queueName","_db","DBWrapper","onupgradeneeded","evt","_upgradeDb","pushEntry","entry","assert","isType","moduleName","className","funcName","paramName","requestData","id","add","unshiftEntry","firstEntry","getAllMatching","count","popEntry","_removeEntry","direction","shiftEntry","index","query","IDBKeyRange","only","delete","event","db","target","result","oldVersion","deleteObjectStore","objStore","createObjectStore","autoIncrement","keyPath","createIndex","unique","serializableProperties","StorableRequest","fromRequest","request","url","headers","method","body","clone","arrayBuffer","key","value","entries","prop","undefined","_requestData","toObject","Object","assign","slice","toRequest","Request","TAG_PREFIX","MAX_RETENTION_TIME","queueNames","Set","Queue","name","onSync","maxRetentionTime","has","WorkboxError","_name","_onSync","replayRequests","_maxRetentionTime","_queueStore","_addSyncListener","pushRequest","isInstance","_addRequest","unshiftRequest","popRequest","_removeRequest","shiftRequest","metadata","timestamp","Date","now","operation","storableRequest","logger","log","getFriendlyURL","_syncInProgress","_requestsAddedDuringSync","registerSync","maxRetentionTimeInMs","fetch","error","registration","sync","register","err","warn","addEventListener","tag","syncComplete","syncError","queue","lastChance","waitUntil","_queueNames","Plugin","queueArgs","_queue","fetchDidFail","bind"],"mappings":";;;;EAAA,IAAG;EAACA,EAAAA,IAAI,CAAC,+BAAD,CAAJ,IAAuCC,CAAC,EAAxC;EAA2C,CAA/C,CAA+C,OAAMC,CAAN,EAAQ;;ECAvD;;;;;;;AAQA,EAKA,MAAMC,UAAU,GAAG,CAAnB;EACA,MAAMC,OAAO,GAAG,yBAAhB;EACA,MAAMC,iBAAiB,GAAG,UAA1B;EACA,MAAMC,YAAY,GAAG,WAArB;EAEA;;;;;;;AAMA,EAAO,MAAMC,UAAN,CAAiB;EACtB;;;;;;;EAOAC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ACuC;EACrC,sBAAM,KAAKd,YAAL,EAAN;EACD;;EAED,mBAAKF,eAAL,GAAuB,KAAvB;EACA,mBAAKC,wBAAL,GAAgC,KAAhC;EACD;EACF,WA1BD;;EA2BAnE,UAAAA,KAAK,CAACmF,SAAN,CAAgBJ,YAAY,EAA5B;EACD;EACF,OApCD;EAqCD,KAtCD,MAsCO;EACL,MAA2C;EACzChB,QAAAA,iBAAM,CAACC,GAAP,CAAY,yDAAZ;EACD,OAHI;EAKL;;;EACA,WAAKnB,OAAL,CAAa;EAACoC,QAAAA,KAAK,EAAE;EAAR,OAAb;EACD;EACF;EAED;;;;;;;;;;EAQA,aAAWG,WAAX,GAAyB;EACvB,WAAOhD,UAAP;EACD;;EA3TS;;EC7BZ;;;;;;;AAQA,EAGA;;;;;;;EAMA,MAAMiD,MAAN,CAAa;EACX;;;;;EAKArH,EAAAA,WAAW,CAAC,GAAGsH,SAAJ,EAAe;EACxB,SAAKC,MAAL,GAAc,IAAIjD,KAAJ,CAAU,GAAGgD,SAAb,CAAd;EACA,SAAKE,YAAL,GAAoB,KAAKA,YAAL,CAAkBC,IAAlB,CAAuB,IAAvB,CAApB;EACD;EAED;;;;;;;EAKA,QAAMD,YAAN,CAAmB;EAACzE,IAAAA;EAAD,GAAnB,EAA8B;EAC5B,UAAM,KAAKwE,MAAL,CAAYrC,WAAZ,CAAwB;EAACnC,MAAAA;EAAD,KAAxB,CAAN;EACD;;EAlBU;;ECjBb;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,2 @@
1
+ this.workbox=this.workbox||{},this.workbox.backgroundSync=function(t,e,s){"use strict";try{self["workbox:background-sync:4.1.1"]&&_()}catch(t){}const i=3,n="workbox-background-sync",a="requests",r="queueName";class c{constructor(t){this.t=t,this.s=new s.DBWrapper(n,i,{onupgradeneeded:t=>this.i(t)})}async pushEntry(t){delete t.id,t.queueName=this.t,await this.s.add(a,t)}async unshiftEntry(t){const[e]=await this.s.getAllMatching(a,{count:1});e?t.id=e.id-1:delete t.id,t.queueName=this.t,await this.s.add(a,t)}async popEntry(){return this.h({direction:"prev"})}async shiftEntry(){return this.h({direction:"next"})}async h({direction:t}){const[e]=await this.s.getAllMatching(a,{direction:t,index:r,query:IDBKeyRange.only(this.t),count:1});if(e)return await this.s.delete(a,e.id),delete e.id,delete e.queueName,e}i(t){const e=t.target.result;t.oldVersion>0&&t.oldVersion<i&&e.deleteObjectStore(a),e.createObjectStore(a,{autoIncrement:!0,keyPath:"id"}).createIndex(r,r,{unique:!1})}}const h=["method","referrer","referrerPolicy","mode","credentials","cache","redirect","integrity","keepalive"];class o{static async fromRequest(t){const e={url:t.url,headers:{}};"GET"!==t.method&&(e.body=await t.clone().arrayBuffer());for(const[s,i]of t.headers.entries())e.headers[s]=i;for(const s of h)void 0!==t[s]&&(e[s]=t[s]);return new o(e)}constructor(t){this.o=t}toObject(){const t=Object.assign({},this.o);return t.headers=Object.assign({},this.o.headers),t.body&&(t.body=t.body.slice(0)),t}toRequest(){return new Request(this.o.url,this.o)}clone(){return new o(this.toObject())}}const u="workbox-background-sync",y=10080,w=new Set;class d{constructor(t,{onSync:s,maxRetentionTime:i}={}){if(w.has(t))throw new e.WorkboxError("duplicate-queue-name",{name:t});w.add(t),this.u=t,this.l=s||this.replayRequests,this.q=i||y,this.m=new c(this.u),this.p()}get name(){return this.u}async pushRequest(t){await this.g(t,"push")}async unshiftRequest(t){await this.g(t,"unshift")}async popRequest(){return this.R("pop")}async shiftRequest(){return this.R("shift")}async g({request:t,metadata:e,timestamp:s=Date.now()},i){const n={requestData:(await o.fromRequest(t.clone())).toObject(),timestamp:s};e&&(n.metadata=e),await this.m[`${i}Entry`](n),this.k?this._=!0:await this.registerSync()}async R(t){const e=Date.now(),s=await this.m[`${t}Entry`]();if(s){const i=60*this.q*1e3;return e-s.timestamp>i?this.R(t):(s.request=new o(s.requestData).toRequest(),delete s.requestData,s)}}async replayRequests(){let t;for(;t=await this.shiftRequest();)try{await fetch(t.request)}catch(s){throw await this.unshiftRequest(t),new e.WorkboxError("queue-replay-failed",{name:this.u})}}async registerSync(){if("sync"in registration)try{await registration.sync.register(`${u}:${this.u}`)}catch(t){}}p(){"sync"in registration?self.addEventListener("sync",t=>{if(t.tag===`${u}:${this.u}`){const e=async()=>{let e;this.k=!0;try{await this.l({queue:this})}catch(t){throw e=t}finally{!this._||e&&!t.lastChance||await this.registerSync(),this.k=!1,this._=!1}};t.waitUntil(e())}}):this.l({queue:this})}static get D(){return w}}return t.Queue=d,t.Plugin=class{constructor(...t){this.$=new d(...t),this.fetchDidFail=this.fetchDidFail.bind(this)}async fetchDidFail({request:t}){await this.$.pushRequest({request:t})}},t}({},workbox.core._private,workbox.core._private);
2
+ //# sourceMappingURL=workbox-background-sync.prod.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workbox-background-sync.prod.js","sources":["../_version.mjs","../lib/QueueStore.mjs","../lib/StorableRequest.mjs","../Queue.mjs","../Plugin.mjs"],"sourcesContent":["try{self['workbox:background-sync:4.1.1']&&_()}catch(e){}// eslint-disable-line","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\n\nimport {assert} from 'workbox-core/_private/assert.mjs';\nimport {DBWrapper} from 'workbox-core/_private/DBWrapper.mjs';\nimport '../_version.mjs';\n\n\nconst DB_VERSION = 3;\nconst DB_NAME = 'workbox-background-sync';\nconst OBJECT_STORE_NAME = 'requests';\nconst INDEXED_PROP = 'queueName';\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 */\nexport 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 {string} queueName\n * @private\n */\n constructor(queueName) {\n this._queueName = queueName;\n this._db = new DBWrapper(DB_NAME, DB_VERSION, {\n onupgradeneeded: (evt) => this._upgradeDb(evt),\n });\n }\n\n /**\n * Append an entry last in the queue.\n *\n * @param {Object} entry\n * @param {Object} entry.requestData\n * @param {number} [entry.timestamp]\n * @param {Object} [entry.metadata]\n */\n async pushEntry(entry) {\n if (process.env.NODE_ENV !== 'production') {\n assert.isType(entry, 'object', {\n moduleName: 'workbox-background-sync',\n className: 'QueueStore',\n funcName: 'pushEntry',\n paramName: 'entry',\n });\n assert.isType(entry.requestData, 'object', {\n moduleName: 'workbox-background-sync',\n className: 'QueueStore',\n funcName: 'pushEntry',\n paramName: 'entry.requestData',\n });\n }\n\n // Don't specify an ID since one is automatically generated.\n delete entry.id;\n entry.queueName = this._queueName;\n\n await this._db.add(OBJECT_STORE_NAME, entry);\n }\n\n /**\n * Preppend an entry first in the queue.\n *\n * @param {Object} entry\n * @param {Object} entry.requestData\n * @param {number} [entry.timestamp]\n * @param {Object} [entry.metadata]\n */\n async unshiftEntry(entry) {\n if (process.env.NODE_ENV !== 'production') {\n assert.isType(entry, 'object', {\n moduleName: 'workbox-background-sync',\n className: 'QueueStore',\n funcName: 'unshiftEntry',\n paramName: 'entry',\n });\n assert.isType(entry.requestData, 'object', {\n moduleName: 'workbox-background-sync',\n className: 'QueueStore',\n funcName: 'unshiftEntry',\n paramName: 'entry.requestData',\n });\n }\n\n const [firstEntry] = await this._db.getAllMatching(OBJECT_STORE_NAME, {\n count: 1,\n });\n\n if (firstEntry) {\n // Pick an ID one less than the lowest ID in the object store.\n entry.id = firstEntry.id - 1;\n } else {\n delete entry.id;\n }\n entry.queueName = this._queueName;\n\n await this._db.add(OBJECT_STORE_NAME, entry);\n }\n\n /**\n * Removes and returns the last entry in the queue matching the `queueName`.\n *\n * @return {Promise<Object>}\n */\n async popEntry() {\n return this._removeEntry({direction: 'prev'});\n }\n\n /**\n * Removes and returns the first entry in the queue matching the `queueName`.\n *\n * @return {Promise<Object>}\n */\n async shiftEntry() {\n return this._removeEntry({direction: 'next'});\n }\n\n /**\n * Removes and returns the first or last entry in the queue (based on the\n * `direction` argument) matching the `queueName`.\n *\n * @return {Promise<Object>}\n */\n async _removeEntry({direction}) {\n const [entry] = await this._db.getAllMatching(OBJECT_STORE_NAME, {\n direction,\n index: INDEXED_PROP,\n query: IDBKeyRange.only(this._queueName),\n count: 1,\n });\n\n if (entry) {\n await this._db.delete(OBJECT_STORE_NAME, entry.id);\n\n // Dont' expose the ID or queueName;\n delete entry.id;\n delete entry.queueName;\n return entry;\n }\n }\n\n /**\n * Upgrades the database given an `upgradeneeded` event.\n *\n * @param {Event} event\n */\n _upgradeDb(event) {\n const db = event.target.result;\n\n if (event.oldVersion > 0 && event.oldVersion < DB_VERSION) {\n db.deleteObjectStore(OBJECT_STORE_NAME);\n }\n\n const objStore = db.createObjectStore(OBJECT_STORE_NAME, {\n autoIncrement: true,\n keyPath: 'id',\n });\n objStore.createIndex(INDEXED_PROP, INDEXED_PROP, {unique: false});\n }\n}\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\n\nimport {assert} from 'workbox-core/_private/assert.mjs';\nimport '../_version.mjs';\n\n\nconst serializableProperties = [\n 'method',\n 'referrer',\n 'referrerPolicy',\n 'mode',\n 'credentials',\n 'cache',\n 'redirect',\n 'integrity',\n 'keepalive',\n];\n\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 */\nclass 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 async fromRequest(request) {\n const requestData = {\n url: request.url,\n headers: {},\n };\n\n // Set the body if present.\n if (request.method !== 'GET') {\n // Use ArrayBuffer to support non-text request bodies.\n // NOTE: we can't use Blobs becuse Safari doesn't support storing\n // Blobs in IndexedDB in some cases:\n // https://github.com/dfahlander/Dexie.js/issues/618#issuecomment-398348457\n requestData.body = await request.clone().arrayBuffer();\n }\n\n // Convert the headers from an iterable to an object.\n for (const [key, value] of request.headers.entries()) {\n requestData.headers[key] = value;\n }\n\n // Add all other serializable request properties\n for (const prop of serializableProperties) {\n if (request[prop] !== undefined) {\n requestData[prop] = request[prop];\n }\n }\n\n return new StorableRequest(requestData);\n }\n\n /**\n * Accepts an object of request data that can be used to construct a\n * `Request` but can also be stored in IndexedDB.\n *\n * @param {Object} requestData An object of request data that includes the\n * `url` plus any relevant properties of\n * [requestInit]{@link https://fetch.spec.whatwg.org/#requestinit}.\n * @private\n */\n constructor(requestData) {\n if (process.env.NODE_ENV !== 'production') {\n assert.isType(requestData, 'object', {\n moduleName: 'workbox-background-sync',\n className: 'StorableRequest',\n funcName: 'constructor',\n paramName: 'requestData',\n });\n assert.isType(requestData.url, 'string', {\n moduleName: 'workbox-background-sync',\n className: 'StorableRequest',\n funcName: 'constructor',\n paramName: 'requestData.url',\n });\n }\n\n this._requestData = requestData;\n }\n\n /**\n * Returns a deep clone of the instances `_requestData` object.\n *\n * @return {Object}\n *\n * @private\n */\n toObject() {\n const requestData = Object.assign({}, this._requestData);\n requestData.headers = Object.assign({}, this._requestData.headers);\n if (requestData.body) {\n requestData.body = requestData.body.slice(0);\n }\n\n return requestData;\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._requestData.url, this._requestData);\n }\n\n /**\n * Creates and returns a deep clone of the instance.\n *\n * @return {StorableRequest}\n *\n * @private\n */\n clone() {\n return new StorableRequest(this.toObject());\n }\n}\n\nexport {StorableRequest};\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\n\nimport {WorkboxError} from 'workbox-core/_private/WorkboxError.mjs';\nimport {logger} from 'workbox-core/_private/logger.mjs';\nimport {assert} from 'workbox-core/_private/assert.mjs';\nimport {getFriendlyURL} from 'workbox-core/_private/getFriendlyURL.mjs';\nimport {QueueStore} from './lib/QueueStore.mjs';\nimport {StorableRequest} from './lib/StorableRequest.mjs';\nimport './_version.mjs';\n\n\nconst TAG_PREFIX = 'workbox-background-sync';\nconst MAX_RETENTION_TIME = 60 * 24 * 7; // 7 days in minutes\n\nconst 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 */\nclass 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 {Function} [options.onSync] A function that gets invoked whenever\n * the 'sync' event fires. The function is invoked with an object\n * containing the `queue` property (referencing this instance), and you\n * can use the callback to customize the replay behavior of the queue.\n * When not set the `replayRequests()` method is called.\n * Note: if the replay fails after a sync event, make sure you throw an\n * error, so the browser knows to retry the sync event later.\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, {onSync, maxRetentionTime} = {}) {\n // Ensure the store name is not already being used\n if (queueNames.has(name)) {\n throw new WorkboxError('duplicate-queue-name', {name});\n } else {\n queueNames.add(name);\n }\n\n this._name = name;\n this._onSync = onSync || this.replayRequests;\n this._maxRetentionTime = maxRetentionTime || MAX_RETENTION_TIME;\n this._queueStore = new QueueStore(this._name);\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 in IndexedDB (with its timestamp and any\n * metadata) at the end of the queue.\n *\n * @param {Object} entry\n * @param {Request} entry.request The request to store in the queue.\n * @param {Object} [entry.metadata] Any metadata you want associated with the\n * stored request. When requests are replayed you'll have access to this\n * metadata object in case you need to modify the request beforehand.\n * @param {number} [entry.timestamp] The timestamp (Epoch time in\n * milliseconds) when the request was first added to the queue. This is\n * used along with `maxRetentionTime` to remove outdated requests. In\n * general you don't need to set this value, as it's automatically set\n * for you (defaulting to `Date.now()`), but you can update it if you\n * don't want particular requests to expire.\n */\n async pushRequest(entry) {\n if (process.env.NODE_ENV !== 'production') {\n assert.isType(entry, 'object', {\n moduleName: 'workbox-background-sync',\n className: 'Queue',\n funcName: 'pushRequest',\n paramName: 'entry',\n });\n assert.isInstance(entry.request, Request, {\n moduleName: 'workbox-background-sync',\n className: 'Queue',\n funcName: 'pushRequest',\n paramName: 'entry.request',\n });\n }\n\n await this._addRequest(entry, 'push');\n }\n\n /**\n * Stores the passed request in IndexedDB (with its timestamp and any\n * metadata) at the beginning of the queue.\n *\n * @param {Object} entry\n * @param {Request} entry.request The request to store in the queue.\n * @param {Object} [entry.metadata] Any metadata you want associated with the\n * stored request. When requests are replayed you'll have access to this\n * metadata object in case you need to modify the request beforehand.\n * @param {number} [entry.timestamp] The timestamp (Epoch time in\n * milliseconds) when the request was first added to the queue. This is\n * used along with `maxRetentionTime` to remove outdated requests. In\n * general you don't need to set this value, as it's automatically set\n * for you (defaulting to `Date.now()`), but you can update it if you\n * don't want particular requests to expire.\n */\n async unshiftRequest(entry) {\n if (process.env.NODE_ENV !== 'production') {\n assert.isType(entry, 'object', {\n moduleName: 'workbox-background-sync',\n className: 'Queue',\n funcName: 'unshiftRequest',\n paramName: 'entry',\n });\n assert.isInstance(entry.request, Request, {\n moduleName: 'workbox-background-sync',\n className: 'Queue',\n funcName: 'unshiftRequest',\n paramName: 'entry.request',\n });\n }\n\n await this._addRequest(entry, 'unshift');\n }\n\n /**\n * Removes and returns the last request in the queue (along with its\n * timestamp and any metadata). The returned object takes the form:\n * `{request, timestamp, metadata}`.\n *\n * @return {Promise<Object>}\n */\n async popRequest() {\n return this._removeRequest('pop');\n }\n\n /**\n * Removes and returns the first request in the queue (along with its\n * timestamp and any metadata). The returned object takes the form:\n * `{request, timestamp, metadata}`.\n *\n * @return {Promise<Object>}\n */\n async shiftRequest() {\n return this._removeRequest('shift');\n }\n\n /**\n * Adds the entry to the QueueStore and registers for a sync event.\n *\n * @param {Object} entry\n * @param {Request} entry.request\n * @param {Object} [entry.metadata]\n * @param {number} [entry.timestamp=Date.now()]\n * @param {string} operation ('push' or 'unshift')\n */\n async _addRequest(\n {request, metadata, timestamp = Date.now()}, operation) {\n const storableRequest = await StorableRequest.fromRequest(request.clone());\n const entry = {\n requestData: storableRequest.toObject(),\n timestamp,\n };\n\n // Only include metadata if it's present.\n if (metadata) {\n entry.metadata = metadata;\n }\n\n await this._queueStore[`${operation}Entry`](entry);\n\n if (process.env.NODE_ENV !== 'production') {\n logger.log(`Request for '${getFriendlyURL(request.url)}' has ` +\n `been added to background sync queue '${this._name}'.`);\n }\n\n // Don't register for a sync if we're in the middle of a sync. Instead,\n // we wait until the sync is complete and call register if\n // `this._requestsAddedDuringSync` is true.\n if (this._syncInProgress) {\n this._requestsAddedDuringSync = true;\n } else {\n await this.registerSync();\n }\n }\n\n /**\n * Removes and returns the first or last (depending on `operation`) entry\n * form the QueueStore that's not older than the `maxRetentionTime`.\n *\n * @param {string} operation ('pop' or 'shift')\n * @return {Object|undefined}\n */\n async _removeRequest(operation) {\n const now = Date.now();\n const entry = await this._queueStore[`${operation}Entry`]();\n\n if (entry ) {\n // Ignore requests older than maxRetentionTime. Call this function\n // recursively until an unexpired request is found.\n const maxRetentionTimeInMs = this._maxRetentionTime * 60 * 1000;\n if (now - entry.timestamp > maxRetentionTimeInMs) {\n return this._removeRequest(operation);\n }\n\n entry.request = new StorableRequest(entry.requestData).toRequest();\n delete entry.requestData;\n\n return entry;\n }\n }\n\n /**\n * Loops through each request in the queue and attempts to re-fetch it.\n * If any request fails to re-fetch, it's put back in the same position in\n * the queue (which registers a retry for the next sync event).\n */\n async replayRequests() {\n let entry;\n while (entry = await this.shiftRequest()) {\n try {\n await fetch(entry.request);\n\n if (process.env.NODE_ENV !== 'production') {\n logger.log(`Request for '${getFriendlyURL(entry.request.url)}'` +\n `has been replayed in queue '${this._name}'`);\n }\n } catch (error) {\n await this.unshiftRequest(entry);\n\n if (process.env.NODE_ENV !== 'production') {\n logger.log(`Request for '${getFriendlyURL(entry.request.url)}'` +\n `failed to replay, putting it back in queue '${this._name}'`);\n }\n throw new WorkboxError('queue-replay-failed', {name: this._name});\n }\n }\n if (process.env.NODE_ENV !== 'production') {\n logger.log(`All requests in queue '${this.name}' have successfully ` +\n `replayed; the queue is now empty!`);\n }\n }\n\n /**\n * Registers a sync event with a tag unique to this instance.\n */\n async registerSync() {\n if ('sync' in registration) {\n try {\n await registration.sync.register(`${TAG_PREFIX}:${this._name}`);\n } catch (err) {\n // This means the registration failed for some reason, possibly due to\n // the user disabling it.\n if (process.env.NODE_ENV !== 'production') {\n logger.warn(\n `Unable to register sync event for '${this._name}'.`, err);\n }\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 if (process.env.NODE_ENV !== 'production') {\n logger.log(`Background sync for tag '${event.tag}'` +\n `has been received`);\n }\n\n const syncComplete = async () => {\n this._syncInProgress = true;\n\n let syncError;\n try {\n await this._onSync({queue: this});\n } catch (error) {\n syncError = error;\n\n // Rethrow the error. Note: the logic in the finally clause\n // will run before this gets rethrown.\n throw syncError;\n } finally {\n // New items may have been added to the queue during the sync,\n // so we need to register for a new sync if that's happened...\n // Unless there was an error during the sync, in which\n // case the browser will automatically retry later, as long\n // as `event.lastChance` is not true.\n if (this._requestsAddedDuringSync &&\n !(syncError && !event.lastChance)) {\n await this.registerSync();\n }\n\n this._syncInProgress = false;\n this._requestsAddedDuringSync = false;\n }\n };\n event.waitUntil(syncComplete());\n }\n });\n } else {\n if (process.env.NODE_ENV !== 'production') {\n 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._onSync({queue: this});\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\nexport {Queue};\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\n\nimport {Queue} from './Queue.mjs';\nimport './_version.mjs';\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 */\nclass 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 async fetchDidFail({request}) {\n await this._queue.pushRequest({request});\n }\n}\n\nexport {Plugin};\n"],"names":["self","_","e","DB_VERSION","DB_NAME","OBJECT_STORE_NAME","INDEXED_PROP","QueueStore","constructor","queueName","_queueName","_db","DBWrapper","onupgradeneeded","evt","this","_upgradeDb","entry","id","add","firstEntry","getAllMatching","count","_removeEntry","direction","index","query","IDBKeyRange","only","delete","event","db","target","result","oldVersion","deleteObjectStore","createObjectStore","autoIncrement","keyPath","createIndex","unique","serializableProperties","StorableRequest","request","requestData","url","headers","method","body","clone","arrayBuffer","key","value","entries","prop","undefined","_requestData","toObject","Object","assign","slice","toRequest","Request","TAG_PREFIX","MAX_RETENTION_TIME","queueNames","Set","Queue","name","onSync","maxRetentionTime","has","WorkboxError","_name","_onSync","replayRequests","_maxRetentionTime","_queueStore","_addSyncListener","_addRequest","_removeRequest","metadata","timestamp","Date","now","operation","fromRequest","_syncInProgress","_requestsAddedDuringSync","registerSync","maxRetentionTimeInMs","shiftRequest","fetch","error","unshiftRequest","registration","sync","register","err","addEventListener","tag","syncComplete","async","syncError","queue","lastChance","waitUntil","queueArg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A2B,QAE1BzE,KAAK0E,uBAWMJ,SACbD,EAAMD,KAAKC,MACXnE,QAAcF,KAAK8D,KAAeQ,eAEpCpE,EAAQ,OAGJyE,EAAgD,GAAzB3E,KAAK6D,EAAyB,WACvDQ,EAAMnE,EAAMiE,UAAYQ,EACnB3E,KAAKiE,EAAeK,IAG7BpE,EAAM0B,QAAU,IAAID,EAAgBzB,EAAM2B,aAAaiB,mBAChD5C,EAAM2B,YAEN3B,+BAULA,OACGA,QAAcF,KAAK4E,0BAEhBC,MAAM3E,EAAM0B,SAMlB,MAAOkD,eACD9E,KAAK+E,eAAe7E,GAMpB,IAAIuD,eAAa,sBAAuB,CAACJ,KAAMrD,KAAK0D,6BAa1D,SAAUsB,uBAEJA,aAAaC,KAAKC,YAAYlC,KAAchD,KAAK0D,KACvD,MAAOyB,KAkBbpB,IACM,SAAUiB,aACZ/F,KAAKmG,iBAAiB,OAASrE,OACzBA,EAAMsE,SAAWrC,KAAchD,KAAK0D,IAAS,OAMzC4B,EAAeC,cAGfC,OAFChB,GAAkB,YAIfxE,KAAK2D,EAAQ,CAAC8B,MAAOzF,OAC3B,MAAO8E,SACPU,EAAYV,WAWR9E,KAAKyE,GACHe,IAAczE,EAAM2E,kBAClB1F,KAAK0E,oBAGRF,GAAkB,OAClBC,GAA2B,IAGpC1D,EAAM4E,UAAUL,aASf3B,EAAQ,CAAC8B,MAAOzF,6BAahBkD,6BCtUX,MAMEzD,eAAemG,QACRC,EAAS,IAAIzC,KAASwC,QACtBE,aAAe9F,KAAK8F,aAAaC,KAAK/F,0BAQ1B4B,QAACA,UACZ5B,KAAK6F,EAAOG,YAAY,CAACpE,QAAAA"}
@@ -0,0 +1,482 @@
1
+ this.workbox = this.workbox || {};
2
+ this.workbox.broadcastUpdate = (function (exports, assert_mjs, getFriendlyURL_mjs, logger_mjs, Deferred_mjs, WorkboxError_mjs) {
3
+ 'use strict';
4
+
5
+ try {
6
+ self['workbox:broadcast-update:4.1.1'] && _();
7
+ } catch (e) {} // eslint-disable-line
8
+
9
+ /*
10
+ Copyright 2018 Google LLC
11
+
12
+ Use of this source code is governed by an MIT-style
13
+ license that can be found in the LICENSE file or at
14
+ https://opensource.org/licenses/MIT.
15
+ */
16
+ /**
17
+ * Given two `Response's`, compares several header values to see if they are
18
+ * the same or not.
19
+ *
20
+ * @param {Response} firstResponse
21
+ * @param {Response} secondResponse
22
+ * @param {Array<string>} headersToCheck
23
+ * @return {boolean}
24
+ *
25
+ * @memberof workbox.broadcastUpdate
26
+ * @private
27
+ */
28
+
29
+ const responsesAreSame = (firstResponse, secondResponse, headersToCheck) => {
30
+ {
31
+ if (!(firstResponse instanceof Response && secondResponse instanceof Response)) {
32
+ throw new WorkboxError_mjs.WorkboxError('invalid-responses-are-same-args');
33
+ }
34
+ }
35
+
36
+ const atLeastOneHeaderAvailable = headersToCheck.some(header => {
37
+ return firstResponse.headers.has(header) && secondResponse.headers.has(header);
38
+ });
39
+
40
+ if (!atLeastOneHeaderAvailable) {
41
+ {
42
+ logger_mjs.logger.warn(`Unable to determine where the response has been updated ` + `because none of the headers that would be checked are present.`);
43
+ logger_mjs.logger.debug(`Attempting to compare the following: `, firstResponse, secondResponse, headersToCheck);
44
+ } // Just return true, indicating the that responses are the same, since we
45
+ // can't determine otherwise.
46
+
47
+
48
+ return true;
49
+ }
50
+
51
+ return headersToCheck.every(header => {
52
+ const headerStateComparison = firstResponse.headers.has(header) === secondResponse.headers.has(header);
53
+ const headerValueComparison = firstResponse.headers.get(header) === secondResponse.headers.get(header);
54
+ return headerStateComparison && headerValueComparison;
55
+ });
56
+ };
57
+
58
+ /*
59
+ Copyright 2018 Google LLC
60
+
61
+ Use of this source code is governed by an MIT-style
62
+ license that can be found in the LICENSE file or at
63
+ https://opensource.org/licenses/MIT.
64
+ */
65
+ const CACHE_UPDATED_MESSAGE_TYPE = 'CACHE_UPDATED';
66
+ const CACHE_UPDATED_MESSAGE_META = 'workbox-broadcast-update';
67
+ const DEFAULT_BROADCAST_CHANNEL_NAME = 'workbox';
68
+ const DEFAULT_DEFER_NOTIFICATION_TIMEOUT = 10000;
69
+ const DEFAULT_HEADERS_TO_CHECK = ['content-length', 'etag', 'last-modified'];
70
+
71
+ /*
72
+ Copyright 2018 Google LLC
73
+
74
+ Use of this source code is governed by an MIT-style
75
+ license that can be found in the LICENSE file or at
76
+ https://opensource.org/licenses/MIT.
77
+ */
78
+ /**
79
+ * You would not normally call this method directly; it's called automatically
80
+ * by an instance of the {@link BroadcastCacheUpdate} class. It's exposed here
81
+ * for the benefit of developers who would rather not use the full
82
+ * `BroadcastCacheUpdate` implementation.
83
+ *
84
+ * Calling this will dispatch a message on the provided
85
+ * {@link https://developers.google.com/web/updates/2016/09/broadcastchannel|Broadcast Channel}
86
+ * to notify interested subscribers about a change to a cached resource.
87
+ *
88
+ * The message that's posted has a formation inspired by the
89
+ * [Flux standard action](https://github.com/acdlite/flux-standard-action#introduction)
90
+ * format like so:
91
+ *
92
+ * ```
93
+ * {
94
+ * type: 'CACHE_UPDATED',
95
+ * meta: 'workbox-broadcast-update',
96
+ * payload: {
97
+ * cacheName: 'the-cache-name',
98
+ * updatedURL: 'https://example.com/'
99
+ * }
100
+ * }
101
+ * ```
102
+ *
103
+ * (Usage of [Flux](https://facebook.github.io/flux/) itself is not at
104
+ * all required.)
105
+ *
106
+ * @param {Object} options
107
+ * @param {string} options.cacheName The name of the cache in which the updated
108
+ * `Response` was stored.
109
+ * @param {string} options.url The URL associated with the updated `Response`.
110
+ * @param {BroadcastChannel} [options.channel] The `BroadcastChannel` to use.
111
+ * If no channel is set or the browser doesn't support the BroadcastChannel
112
+ * api, then an attempt will be made to `postMessage` each window client.
113
+ *
114
+ * @memberof workbox.broadcastUpdate
115
+ */
116
+
117
+ const broadcastUpdate = async ({
118
+ channel,
119
+ cacheName,
120
+ url
121
+ }) => {
122
+ {
123
+ assert_mjs.assert.isType(cacheName, 'string', {
124
+ moduleName: 'workbox-broadcast-update',
125
+ className: '~',
126
+ funcName: 'broadcastUpdate',
127
+ paramName: 'cacheName'
128
+ });
129
+ assert_mjs.assert.isType(url, 'string', {
130
+ moduleName: 'workbox-broadcast-update',
131
+ className: '~',
132
+ funcName: 'broadcastUpdate',
133
+ paramName: 'url'
134
+ });
135
+ }
136
+
137
+ const data = {
138
+ type: CACHE_UPDATED_MESSAGE_TYPE,
139
+ meta: CACHE_UPDATED_MESSAGE_META,
140
+ payload: {
141
+ cacheName: cacheName,
142
+ updatedURL: url
143
+ }
144
+ };
145
+
146
+ if (channel) {
147
+ channel.postMessage(data);
148
+ } else {
149
+ const windows = await clients.matchAll({
150
+ type: 'window'
151
+ });
152
+
153
+ for (const win of windows) {
154
+ win.postMessage(data);
155
+ }
156
+ }
157
+ };
158
+
159
+ /*
160
+ Copyright 2018 Google LLC
161
+
162
+ Use of this source code is governed by an MIT-style
163
+ license that can be found in the LICENSE file or at
164
+ https://opensource.org/licenses/MIT.
165
+ */
166
+ /**
167
+ * Uses the [Broadcast Channel API]{@link https://developers.google.com/web/updates/2016/09/broadcastchannel}
168
+ * to notify interested parties when a cached response has been updated.
169
+ * In browsers that do not support the Broadcast Channel API, the instance
170
+ * falls back to sending the update via `postMessage()` to all window clients.
171
+ *
172
+ * For efficiency's sake, the underlying response bodies are not compared;
173
+ * only specific response headers are checked.
174
+ *
175
+ * @memberof workbox.broadcastUpdate
176
+ */
177
+
178
+ class BroadcastCacheUpdate {
179
+ /**
180
+ * Construct a BroadcastCacheUpdate instance with a specific `channelName` to
181
+ * broadcast messages on
182
+ *
183
+ * @param {Object} options
184
+ * @param {Array<string>}
185
+ * [options.headersToCheck=['content-length', 'etag', 'last-modified']]
186
+ * A list of headers that will be used to determine whether the responses
187
+ * differ.
188
+ * @param {string} [options.channelName='workbox'] The name that will be used
189
+ *. when creating the `BroadcastChannel`, which defaults to 'workbox' (the
190
+ * channel name used by the `workbox-window` package).
191
+ * @param {string} [options.deferNoticationTimeout=10000] The amount of time
192
+ * to wait for a ready message from the window on navigation requests
193
+ * before sending the update.
194
+ */
195
+ constructor({
196
+ headersToCheck,
197
+ channelName,
198
+ deferNoticationTimeout
199
+ } = {}) {
200
+ this._headersToCheck = headersToCheck || DEFAULT_HEADERS_TO_CHECK;
201
+ this._channelName = channelName || DEFAULT_BROADCAST_CHANNEL_NAME;
202
+ this._deferNoticationTimeout = deferNoticationTimeout || DEFAULT_DEFER_NOTIFICATION_TIMEOUT;
203
+
204
+ {
205
+ assert_mjs.assert.isType(this._channelName, 'string', {
206
+ moduleName: 'workbox-broadcast-update',
207
+ className: 'BroadcastCacheUpdate',
208
+ funcName: 'constructor',
209
+ paramName: 'channelName'
210
+ });
211
+ assert_mjs.assert.isArray(this._headersToCheck, {
212
+ moduleName: 'workbox-broadcast-update',
213
+ className: 'BroadcastCacheUpdate',
214
+ funcName: 'constructor',
215
+ paramName: 'headersToCheck'
216
+ });
217
+ }
218
+
219
+ this._initWindowReadyDeferreds();
220
+ }
221
+ /**
222
+ * Compare two [Responses](https://developer.mozilla.org/en-US/docs/Web/API/Response)
223
+ * and send a message via the
224
+ * {@link https://developers.google.com/web/updates/2016/09/broadcastchannel|Broadcast Channel API}
225
+ * if they differ.
226
+ *
227
+ * Neither of the Responses can be {@link http://stackoverflow.com/questions/39109789|opaque}.
228
+ *
229
+ * @param {Object} options
230
+ * @param {Response} options.oldResponse Cached response to compare.
231
+ * @param {Response} options.newResponse Possibly updated response to compare.
232
+ * @param {string} options.url The URL of the request.
233
+ * @param {string} options.cacheName Name of the cache the responses belong
234
+ * to. This is included in the broadcast message.
235
+ * @param {Event} [options.event] event An optional event that triggered
236
+ * this possible cache update.
237
+ * @return {Promise} Resolves once the update is sent.
238
+ */
239
+
240
+
241
+ notifyIfUpdated({
242
+ oldResponse,
243
+ newResponse,
244
+ url,
245
+ cacheName,
246
+ event
247
+ }) {
248
+ if (!responsesAreSame(oldResponse, newResponse, this._headersToCheck)) {
249
+ {
250
+ logger_mjs.logger.log(`Newer response found (and cached) for:`, url);
251
+ }
252
+
253
+ const sendUpdate = async () => {
254
+ // In the case of a navigation request, the requesting page will likely
255
+ // not have loaded its JavaScript in time to recevied the update
256
+ // notification, so we defer it until ready (or we timeout waiting).
257
+ if (event && event.request && event.request.mode === 'navigate') {
258
+ {
259
+ logger_mjs.logger.debug(`Original request was a navigation request, ` + `waiting for a ready message from the window`, event.request);
260
+ }
261
+
262
+ await this._windowReadyOrTimeout(event);
263
+ }
264
+
265
+ await broadcastUpdate({
266
+ channel: this._getChannel(),
267
+ cacheName,
268
+ url
269
+ });
270
+ }; // Send the update and ensure the SW stays alive until it's sent.
271
+
272
+
273
+ const done = sendUpdate();
274
+
275
+ if (event) {
276
+ try {
277
+ event.waitUntil(done);
278
+ } catch (error) {
279
+ {
280
+ logger_mjs.logger.warn(`Unable to ensure service worker stays alive ` + `when broadcasting cache update for ` + `${getFriendlyURL_mjs.getFriendlyURL(event.request.url)}'.`);
281
+ }
282
+ }
283
+ }
284
+
285
+ return done;
286
+ }
287
+ }
288
+ /**
289
+ * @return {BroadcastChannel|undefined} The BroadcastChannel instance used for
290
+ * broadcasting updates, or undefined if the browser doesn't support the
291
+ * Broadcast Channel API.
292
+ *
293
+ * @private
294
+ */
295
+
296
+
297
+ _getChannel() {
298
+ if ('BroadcastChannel' in self && !this._channel) {
299
+ this._channel = new BroadcastChannel(this._channelName);
300
+ }
301
+
302
+ return this._channel;
303
+ }
304
+ /**
305
+ * Waits for a message from the window indicating that it's capable of
306
+ * receiving broadcasts. By default, this will only wait for the amount of
307
+ * time specified via the `deferNoticationTimeout` option.
308
+ *
309
+ * @param {Event} event The navigation fetch event.
310
+ * @return {Promise}
311
+ * @private
312
+ */
313
+
314
+
315
+ _windowReadyOrTimeout(event) {
316
+ if (!this._navigationEventsDeferreds.has(event)) {
317
+ const deferred = new Deferred_mjs.Deferred(); // Set the deferred on the `_navigationEventsDeferreds` map so it will
318
+ // be resolved when the next ready message event comes.
319
+
320
+ this._navigationEventsDeferreds.set(event, deferred); // But don't wait too long for the message since it may never come.
321
+
322
+
323
+ const timeout = setTimeout(() => {
324
+ {
325
+ logger_mjs.logger.debug(`Timed out after ${this._deferNoticationTimeout}` + `ms waiting for message from window`);
326
+ }
327
+
328
+ deferred.resolve();
329
+ }, this._deferNoticationTimeout); // Ensure the timeout is cleared if the deferred promise is resolved.
330
+
331
+ deferred.promise.then(() => clearTimeout(timeout));
332
+ }
333
+
334
+ return this._navigationEventsDeferreds.get(event).promise;
335
+ }
336
+ /**
337
+ * Creates a mapping between navigation fetch events and deferreds, and adds
338
+ * a listener for message events from the window. When message events arrive,
339
+ * all deferreds in the mapping are resolved.
340
+ *
341
+ * Note: it would be easier if we could only resolve the deferred of
342
+ * navigation fetch event whose client ID matched the source ID of the
343
+ * message event, but currently client IDs are not exposed on navigation
344
+ * fetch events: https://www.chromestatus.com/feature/4846038800138240
345
+ */
346
+
347
+
348
+ _initWindowReadyDeferreds() {
349
+ // A mapping between navigation events and their deferreds.
350
+ this._navigationEventsDeferreds = new Map(); // The message listener needs to be added in the initial run of the
351
+ // service worker, but since we don't actually need to be listening for
352
+ // messages until the cache updates, we only invoke the callback if set.
353
+
354
+ self.addEventListener('message', event => {
355
+ if (event.data.type === 'WINDOW_READY' && event.data.meta === 'workbox-window' && this._navigationEventsDeferreds.size > 0) {
356
+ {
357
+ logger_mjs.logger.debug(`Received WINDOW_READY event: `, event);
358
+ } // Resolve any pending deferreds.
359
+
360
+
361
+ for (const deferred of this._navigationEventsDeferreds.values()) {
362
+ deferred.resolve();
363
+ }
364
+
365
+ this._navigationEventsDeferreds.clear();
366
+ }
367
+ });
368
+ }
369
+
370
+ }
371
+
372
+ /*
373
+ Copyright 2018 Google LLC
374
+
375
+ Use of this source code is governed by an MIT-style
376
+ license that can be found in the LICENSE file or at
377
+ https://opensource.org/licenses/MIT.
378
+ */
379
+ /**
380
+ * This plugin will automatically broadcast a message whenever a cached response
381
+ * is updated.
382
+ *
383
+ * @memberof workbox.broadcastUpdate
384
+ */
385
+
386
+ class Plugin {
387
+ /**
388
+ * Construct a BroadcastCacheUpdate instance with the passed options and
389
+ * calls its `notifyIfUpdated()` method whenever the plugin's
390
+ * `cacheDidUpdate` callback is invoked.
391
+ *
392
+ * @param {Object} options
393
+ * @param {Array<string>}
394
+ * [options.headersToCheck=['content-length', 'etag', 'last-modified']]
395
+ * A list of headers that will be used to determine whether the responses
396
+ * differ.
397
+ * @param {string} [options.channelName='workbox'] The name that will be used
398
+ *. when creating the `BroadcastChannel`, which defaults to 'workbox' (the
399
+ * channel name used by the `workbox-window` package).
400
+ * @param {string} [options.deferNoticationTimeout=10000] The amount of time
401
+ * to wait for a ready message from the window on navigation requests
402
+ * before sending the update.
403
+ */
404
+ constructor(options) {
405
+ this._broadcastUpdate = new BroadcastCacheUpdate(options);
406
+ }
407
+ /**
408
+ * A "lifecycle" callback that will be triggered automatically by the
409
+ * `workbox-sw` and `workbox-runtime-caching` handlers when an entry is
410
+ * added to a cache.
411
+ *
412
+ * @private
413
+ * @param {Object} options The input object to this function.
414
+ * @param {string} options.cacheName Name of the cache being updated.
415
+ * @param {Response} [options.oldResponse] The previous cached value, if any.
416
+ * @param {Response} options.newResponse The new value in the cache.
417
+ * @param {Request} options.request The request that triggered the udpate.
418
+ * @param {Request} [options.event] The event that triggered the update.
419
+ */
420
+
421
+
422
+ cacheDidUpdate({
423
+ cacheName,
424
+ oldResponse,
425
+ newResponse,
426
+ request,
427
+ event
428
+ }) {
429
+ {
430
+ assert_mjs.assert.isType(cacheName, 'string', {
431
+ moduleName: 'workbox-broadcast-update',
432
+ className: 'Plugin',
433
+ funcName: 'cacheDidUpdate',
434
+ paramName: 'cacheName'
435
+ });
436
+ assert_mjs.assert.isInstance(newResponse, Response, {
437
+ moduleName: 'workbox-broadcast-update',
438
+ className: 'Plugin',
439
+ funcName: 'cacheDidUpdate',
440
+ paramName: 'newResponse'
441
+ });
442
+ assert_mjs.assert.isInstance(request, Request, {
443
+ moduleName: 'workbox-broadcast-update',
444
+ className: 'Plugin',
445
+ funcName: 'cacheDidUpdate',
446
+ paramName: 'request'
447
+ });
448
+ }
449
+
450
+ if (!oldResponse) {
451
+ // Without a two responses there is nothing to compare.
452
+ return;
453
+ }
454
+
455
+ this._broadcastUpdate.notifyIfUpdated({
456
+ cacheName,
457
+ oldResponse,
458
+ newResponse,
459
+ event,
460
+ url: request.url
461
+ });
462
+ }
463
+
464
+ }
465
+
466
+ /*
467
+ Copyright 2018 Google LLC
468
+
469
+ Use of this source code is governed by an MIT-style
470
+ license that can be found in the LICENSE file or at
471
+ https://opensource.org/licenses/MIT.
472
+ */
473
+
474
+ exports.BroadcastCacheUpdate = BroadcastCacheUpdate;
475
+ exports.Plugin = Plugin;
476
+ exports.broadcastUpdate = broadcastUpdate;
477
+ exports.responsesAreSame = responsesAreSame;
478
+
479
+ return exports;
480
+
481
+ }({}, workbox.core._private, workbox.core._private, workbox.core._private, workbox.core._private, workbox.core._private));
482
+ //# sourceMappingURL=workbox-broadcast-update.dev.js.map