jekyll-pwa-workbox 0.0.7.alpha → 0.0.7
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.
- checksums.yaml +4 -4
- data/lib/jekyll-pwa-workbox.rb +1 -1
- data/lib/vendor/{workbox-v5.0.0.alpha1 → workbox-v5.0.0}/workbox-background-sync.dev.js +12 -13
- data/lib/vendor/workbox-v5.0.0/workbox-background-sync.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.0.0/workbox-background-sync.prod.js +2 -0
- data/lib/vendor/workbox-v5.0.0/workbox-background-sync.prod.js.map +1 -0
- data/lib/vendor/workbox-v5.0.0/workbox-broadcast-update.dev.js +288 -0
- data/lib/vendor/workbox-v5.0.0/workbox-broadcast-update.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.0.0/workbox-broadcast-update.prod.js +2 -0
- data/lib/vendor/workbox-v5.0.0/workbox-broadcast-update.prod.js.map +1 -0
- data/lib/vendor/{workbox-v5.0.0.alpha1 → workbox-v5.0.0}/workbox-cacheable-response.dev.js +6 -7
- data/lib/vendor/workbox-v5.0.0/workbox-cacheable-response.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.0.0/workbox-cacheable-response.prod.js +2 -0
- data/lib/vendor/workbox-v5.0.0/workbox-cacheable-response.prod.js.map +1 -0
- data/lib/vendor/{workbox-v5.0.0.alpha1 → workbox-v5.0.0}/workbox-core.dev.js +306 -67
- data/lib/vendor/workbox-v5.0.0/workbox-core.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.0.0/workbox-core.prod.js +2 -0
- data/lib/vendor/workbox-v5.0.0/workbox-core.prod.js.map +1 -0
- data/lib/vendor/{workbox-v5.0.0.alpha1 → workbox-v5.0.0}/workbox-expiration.dev.js +13 -14
- data/lib/vendor/workbox-v5.0.0/workbox-expiration.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.0.0/workbox-expiration.prod.js +2 -0
- data/lib/vendor/workbox-v5.0.0/workbox-expiration.prod.js.map +1 -0
- data/lib/vendor/{workbox-v5.0.0.alpha1 → workbox-v5.0.0}/workbox-navigation-preload.dev.js +4 -5
- data/lib/vendor/workbox-v5.0.0/workbox-navigation-preload.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.0.0/workbox-navigation-preload.prod.js +2 -0
- data/lib/vendor/workbox-v5.0.0/workbox-navigation-preload.prod.js.map +1 -0
- data/lib/vendor/{workbox-v5.0.0.alpha1 → workbox-v5.0.0}/workbox-offline-ga.dev.js +12 -13
- data/lib/vendor/workbox-v5.0.0/workbox-offline-ga.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.0.0/workbox-offline-ga.prod.js +2 -0
- data/lib/vendor/workbox-v5.0.0/workbox-offline-ga.prod.js.map +1 -0
- data/lib/vendor/{workbox-v5.0.0.alpha1 → workbox-v5.0.0}/workbox-precaching.dev.js +314 -86
- data/lib/vendor/workbox-v5.0.0/workbox-precaching.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.0.0/workbox-precaching.prod.js +2 -0
- data/lib/vendor/workbox-v5.0.0/workbox-precaching.prod.js.map +1 -0
- data/lib/vendor/{workbox-v5.0.0.alpha1 → workbox-v5.0.0}/workbox-range-requests.dev.js +8 -9
- data/lib/vendor/workbox-v5.0.0/workbox-range-requests.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.0.0/workbox-range-requests.prod.js +2 -0
- data/lib/vendor/workbox-v5.0.0/workbox-range-requests.prod.js.map +1 -0
- data/lib/vendor/{workbox-v5.0.0.alpha1 → workbox-v5.0.0}/workbox-routing.dev.js +79 -182
- data/lib/vendor/workbox-v5.0.0/workbox-routing.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.0.0/workbox-routing.prod.js +2 -0
- data/lib/vendor/workbox-v5.0.0/workbox-routing.prod.js.map +1 -0
- data/lib/vendor/{workbox-v5.0.0.alpha1 → workbox-v5.0.0}/workbox-strategies.dev.js +23 -227
- data/lib/vendor/workbox-v5.0.0/workbox-strategies.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.0.0/workbox-strategies.prod.js +2 -0
- data/lib/vendor/workbox-v5.0.0/workbox-strategies.prod.js.map +1 -0
- data/lib/vendor/{workbox-v5.0.0.alpha1 → workbox-v5.0.0}/workbox-streams.dev.js +16 -31
- data/lib/vendor/workbox-v5.0.0/workbox-streams.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.0.0/workbox-streams.prod.js +2 -0
- data/lib/vendor/workbox-v5.0.0/workbox-streams.prod.js.map +1 -0
- data/lib/vendor/workbox-v5.0.0/workbox-sw.js +2 -0
- data/lib/vendor/workbox-v5.0.0/workbox-sw.js.map +1 -0
- data/lib/vendor/{workbox-v5.0.0.alpha1 → workbox-v5.0.0}/workbox-window.dev.es5.mjs +317 -113
- data/lib/vendor/workbox-v5.0.0/workbox-window.dev.es5.mjs.map +1 -0
- data/lib/vendor/{workbox-v5.0.0.alpha1 → workbox-v5.0.0}/workbox-window.dev.mjs +244 -44
- data/lib/vendor/workbox-v5.0.0/workbox-window.dev.mjs.map +1 -0
- data/lib/vendor/{workbox-v5.0.0.alpha1 → workbox-v5.0.0}/workbox-window.dev.umd.js +317 -113
- data/lib/vendor/workbox-v5.0.0/workbox-window.dev.umd.js.map +1 -0
- data/lib/vendor/workbox-v5.0.0/workbox-window.prod.es5.mjs +2 -0
- data/lib/vendor/workbox-v5.0.0/workbox-window.prod.es5.mjs.map +1 -0
- data/lib/vendor/workbox-v5.0.0/workbox-window.prod.mjs +2 -0
- data/lib/vendor/workbox-v5.0.0/workbox-window.prod.mjs.map +1 -0
- data/lib/vendor/workbox-v5.0.0/workbox-window.prod.umd.js +2 -0
- data/lib/vendor/workbox-v5.0.0/workbox-window.prod.umd.js.map +1 -0
- metadata +70 -69
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-background-sync.dev.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-background-sync.prod.js +0 -2
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-background-sync.prod.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-broadcast-update.dev.js +0 -486
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-broadcast-update.dev.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-broadcast-update.prod.js +0 -2
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-broadcast-update.prod.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-cacheable-response.dev.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-cacheable-response.prod.js +0 -2
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-cacheable-response.prod.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-core.dev.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-core.prod.js +0 -2
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-core.prod.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-expiration.dev.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-expiration.prod.js +0 -2
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-expiration.prod.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-navigation-preload.dev.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-navigation-preload.prod.js +0 -2
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-navigation-preload.prod.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-offline-ga.dev.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-offline-ga.prod.js +0 -2
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-offline-ga.prod.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-precaching.dev.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-precaching.prod.js +0 -2
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-precaching.prod.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-range-requests.dev.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-range-requests.prod.js +0 -2
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-range-requests.prod.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-routing.dev.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-routing.prod.js +0 -2
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-routing.prod.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-strategies.dev.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-strategies.prod.js +0 -2
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-strategies.prod.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-streams.dev.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-streams.prod.js +0 -2
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-streams.prod.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-sw.js +0 -2
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-sw.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.dev.es5.mjs.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.dev.mjs.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.dev.umd.js.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.prod.es5.mjs +0 -2
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.prod.es5.mjs.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.prod.mjs +0 -2
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.prod.mjs.map +0 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.prod.umd.js +0 -2
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.prod.umd.js.map +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a5c5bdde77d1cd4d620bc9615961cc9e44e7dbe4353f82f6e621f67cd8420b0
|
4
|
+
data.tar.gz: 7c0c45303d3925b8d14bed6c9a4cdf2b9bf9417f8d2f965c8cf1e0a397a25ef5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 788607fa6afa460be54c0e3c5cfc5c8bbb4acd548511bed2ad39b96de1f3669b924e540d69d280a8235d7ddaf7e381aa5cf3fd5e36019e2c7c4ae972417ed08c
|
7
|
+
data.tar.gz: ee7e4ee80303a0af4a3b19e61968393a3217400371763f85ad87ea875e8a948104db916b82a1621e66924bc5658ecbdd62080ac1b2b02d1adf5ac1d33f86b563
|
data/lib/jekyll-pwa-workbox.rb
CHANGED
@@ -2,9 +2,8 @@ this.workbox = this.workbox || {};
|
|
2
2
|
this.workbox.backgroundSync = (function (exports, WorkboxError_js, logger_js, assert_js, getFriendlyURL_js, DBWrapper_js) {
|
3
3
|
'use strict';
|
4
4
|
|
5
|
-
// @ts-ignore
|
6
5
|
try {
|
7
|
-
self['workbox:background-sync:5.0.0
|
6
|
+
self['workbox:background-sync:5.0.0'] && _();
|
8
7
|
} catch (e) {}
|
9
8
|
|
10
9
|
/*
|
@@ -19,7 +18,7 @@ this.workbox.backgroundSync = (function (exports, WorkboxError_js, logger_js, as
|
|
19
18
|
const OBJECT_STORE_NAME = 'requests';
|
20
19
|
const INDEXED_PROP = 'queueName';
|
21
20
|
/**
|
22
|
-
* A class to manage storing requests from a Queue in
|
21
|
+
* A class to manage storing requests from a Queue in IndexedDB,
|
23
22
|
* indexed by their queue name for easier access.
|
24
23
|
*
|
25
24
|
* @private
|
@@ -72,7 +71,7 @@ this.workbox.backgroundSync = (function (exports, WorkboxError_js, logger_js, as
|
|
72
71
|
await this._db.add(OBJECT_STORE_NAME, entry);
|
73
72
|
}
|
74
73
|
/**
|
75
|
-
*
|
74
|
+
* Prepend an entry first in the queue.
|
76
75
|
*
|
77
76
|
* @param {Object} entry
|
78
77
|
* @param {Object} entry.requestData
|
@@ -142,7 +141,7 @@ this.workbox.backgroundSync = (function (exports, WorkboxError_js, logger_js, as
|
|
142
141
|
/**
|
143
142
|
* Returns all entries in the store matching the `queueName`.
|
144
143
|
*
|
145
|
-
* @param {Object} options See workbox.
|
144
|
+
* @param {Object} options See {@link module:workbox-background-sync.Queue~getAll}
|
146
145
|
* @return {Promise<Array<Object>>}
|
147
146
|
* @private
|
148
147
|
*/
|
@@ -304,8 +303,8 @@ this.workbox.backgroundSync = (function (exports, WorkboxError_js, logger_js, as
|
|
304
303
|
// navigation requests can't be constructed via script.
|
305
304
|
|
306
305
|
|
307
|
-
if (requestData
|
308
|
-
requestData
|
306
|
+
if (requestData['mode'] === 'navigate') {
|
307
|
+
requestData['mode'] = 'same-origin';
|
309
308
|
}
|
310
309
|
|
311
310
|
this._requestData = requestData;
|
@@ -372,7 +371,7 @@ this.workbox.backgroundSync = (function (exports, WorkboxError_js, logger_js, as
|
|
372
371
|
* later. All parts of the storing and replaying process are observable via
|
373
372
|
* callbacks.
|
374
373
|
*
|
375
|
-
* @memberof workbox
|
374
|
+
* @memberof module:workbox-background-sync
|
376
375
|
*/
|
377
376
|
|
378
377
|
class Queue {
|
@@ -780,15 +779,15 @@ this.workbox.backgroundSync = (function (exports, WorkboxError_js, logger_js, as
|
|
780
779
|
* A class implementing the `fetchDidFail` lifecycle callback. This makes it
|
781
780
|
* easier to add failed requests to a background sync Queue.
|
782
781
|
*
|
783
|
-
* @memberof workbox
|
782
|
+
* @memberof module:workbox-background-sync
|
784
783
|
*/
|
785
784
|
|
786
|
-
class
|
785
|
+
class BackgroundSyncPlugin {
|
787
786
|
/**
|
788
|
-
* @param {string} name See the [Queue]{@link workbox.
|
787
|
+
* @param {string} name See the [Queue]{@link module:workbox-background-sync.Queue}
|
789
788
|
* documentation for parameter details.
|
790
789
|
* @param {Object} [options] See the
|
791
|
-
* [Queue]{@link workbox.
|
790
|
+
* [Queue]{@link module:workbox-background-sync.Queue} documentation for
|
792
791
|
* parameter details.
|
793
792
|
*/
|
794
793
|
constructor(name, options) {
|
@@ -810,7 +809,7 @@ this.workbox.backgroundSync = (function (exports, WorkboxError_js, logger_js, as
|
|
810
809
|
|
811
810
|
}
|
812
811
|
|
813
|
-
exports.
|
812
|
+
exports.BackgroundSyncPlugin = BackgroundSyncPlugin;
|
814
813
|
exports.Queue = Queue;
|
815
814
|
|
816
815
|
return exports;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"workbox-background-sync.dev.js","sources":["../_version.js","../lib/QueueStore.js","../lib/StorableRequest.js","../Queue.js","../BackgroundSyncPlugin.js"],"sourcesContent":["\"use strict\";\n// @ts-ignore\ntry {\n self['workbox:background-sync:5.0.0'] && _();\n}\ncatch (e) { }\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*/\nimport { assert } from 'workbox-core/_private/assert.js';\nimport { DBWrapper } from 'workbox-core/_private/DBWrapper.js';\nimport '../_version.js';\nconst DB_VERSION = 3;\nconst DB_NAME = 'workbox-background-sync';\nconst OBJECT_STORE_NAME = 'requests';\nconst INDEXED_PROP = 'queueName';\n/**\n * A class to manage storing requests from a Queue in IndexedDB,\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: this._upgradeDb,\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 * @private\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 // Don't specify an ID since one is automatically generated.\n delete entry.id;\n entry.queueName = this._queueName;\n await this._db.add(OBJECT_STORE_NAME, entry);\n }\n /**\n * Prepend 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 * @private\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 const [firstEntry] = await this._db.getAllMatching(OBJECT_STORE_NAME, {\n count: 1,\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 }\n else {\n // Otherwise let the auto-incrementor assign the ID.\n delete entry.id;\n }\n entry.queueName = this._queueName;\n await this._db.add(OBJECT_STORE_NAME, entry);\n }\n /**\n * Removes and returns the last entry in the queue matching the `queueName`.\n *\n * @return {Promise<Object>}\n * @private\n */\n async popEntry() {\n return this._removeEntry({ direction: 'prev' });\n }\n /**\n * Removes and returns the first entry in the queue matching the `queueName`.\n *\n * @return {Promise<Object>}\n * @private\n */\n async shiftEntry() {\n return this._removeEntry({ direction: 'next' });\n }\n /**\n * Returns all entries in the store matching the `queueName`.\n *\n * @param {Object} options See {@link module:workbox-background-sync.Queue~getAll}\n * @return {Promise<Array<Object>>}\n * @private\n */\n async getAll() {\n return await this._db.getAllMatching(OBJECT_STORE_NAME, {\n index: INDEXED_PROP,\n query: IDBKeyRange.only(this._queueName),\n });\n }\n /**\n * Deletes the entry for the given ID.\n *\n * WARNING: this method does not ensure the deleted enry belongs to this\n * queue (i.e. matches the `queueName`). But this limitation is acceptable\n * as this class is not publicly exposed. An additional check would make\n * this method slower than it needs to be.\n *\n * @private\n * @param {number} id\n */\n async deleteEntry(id) {\n await this._db.delete(OBJECT_STORE_NAME, id);\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 * @private\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 if (entry) {\n await this.deleteEntry(entry.id);\n return entry;\n }\n }\n /**\n * Upgrades the database given an `upgradeneeded` event.\n *\n * @param {Event} event\n * @private\n */\n _upgradeDb(event) {\n const db = event.target.result;\n if (event.oldVersion > 0 && event.oldVersion < DB_VERSION) {\n if (db.objectStoreNames.contains(OBJECT_STORE_NAME)) {\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*/\nimport { assert } from 'workbox-core/_private/assert.js';\nimport '../_version.js';\nconst serializableProperties = [\n 'method',\n 'referrer',\n 'referrerPolicy',\n 'mode',\n 'credentials',\n 'cache',\n 'redirect',\n 'integrity',\n '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 */\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 // 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 // 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 // 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 return new StorableRequest(requestData);\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 // If the request's mode is `navigate`, convert it to `same-origin` since\n // navigation requests can't be constructed via script.\n if (requestData['mode'] === 'navigate') {\n requestData['mode'] = 'same-origin';\n }\n this._requestData = requestData;\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 return requestData;\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 * 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}\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*/\nimport { WorkboxError } from 'workbox-core/_private/WorkboxError.js';\nimport { logger } from 'workbox-core/_private/logger.js';\nimport { assert } from 'workbox-core/_private/assert.js';\nimport { getFriendlyURL } from 'workbox-core/_private/getFriendlyURL.js';\nimport { QueueStore } from './lib/QueueStore.js';\nimport { StorableRequest } from './lib/StorableRequest.js';\nimport './_version.js';\nconst TAG_PREFIX = 'workbox-background-sync';\nconst MAX_RETENTION_TIME = 60 * 24 * 7; // 7 days in minutes\nconst queueNames = new Set();\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 module:workbox-background-sync\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 this._syncInProgress = false;\n this._requestsAddedDuringSync = false;\n // Ensure the store name is not already being used\n if (queueNames.has(name)) {\n throw new WorkboxError('duplicate-queue-name', { name });\n }\n else {\n queueNames.add(name);\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 this._addSyncListener();\n }\n /**\n * @return {string}\n */\n get name() {\n return this._name;\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 await this._addRequest(entry, 'push');\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 await this._addRequest(entry, 'unshift');\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 * 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 * Returns all the entries that have not expired (per `maxRetentionTime`).\n * Any expired entries are removed from the queue.\n *\n * @return {Promise<Array<Object>>}\n */\n async getAll() {\n const allEntries = await this._queueStore.getAll();\n const now = Date.now();\n const unexpiredEntries = [];\n for (const entry of allEntries) {\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 await this._queueStore.deleteEntry(entry.id);\n }\n else {\n unexpiredEntries.push(convertEntry(entry));\n }\n }\n return unexpiredEntries;\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 * @private\n */\n async _addRequest({ 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 // Only include metadata if it's present.\n if (metadata) {\n entry.metadata = metadata;\n }\n await this._queueStore[`${operation}Entry`](entry);\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 // 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 }\n else {\n await this.registerSync();\n }\n }\n /**\n * Removes and returns the first or last (depending on `operation`) entry\n * from the QueueStore that's not older than the `maxRetentionTime`.\n *\n * @param {string} operation ('pop' or 'shift')\n * @return {Object|undefined}\n * @private\n */\n async _removeRequest(operation) {\n const now = Date.now();\n const entry = await this._queueStore[`${operation}Entry`]();\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 return convertEntry(entry);\n }\n else {\n return undefined;\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.clone());\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 }\n catch (error) {\n await this.unshiftRequest(entry);\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 * Registers a sync event with a tag unique to this instance.\n */\n async registerSync() {\n if ('sync' in self.registration) {\n try {\n await self.registration.sync.register(`${TAG_PREFIX}:${this._name}`);\n }\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(`Unable to register sync event for '${this._name}'.`, err);\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 self.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 const syncComplete = async () => {\n this._syncInProgress = true;\n let syncError;\n try {\n await this._onSync({ queue: this });\n }\n catch (error) {\n syncError = error;\n // Rethrow the error. Note: the logic in the finally clause\n // will run before this gets rethrown.\n throw syncError;\n }\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 this._syncInProgress = false;\n this._requestsAddedDuringSync = false;\n }\n };\n event.waitUntil(syncComplete());\n }\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 * 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 * Converts a QueueStore entry into the format exposed by Queue. This entails\n * converting the request data into a real request and omitting the `id` and\n * `queueName` properties.\n *\n * @param {Object} queueStoreEntry\n * @return {Object}\n * @private\n */\nconst convertEntry = (queueStoreEntry) => {\n const queueEntry = {\n request: new StorableRequest(queueStoreEntry.requestData).toRequest(),\n timestamp: queueStoreEntry.timestamp,\n };\n if (queueStoreEntry.metadata) {\n queueEntry.metadata = queueStoreEntry.metadata;\n }\n return queueEntry;\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*/\nimport { Queue } from './Queue.js';\nimport './_version.js';\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 module:workbox-background-sync\n */\nclass BackgroundSyncPlugin {\n /**\n * @param {string} name See the [Queue]{@link module:workbox-background-sync.Queue}\n * documentation for parameter details.\n * @param {Object} [options] See the\n * [Queue]{@link module:workbox-background-sync.Queue} documentation for\n * parameter details.\n */\n constructor(name, options) {\n /**\n * @param {Object} options\n * @param {Request} options.request\n * @private\n */\n this.fetchDidFail = async ({ request }) => {\n await this._queue.pushRequest({ request });\n };\n this._queue = new Queue(name, options);\n }\n}\nexport { BackgroundSyncPlugin };\n"],"names":["self","_","e","DB_VERSION","DB_NAME","OBJECT_STORE_NAME","INDEXED_PROP","QueueStore","constructor","queueName","_queueName","_db","DBWrapper","onupgradeneeded","_upgradeDb","pushEntry","entry","assert","isType","moduleName","className","funcName","paramName","requestData","id","add","unshiftEntry","firstEntry","getAllMatching","count","popEntry","_removeEntry","direction","shiftEntry","getAll","index","query","IDBKeyRange","only","deleteEntry","delete","event","db","target","result","oldVersion","objectStoreNames","contains","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","_syncInProgress","_requestsAddedDuringSync","has","WorkboxError","_name","_onSync","replayRequests","_maxRetentionTime","_queueStore","_addSyncListener","pushRequest","isInstance","_addRequest","unshiftRequest","popRequest","_removeRequest","shiftRequest","allEntries","now","Date","unexpiredEntries","maxRetentionTimeInMs","timestamp","push","convertEntry","metadata","operation","storableRequest","logger","log","getFriendlyURL","registerSync","fetch","process","error","registration","sync","register","err","warn","addEventListener","tag","syncComplete","syncError","queue","lastChance","waitUntil","_queueNames","queueStoreEntry","queueEntry","BackgroundSyncPlugin","options","fetchDidFail","_queue"],"mappings":";;;;IAEA,IAAI;IACAA,EAAAA,IAAI,CAAC,+BAAD,CAAJ,IAAyCC,CAAC,EAA1C;IACH,CAFD,CAGA,OAAOC,CAAP,EAAU;;ICLV;;;;;;;AAOA,IAGA,MAAMC,UAAU,GAAG,CAAnB;IACA,MAAMC,OAAO,GAAG,yBAAhB;IACA,MAAMC,iBAAiB,GAAG,UAA1B;IACA,MAAMC,YAAY,GAAG,WAArB;IACA;;;;;;;AAMA,IAAO,MAAMC,UAAN,CAAiB;IACpB;;;;;;;IAOAC,EAAAA,WAAW,CAACC,SAAD,EAAY;IACnB,SAAKC,UAAL,GAAkBD,SAAlB;IACA,SAAKE,GAAL,GAAW,IAAIC,sBAAJ,CAAcR,OAAd,EAAuBD,UAAvB,EAAmC;IAC1CU,MAAAA,eAAe,EAAE,KAAKC;IADoB,KAAnC,CAAX;IAGH;IACD;;;;;;;;;;;IASA,QAAMC,SAAN,CAAgBC,KAAhB,EAAuB;IACnB,IAA2C;IACvCC,MAAAA,gBAAM,CAACC,MAAP,CAAcF,KAAd,EAAqB,QAArB,EAA+B;IAC3BG,QAAAA,UAAU,EAAE,yBADe;IAE3BC,QAAAA,SAAS,EAAE,YAFgB;IAG3BC,QAAAA,QAAQ,EAAE,WAHiB;IAI3BC,QAAAA,SAAS,EAAE;IAJgB,OAA/B;IAMAL,MAAAA,gBAAM,CAACC,MAAP,CAAcF,KAAK,CAACO,WAApB,EAAiC,QAAjC,EAA2C;IACvCJ,QAAAA,UAAU,EAAE,yBAD2B;IAEvCC,QAAAA,SAAS,EAAE,YAF4B;IAGvCC,QAAAA,QAAQ,EAAE,WAH6B;IAIvCC,QAAAA,SAAS,EAAE;IAJ4B,OAA3C;IAMH,KAdkB;;;IAgBnB,WAAON,KAAK,CAACQ,EAAb;IACAR,IAAAA,KAAK,CAACP,SAAN,GAAkB,KAAKC,UA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ACH,CATD;;ICnWA;;;;;;;AAOA,IAEA;;;;;;;IAMA,MAAMC,oBAAN,CAA2B;IACvB;;;;;;;IAOA/H,EAAAA,WAAW,CAAC0E,IAAD,EAAOsD,OAAP,EAAgB;IACvB;;;;;IAKA,SAAKC,YAAL,GAAoB,OAAO;IAAE/E,MAAAA;IAAF,KAAP,KAAuB;IACvC,YAAM,KAAKgF,MAAL,CAAY3C,WAAZ,CAAwB;IAAErC,QAAAA;IAAF,OAAxB,CAAN;IACH,KAFD;;IAGA,SAAKgF,MAAL,GAAc,IAAIzD,KAAJ,CAAUC,IAAV,EAAgBsD,OAAhB,CAAd;IACH;;IAlBsB;;;;;;;;;;;"}
|
@@ -0,0 +1,2 @@
|
|
1
|
+
this.workbox=this.workbox||{},this.workbox.backgroundSync=function(t,e,s,i,n){"use strict";try{self["workbox:background-sync:5.0.0"]&&_()}catch(t){}const a=3,r="workbox-background-sync",c="requests",h="queueName";class o{constructor(t){this.t=t,this.s=new n.DBWrapper(r,a,{onupgradeneeded:this.i})}async pushEntry(t){delete t.id,t.queueName=this.t,await this.s.add(c,t)}async unshiftEntry(t){const[e]=await this.s.getAllMatching(c,{count:1});e?t.id=e.id-1:delete t.id,t.queueName=this.t,await this.s.add(c,t)}async popEntry(){return this.h({direction:"prev"})}async shiftEntry(){return this.h({direction:"next"})}async getAll(){return await this.s.getAllMatching(c,{index:h,query:IDBKeyRange.only(this.t)})}async deleteEntry(t){await this.s.delete(c,t)}async h({direction:t}){const[e]=await this.s.getAllMatching(c,{direction:t,index:h,query:IDBKeyRange.only(this.t),count:1});if(e)return await this.deleteEntry(e.id),e}i(t){const e=t.target.result;t.oldVersion>0&&t.oldVersion<a&&e.objectStoreNames.contains(c)&&e.deleteObjectStore(c),e.createObjectStore(c,{autoIncrement:!0,keyPath:"id"}).createIndex(h,h,{unique:!1})}}const u=["method","referrer","referrerPolicy","mode","credentials","cache","redirect","integrity","keepalive"];class y{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 u)void 0!==t[s]&&(e[s]=t[s]);return new y(e)}constructor(t){"navigate"===t.mode&&(t.mode="same-origin"),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 y(this.toObject())}}const w="workbox-background-sync",f=10080,d=new Set;class l{constructor(t,{onSync:s,maxRetentionTime:i}={}){if(this.u=!1,this.l=!1,d.has(t))throw new e.WorkboxError("duplicate-queue-name",{name:t});d.add(t),this.q=t,this.m=s||this.replayRequests,this.p=i||f,this.g=new o(this.q),this.R()}get name(){return this.q}async pushRequest(t){await this.k(t,"push")}async unshiftRequest(t){await this.k(t,"unshift")}async popRequest(){return this.D("pop")}async shiftRequest(){return this.D("shift")}async getAll(){const t=await this.g.getAll(),e=Date.now(),s=[];for(const i of t){const t=60*this.p*1e3;e-i.timestamp>t?await this.g.deleteEntry(i.id):s.push(q(i))}return s}async k({request:t,metadata:e,timestamp:s=Date.now()},i){const n={requestData:(await y.fromRequest(t.clone())).toObject(),timestamp:s};e&&(n.metadata=e),await this.g[`${i}Entry`](n),this.u?this.l=!0:await this.registerSync()}async D(t){const e=Date.now(),s=await this.g[`${t}Entry`]();if(s){const i=60*this.p*1e3;return e-s.timestamp>i?this.D(t):q(s)}}async replayRequests(){let t;for(;t=await this.shiftRequest();)try{await fetch(t.request.clone())}catch(s){throw await this.unshiftRequest(t),new e.WorkboxError("queue-replay-failed",{name:this.q})}}async registerSync(){if("sync"in self.registration)try{await self.registration.sync.register(`${w}:${this.q}`)}catch(t){}}R(){"sync"in self.registration?self.addEventListener("sync",t=>{if(t.tag===`${w}:${this.q}`){const e=async()=>{let e;this.u=!0;try{await this.m({queue:this})}catch(t){throw e=t}finally{!this.l||e&&!t.lastChance||await this.registerSync(),this.u=!1,this.l=!1}};t.waitUntil(e())}}):this.m({queue:this})}static get _(){return d}}const q=t=>{const e={request:new y(t.requestData).toRequest(),timestamp:t.timestamp};return t.metadata&&(e.metadata=t.metadata),e};return t.BackgroundSyncPlugin=class{constructor(t,e){this.fetchDidFail=(async({request:t})=>{await this.v.pushRequest({request:t})}),this.v=new l(t,e)}},t.Queue=l,t}({},workbox.core._private,workbox.core._private,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.js","../lib/QueueStore.js","../lib/StorableRequest.js","../Queue.js","../BackgroundSyncPlugin.js"],"sourcesContent":["\"use strict\";\n// @ts-ignore\ntry {\n self['workbox:background-sync:5.0.0'] && _();\n}\ncatch (e) { }\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*/\nimport { assert } from 'workbox-core/_private/assert.js';\nimport { DBWrapper } from 'workbox-core/_private/DBWrapper.js';\nimport '../_version.js';\nconst DB_VERSION = 3;\nconst DB_NAME = 'workbox-background-sync';\nconst OBJECT_STORE_NAME = 'requests';\nconst INDEXED_PROP = 'queueName';\n/**\n * A class to manage storing requests from a Queue in IndexedDB,\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: this._upgradeDb,\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 * @private\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 // Don't specify an ID since one is automatically generated.\n delete entry.id;\n entry.queueName = this._queueName;\n await this._db.add(OBJECT_STORE_NAME, entry);\n }\n /**\n * Prepend 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 * @private\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 const [firstEntry] = await this._db.getAllMatching(OBJECT_STORE_NAME, {\n count: 1,\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 }\n else {\n // Otherwise let the auto-incrementor assign the ID.\n delete entry.id;\n }\n entry.queueName = this._queueName;\n await this._db.add(OBJECT_STORE_NAME, entry);\n }\n /**\n * Removes and returns the last entry in the queue matching the `queueName`.\n *\n * @return {Promise<Object>}\n * @private\n */\n async popEntry() {\n return this._removeEntry({ direction: 'prev' });\n }\n /**\n * Removes and returns the first entry in the queue matching the `queueName`.\n *\n * @return {Promise<Object>}\n * @private\n */\n async shiftEntry() {\n return this._removeEntry({ direction: 'next' });\n }\n /**\n * Returns all entries in the store matching the `queueName`.\n *\n * @param {Object} options See {@link module:workbox-background-sync.Queue~getAll}\n * @return {Promise<Array<Object>>}\n * @private\n */\n async getAll() {\n return await this._db.getAllMatching(OBJECT_STORE_NAME, {\n index: INDEXED_PROP,\n query: IDBKeyRange.only(this._queueName),\n });\n }\n /**\n * Deletes the entry for the given ID.\n *\n * WARNING: this method does not ensure the deleted enry belongs to this\n * queue (i.e. matches the `queueName`). But this limitation is acceptable\n * as this class is not publicly exposed. An additional check would make\n * this method slower than it needs to be.\n *\n * @private\n * @param {number} id\n */\n async deleteEntry(id) {\n await this._db.delete(OBJECT_STORE_NAME, id);\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 * @private\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 if (entry) {\n await this.deleteEntry(entry.id);\n return entry;\n }\n }\n /**\n * Upgrades the database given an `upgradeneeded` event.\n *\n * @param {Event} event\n * @private\n */\n _upgradeDb(event) {\n const db = event.target.result;\n if (event.oldVersion > 0 && event.oldVersion < DB_VERSION) {\n if (db.objectStoreNames.contains(OBJECT_STORE_NAME)) {\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*/\nimport { assert } from 'workbox-core/_private/assert.js';\nimport '../_version.js';\nconst serializableProperties = [\n 'method',\n 'referrer',\n 'referrerPolicy',\n 'mode',\n 'credentials',\n 'cache',\n 'redirect',\n 'integrity',\n '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 */\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 // 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 // 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 // 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 return new StorableRequest(requestData);\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 // If the request's mode is `navigate`, convert it to `same-origin` since\n // navigation requests can't be constructed via script.\n if (requestData['mode'] === 'navigate') {\n requestData['mode'] = 'same-origin';\n }\n this._requestData = requestData;\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 return requestData;\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 * 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}\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*/\nimport { WorkboxError } from 'workbox-core/_private/WorkboxError.js';\nimport { logger } from 'workbox-core/_private/logger.js';\nimport { assert } from 'workbox-core/_private/assert.js';\nimport { getFriendlyURL } from 'workbox-core/_private/getFriendlyURL.js';\nimport { QueueStore } from './lib/QueueStore.js';\nimport { StorableRequest } from './lib/StorableRequest.js';\nimport './_version.js';\nconst TAG_PREFIX = 'workbox-background-sync';\nconst MAX_RETENTION_TIME = 60 * 24 * 7; // 7 days in minutes\nconst queueNames = new Set();\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 module:workbox-background-sync\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 this._syncInProgress = false;\n this._requestsAddedDuringSync = false;\n // Ensure the store name is not already being used\n if (queueNames.has(name)) {\n throw new WorkboxError('duplicate-queue-name', { name });\n }\n else {\n queueNames.add(name);\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 this._addSyncListener();\n }\n /**\n * @return {string}\n */\n get name() {\n return this._name;\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 await this._addRequest(entry, 'push');\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 await this._addRequest(entry, 'unshift');\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 * 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 * Returns all the entries that have not expired (per `maxRetentionTime`).\n * Any expired entries are removed from the queue.\n *\n * @return {Promise<Array<Object>>}\n */\n async getAll() {\n const allEntries = await this._queueStore.getAll();\n const now = Date.now();\n const unexpiredEntries = [];\n for (const entry of allEntries) {\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 await this._queueStore.deleteEntry(entry.id);\n }\n else {\n unexpiredEntries.push(convertEntry(entry));\n }\n }\n return unexpiredEntries;\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 * @private\n */\n async _addRequest({ 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 // Only include metadata if it's present.\n if (metadata) {\n entry.metadata = metadata;\n }\n await this._queueStore[`${operation}Entry`](entry);\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 // 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 }\n else {\n await this.registerSync();\n }\n }\n /**\n * Removes and returns the first or last (depending on `operation`) entry\n * from the QueueStore that's not older than the `maxRetentionTime`.\n *\n * @param {string} operation ('pop' or 'shift')\n * @return {Object|undefined}\n * @private\n */\n async _removeRequest(operation) {\n const now = Date.now();\n const entry = await this._queueStore[`${operation}Entry`]();\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 return convertEntry(entry);\n }\n else {\n return undefined;\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.clone());\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 }\n catch (error) {\n await this.unshiftRequest(entry);\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 * Registers a sync event with a tag unique to this instance.\n */\n async registerSync() {\n if ('sync' in self.registration) {\n try {\n await self.registration.sync.register(`${TAG_PREFIX}:${this._name}`);\n }\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(`Unable to register sync event for '${this._name}'.`, err);\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 self.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 const syncComplete = async () => {\n this._syncInProgress = true;\n let syncError;\n try {\n await this._onSync({ queue: this });\n }\n catch (error) {\n syncError = error;\n // Rethrow the error. Note: the logic in the finally clause\n // will run before this gets rethrown.\n throw syncError;\n }\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 this._syncInProgress = false;\n this._requestsAddedDuringSync = false;\n }\n };\n event.waitUntil(syncComplete());\n }\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 * 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 * Converts a QueueStore entry into the format exposed by Queue. This entails\n * converting the request data into a real request and omitting the `id` and\n * `queueName` properties.\n *\n * @param {Object} queueStoreEntry\n * @return {Object}\n * @private\n */\nconst convertEntry = (queueStoreEntry) => {\n const queueEntry = {\n request: new StorableRequest(queueStoreEntry.requestData).toRequest(),\n timestamp: queueStoreEntry.timestamp,\n };\n if (queueStoreEntry.metadata) {\n queueEntry.metadata = queueStoreEntry.metadata;\n }\n return queueEntry;\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*/\nimport { Queue } from './Queue.js';\nimport './_version.js';\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 module:workbox-background-sync\n */\nclass BackgroundSyncPlugin {\n /**\n * @param {string} name See the [Queue]{@link module:workbox-background-sync.Queue}\n * documentation for parameter details.\n * @param {Object} [options] See the\n * [Queue]{@link module:workbox-background-sync.Queue} documentation for\n * parameter details.\n */\n constructor(name, options) {\n /**\n * @param {Object} options\n * @param {Request} options.request\n * @private\n */\n this.fetchDidFail = async ({ request }) => {\n await this._queue.pushRequest({ request });\n };\n this._queue = new Queue(name, options);\n }\n}\nexport { BackgroundSyncPlugin };\n"],"names":["self","_","e","DB_VERSION","DB_NAME","OBJECT_STORE_NAME","INDEXED_PROP","QueueStore","constructor","queueName","_queueName","_db","DBWrapper","onupgradeneeded","this","_upgradeDb","entry","id","add","firstEntry","getAllMatching","count","_removeEntry","direction","index","query","IDBKeyRange","only","delete","deleteEntry","event","db","target","result","oldVersion","objectStoreNames","contains","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","_syncInProgress","_requestsAddedDuringSync","has","WorkboxError","_name","_onSync","replayRequests","_maxRetentionTime","_queueStore","_addSyncListener","_addRequest","_removeRequest","allEntries","getAll","now","Date","unexpiredEntries","maxRetentionTimeInMs","timestamp","push","convertEntry","metadata","operation","fromRequest","registerSync","shiftRequest","fetch","error","unshiftRequest","registration","sync","register","err","addEventListener","tag","syncComplete","async","syncError","queue","lastChance","waitUntil","queueStoreEntry","queueEntry","options","fetchDidFail","_queue","pushRequest"],"mappings":"2FAEA,IACIA,KAAK,kCAAoCC,IAE7C,MAAOC,ICKP,MAAMC,EAAa,EACbC,EAAU,0BACVC,EAAoB,WACpBC,EAAe,YAOd,MAAMC,EAQTC,YAAYC,QACHC,EAAaD,OACbE,EAAM,IAAIC,YAAUR,EAASD,EAAY,CAC1CU,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3G,YAAY8D,EAAM8C,QAMTC,aAAeR,QAAShE,QAAAA,YACnB/B,KAAKwG,EAAOC,YAAY,CAAE1E,QAAAA,WAE/ByE,EAAS,IAAIjD,EAAMC,EAAM8C"}
|
@@ -0,0 +1,288 @@
|
|
1
|
+
this.workbox = this.workbox || {};
|
2
|
+
this.workbox.broadcastUpdate = (function (exports, assert_js, timeout_js, resultingClientExists_js, logger_js, WorkboxError_js, dontWaitFor_js) {
|
3
|
+
'use strict';
|
4
|
+
|
5
|
+
try {
|
6
|
+
self['workbox:broadcast-update:5.0.0'] && _();
|
7
|
+
} catch (e) {}
|
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 module:workbox-broadcast-update
|
26
|
+
*/
|
27
|
+
|
28
|
+
const responsesAreSame = (firstResponse, secondResponse, headersToCheck) => {
|
29
|
+
{
|
30
|
+
if (!(firstResponse instanceof Response && secondResponse instanceof Response)) {
|
31
|
+
throw new WorkboxError_js.WorkboxError('invalid-responses-are-same-args');
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
const atLeastOneHeaderAvailable = headersToCheck.some(header => {
|
36
|
+
return firstResponse.headers.has(header) && secondResponse.headers.has(header);
|
37
|
+
});
|
38
|
+
|
39
|
+
if (!atLeastOneHeaderAvailable) {
|
40
|
+
{
|
41
|
+
logger_js.logger.warn(`Unable to determine where the response has been updated ` + `because none of the headers that would be checked are present.`);
|
42
|
+
logger_js.logger.debug(`Attempting to compare the following: `, firstResponse, secondResponse, headersToCheck);
|
43
|
+
} // Just return true, indicating the that responses are the same, since we
|
44
|
+
// can't determine otherwise.
|
45
|
+
|
46
|
+
|
47
|
+
return true;
|
48
|
+
}
|
49
|
+
|
50
|
+
return headersToCheck.every(header => {
|
51
|
+
const headerStateComparison = firstResponse.headers.has(header) === secondResponse.headers.has(header);
|
52
|
+
const headerValueComparison = firstResponse.headers.get(header) === secondResponse.headers.get(header);
|
53
|
+
return headerStateComparison && headerValueComparison;
|
54
|
+
});
|
55
|
+
};
|
56
|
+
|
57
|
+
/*
|
58
|
+
Copyright 2018 Google LLC
|
59
|
+
|
60
|
+
Use of this source code is governed by an MIT-style
|
61
|
+
license that can be found in the LICENSE file or at
|
62
|
+
https://opensource.org/licenses/MIT.
|
63
|
+
*/
|
64
|
+
const CACHE_UPDATED_MESSAGE_TYPE = 'CACHE_UPDATED';
|
65
|
+
const CACHE_UPDATED_MESSAGE_META = 'workbox-broadcast-update';
|
66
|
+
const DEFAULT_HEADERS_TO_CHECK = ['content-length', 'etag', 'last-modified'];
|
67
|
+
|
68
|
+
/*
|
69
|
+
Copyright 2018 Google LLC
|
70
|
+
|
71
|
+
Use of this source code is governed by an MIT-style
|
72
|
+
license that can be found in the LICENSE file or at
|
73
|
+
https://opensource.org/licenses/MIT.
|
74
|
+
*/
|
75
|
+
// TODO(philipwalton): remove once this Safari bug fix has been released.
|
76
|
+
// https://bugs.webkit.org/show_bug.cgi?id=201169
|
77
|
+
|
78
|
+
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
|
79
|
+
/**
|
80
|
+
* Generates the default payload used in update messages. By default the
|
81
|
+
* payload includes the `cacheName` and `updatedURL` fields.
|
82
|
+
*
|
83
|
+
* @return Object
|
84
|
+
* @private
|
85
|
+
*/
|
86
|
+
|
87
|
+
function defaultPayloadGenerator(data) {
|
88
|
+
return {
|
89
|
+
cacheName: data.cacheName,
|
90
|
+
updatedURL: data.request.url
|
91
|
+
};
|
92
|
+
}
|
93
|
+
/**
|
94
|
+
* Uses the `postMessage()` API to inform any open windows/tabs when a cached
|
95
|
+
* response has been updated.
|
96
|
+
*
|
97
|
+
* For efficiency's sake, the underlying response bodies are not compared;
|
98
|
+
* only specific response headers are checked.
|
99
|
+
*
|
100
|
+
* @memberof module:workbox-broadcast-update
|
101
|
+
*/
|
102
|
+
|
103
|
+
|
104
|
+
class BroadcastCacheUpdate {
|
105
|
+
/**
|
106
|
+
* Construct a BroadcastCacheUpdate instance with a specific `channelName` to
|
107
|
+
* broadcast messages on
|
108
|
+
*
|
109
|
+
* @param {Object} options
|
110
|
+
* @param {Array<string>} [options.headersToCheck=['content-length', 'etag', 'last-modified']]
|
111
|
+
* A list of headers that will be used to determine whether the responses
|
112
|
+
* differ.
|
113
|
+
* @param {string} [options.generatePayload] A function whose return value
|
114
|
+
* will be used as the `payload` field in any cache update messages sent
|
115
|
+
* to the window clients.
|
116
|
+
*/
|
117
|
+
constructor({
|
118
|
+
headersToCheck,
|
119
|
+
generatePayload
|
120
|
+
} = {}) {
|
121
|
+
this._headersToCheck = headersToCheck || DEFAULT_HEADERS_TO_CHECK;
|
122
|
+
this._generatePayload = generatePayload || defaultPayloadGenerator;
|
123
|
+
}
|
124
|
+
/**
|
125
|
+
* Compares two [Responses](https://developer.mozilla.org/en-US/docs/Web/API/Response)
|
126
|
+
* and sends a message (via `postMessage()`) to all window clients if the
|
127
|
+
* responses differ (note: neither of the Responses can be
|
128
|
+
* {@link http://stackoverflow.com/questions/39109789|opaque}).
|
129
|
+
*
|
130
|
+
* The message that's posted has the following format (where `payload` can
|
131
|
+
* be customized via the `generatePayload` option the instance is created
|
132
|
+
* with):
|
133
|
+
*
|
134
|
+
* ```
|
135
|
+
* {
|
136
|
+
* type: 'CACHE_UPDATED',
|
137
|
+
* meta: 'workbox-broadcast-update',
|
138
|
+
* payload: {
|
139
|
+
* cacheName: 'the-cache-name',
|
140
|
+
* updatedURL: 'https://example.com/'
|
141
|
+
* }
|
142
|
+
* }
|
143
|
+
* ```
|
144
|
+
*
|
145
|
+
* @param {Object} options
|
146
|
+
* @param {Response} [options.oldResponse] Cached response to compare.
|
147
|
+
* @param {Response} options.newResponse Possibly updated response to compare.
|
148
|
+
* @param {Request} options.request The request.
|
149
|
+
* @param {string} options.cacheName Name of the cache the responses belong
|
150
|
+
* to. This is included in the broadcast message.
|
151
|
+
* @param {Event} [options.event] event An optional event that triggered
|
152
|
+
* this possible cache update.
|
153
|
+
* @return {Promise} Resolves once the update is sent.
|
154
|
+
*/
|
155
|
+
|
156
|
+
|
157
|
+
async notifyIfUpdated(options) {
|
158
|
+
{
|
159
|
+
assert_js.assert.isType(options.cacheName, 'string', {
|
160
|
+
moduleName: 'workbox-broadcast-update',
|
161
|
+
className: 'BroadcastCacheUpdate',
|
162
|
+
funcName: 'notifyIfUpdated',
|
163
|
+
paramName: 'cacheName'
|
164
|
+
});
|
165
|
+
assert_js.assert.isInstance(options.newResponse, Response, {
|
166
|
+
moduleName: 'workbox-broadcast-update',
|
167
|
+
className: 'BroadcastCacheUpdate',
|
168
|
+
funcName: 'notifyIfUpdated',
|
169
|
+
paramName: 'newResponse'
|
170
|
+
});
|
171
|
+
assert_js.assert.isInstance(options.request, Request, {
|
172
|
+
moduleName: 'workbox-broadcast-update',
|
173
|
+
className: 'BroadcastCacheUpdate',
|
174
|
+
funcName: 'notifyIfUpdated',
|
175
|
+
paramName: 'request'
|
176
|
+
});
|
177
|
+
} // Without two responses there is nothing to compare.
|
178
|
+
|
179
|
+
|
180
|
+
if (!options.oldResponse) {
|
181
|
+
return;
|
182
|
+
}
|
183
|
+
|
184
|
+
if (!responsesAreSame(options.oldResponse, options.newResponse, this._headersToCheck)) {
|
185
|
+
{
|
186
|
+
logger_js.logger.log(`Newer response found (and cached) for:`, options.request.url);
|
187
|
+
}
|
188
|
+
|
189
|
+
const messageData = {
|
190
|
+
type: CACHE_UPDATED_MESSAGE_TYPE,
|
191
|
+
meta: CACHE_UPDATED_MESSAGE_META,
|
192
|
+
payload: this._generatePayload(options)
|
193
|
+
}; // For navigation requests, wait until the new window client exists
|
194
|
+
// before sending the message
|
195
|
+
|
196
|
+
if (options.request.mode === 'navigate') {
|
197
|
+
let resultingClientId;
|
198
|
+
|
199
|
+
if (options.event instanceof FetchEvent) {
|
200
|
+
resultingClientId = options.event.resultingClientId;
|
201
|
+
}
|
202
|
+
|
203
|
+
const resultingWin = await resultingClientExists_js.resultingClientExists(resultingClientId); // Safari does not currently implement postMessage buffering and
|
204
|
+
// there's no good way to feature detect that, so to increase the
|
205
|
+
// chances of the message being delivered in Safari, we add a timeout.
|
206
|
+
// We also do this if `resultingClientExists()` didn't return a client,
|
207
|
+
// which means it timed out, so it's worth waiting a bit longer.
|
208
|
+
|
209
|
+
if (!resultingWin || isSafari) {
|
210
|
+
// 3500 is chosen because (according to CrUX data) 80% of mobile
|
211
|
+
// websites hit the DOMContentLoaded event in less than 3.5 seconds.
|
212
|
+
// And presumably sites implementing service worker are on the
|
213
|
+
// higher end of the performance spectrum.
|
214
|
+
await timeout_js.timeout(3500);
|
215
|
+
}
|
216
|
+
}
|
217
|
+
|
218
|
+
const windows = await self.clients.matchAll({
|
219
|
+
type: 'window'
|
220
|
+
});
|
221
|
+
|
222
|
+
for (const win of windows) {
|
223
|
+
win.postMessage(messageData);
|
224
|
+
}
|
225
|
+
}
|
226
|
+
}
|
227
|
+
|
228
|
+
}
|
229
|
+
|
230
|
+
/*
|
231
|
+
Copyright 2018 Google LLC
|
232
|
+
|
233
|
+
Use of this source code is governed by an MIT-style
|
234
|
+
license that can be found in the LICENSE file or at
|
235
|
+
https://opensource.org/licenses/MIT.
|
236
|
+
*/
|
237
|
+
/**
|
238
|
+
* This plugin will automatically broadcast a message whenever a cached response
|
239
|
+
* is updated.
|
240
|
+
*
|
241
|
+
* @memberof module:workbox-broadcast-update
|
242
|
+
*/
|
243
|
+
|
244
|
+
class BroadcastUpdatePlugin {
|
245
|
+
/**
|
246
|
+
* Construct a BroadcastCacheUpdate instance with the passed options and
|
247
|
+
* calls its [`notifyIfUpdated()`]{@link module:workbox-broadcast-update.BroadcastCacheUpdate~notifyIfUpdated}
|
248
|
+
* method whenever the plugin's `cacheDidUpdate` callback is invoked.
|
249
|
+
*
|
250
|
+
* @param {Object} options
|
251
|
+
* @param {Array<string>} [options.headersToCheck=['content-length', 'etag', 'last-modified']]
|
252
|
+
* A list of headers that will be used to determine whether the responses
|
253
|
+
* differ.
|
254
|
+
* @param {string} [options.generatePayload] A function whose return value
|
255
|
+
* will be used as the `payload` field in any cache update messages sent
|
256
|
+
* to the window clients.
|
257
|
+
*/
|
258
|
+
constructor(options) {
|
259
|
+
/**
|
260
|
+
* A "lifecycle" callback that will be triggered automatically by the
|
261
|
+
* `workbox-sw` and `workbox-runtime-caching` handlers when an entry is
|
262
|
+
* added to a cache.
|
263
|
+
*
|
264
|
+
* @private
|
265
|
+
* @param {Object} options The input object to this function.
|
266
|
+
* @param {string} options.cacheName Name of the cache being updated.
|
267
|
+
* @param {Response} [options.oldResponse] The previous cached value, if any.
|
268
|
+
* @param {Response} options.newResponse The new value in the cache.
|
269
|
+
* @param {Request} options.request The request that triggered the update.
|
270
|
+
* @param {Request} [options.event] The event that triggered the update.
|
271
|
+
*/
|
272
|
+
this.cacheDidUpdate = async options => {
|
273
|
+
dontWaitFor_js.dontWaitFor(this._broadcastUpdate.notifyIfUpdated(options));
|
274
|
+
};
|
275
|
+
|
276
|
+
this._broadcastUpdate = new BroadcastCacheUpdate(options);
|
277
|
+
}
|
278
|
+
|
279
|
+
}
|
280
|
+
|
281
|
+
exports.BroadcastCacheUpdate = BroadcastCacheUpdate;
|
282
|
+
exports.BroadcastUpdatePlugin = BroadcastUpdatePlugin;
|
283
|
+
exports.responsesAreSame = responsesAreSame;
|
284
|
+
|
285
|
+
return exports;
|
286
|
+
|
287
|
+
}({}, workbox.core._private, workbox.core._private, workbox.core._private, workbox.core._private, workbox.core._private, workbox.core._private));
|
288
|
+
//# sourceMappingURL=workbox-broadcast-update.dev.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"workbox-broadcast-update.dev.js","sources":["../_version.js","../responsesAreSame.js","../utils/constants.js","../BroadcastCacheUpdate.js","../BroadcastUpdatePlugin.js"],"sourcesContent":["\"use strict\";\n// @ts-ignore\ntry {\n self['workbox:broadcast-update:5.0.0'] && _();\n}\ncatch (e) { }\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*/\nimport { WorkboxError } from 'workbox-core/_private/WorkboxError.js';\nimport { logger } from 'workbox-core/_private/logger.js';\nimport './_version.js';\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 module:workbox-broadcast-update\n */\nconst responsesAreSame = (firstResponse, secondResponse, headersToCheck) => {\n if (process.env.NODE_ENV !== 'production') {\n if (!(firstResponse instanceof Response &&\n secondResponse instanceof Response)) {\n throw new WorkboxError('invalid-responses-are-same-args');\n }\n }\n const atLeastOneHeaderAvailable = headersToCheck.some((header) => {\n return firstResponse.headers.has(header) &&\n secondResponse.headers.has(header);\n });\n if (!atLeastOneHeaderAvailable) {\n if (process.env.NODE_ENV !== 'production') {\n logger.warn(`Unable to determine where the response has been updated ` +\n `because none of the headers that would be checked are present.`);\n logger.debug(`Attempting to compare the following: `, firstResponse, secondResponse, headersToCheck);\n }\n // Just return true, indicating the that responses are the same, since we\n // can't determine otherwise.\n return true;\n }\n return headersToCheck.every((header) => {\n const headerStateComparison = firstResponse.headers.has(header) ===\n secondResponse.headers.has(header);\n const headerValueComparison = firstResponse.headers.get(header) ===\n secondResponse.headers.get(header);\n return headerStateComparison && headerValueComparison;\n });\n};\nexport { responsesAreSame };\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*/\nimport '../_version.js';\nexport const CACHE_UPDATED_MESSAGE_TYPE = 'CACHE_UPDATED';\nexport const CACHE_UPDATED_MESSAGE_META = 'workbox-broadcast-update';\nexport const DEFAULT_HEADERS_TO_CHECK = [\n 'content-length',\n 'etag',\n 'last-modified',\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*/\nimport { assert } from 'workbox-core/_private/assert.js';\nimport { timeout } from 'workbox-core/_private/timeout.js';\nimport { resultingClientExists } from 'workbox-core/_private/resultingClientExists.js';\nimport { logger } from 'workbox-core/_private/logger.js';\nimport { responsesAreSame } from './responsesAreSame.js';\nimport { CACHE_UPDATED_MESSAGE_TYPE, CACHE_UPDATED_MESSAGE_META, DEFAULT_HEADERS_TO_CHECK } from './utils/constants.js';\nimport './_version.js';\n// UA-sniff Safari: https://stackoverflow.com/questions/7944460/detect-safari-browser\n// TODO(philipwalton): remove once this Safari bug fix has been released.\n// https://bugs.webkit.org/show_bug.cgi?id=201169\nconst isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);\n/**\n * Generates the default payload used in update messages. By default the\n * payload includes the `cacheName` and `updatedURL` fields.\n *\n * @return Object\n * @private\n */\nfunction defaultPayloadGenerator(data) {\n return {\n cacheName: data.cacheName,\n updatedURL: data.request.url,\n };\n}\n/**\n * Uses the `postMessage()` API to inform any open windows/tabs when a cached\n * 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 module:workbox-broadcast-update\n */\nclass BroadcastCacheUpdate {\n /**\n * Construct a BroadcastCacheUpdate instance with a specific `channelName` to\n * broadcast messages on\n *\n * @param {Object} options\n * @param {Array<string>} [options.headersToCheck=['content-length', 'etag', 'last-modified']]\n * A list of headers that will be used to determine whether the responses\n * differ.\n * @param {string} [options.generatePayload] A function whose return value\n * will be used as the `payload` field in any cache update messages sent\n * to the window clients.\n */\n constructor({ headersToCheck, generatePayload, } = {}) {\n this._headersToCheck = headersToCheck || DEFAULT_HEADERS_TO_CHECK;\n this._generatePayload = generatePayload || defaultPayloadGenerator;\n }\n /**\n * Compares two [Responses](https://developer.mozilla.org/en-US/docs/Web/API/Response)\n * and sends a message (via `postMessage()`) to all window clients if the\n * responses differ (note: neither of the Responses can be\n * {@link http://stackoverflow.com/questions/39109789|opaque}).\n *\n * The message that's posted has the following format (where `payload` can\n * be customized via the `generatePayload` option the instance is created\n * with):\n *\n * ```\n * {\n * type: 'CACHE_UPDATED',\n * meta: 'workbox-broadcast-update',\n * payload: {\n * cacheName: 'the-cache-name',\n * updatedURL: 'https://example.com/'\n * }\n * }\n * ```\n *\n * @param {Object} options\n * @param {Response} [options.oldResponse] Cached response to compare.\n * @param {Response} options.newResponse Possibly updated response to compare.\n * @param {Request} options.request The request.\n * @param {string} options.cacheName Name of the cache the responses belong\n * to. This is included in the broadcast message.\n * @param {Event} [options.event] event An optional event that triggered\n * this possible cache update.\n * @return {Promise} Resolves once the update is sent.\n */\n async notifyIfUpdated(options) {\n if (process.env.NODE_ENV !== 'production') {\n assert.isType(options.cacheName, 'string', {\n moduleName: 'workbox-broadcast-update',\n className: 'BroadcastCacheUpdate',\n funcName: 'notifyIfUpdated',\n paramName: 'cacheName',\n });\n assert.isInstance(options.newResponse, Response, {\n moduleName: 'workbox-broadcast-update',\n className: 'BroadcastCacheUpdate',\n funcName: 'notifyIfUpdated',\n paramName: 'newResponse',\n });\n assert.isInstance(options.request, Request, {\n moduleName: 'workbox-broadcast-update',\n className: 'BroadcastCacheUpdate',\n funcName: 'notifyIfUpdated',\n paramName: 'request',\n });\n }\n // Without two responses there is nothing to compare.\n if (!options.oldResponse) {\n return;\n }\n if (!responsesAreSame(options.oldResponse, options.newResponse, this._headersToCheck)) {\n if (process.env.NODE_ENV !== 'production') {\n logger.log(`Newer response found (and cached) for:`, options.request.url);\n }\n const messageData = {\n type: CACHE_UPDATED_MESSAGE_TYPE,\n meta: CACHE_UPDATED_MESSAGE_META,\n payload: this._generatePayload(options),\n };\n // For navigation requests, wait until the new window client exists\n // before sending the message\n if (options.request.mode === 'navigate') {\n let resultingClientId;\n if (options.event instanceof FetchEvent) {\n resultingClientId = options.event.resultingClientId;\n }\n const resultingWin = await resultingClientExists(resultingClientId);\n // Safari does not currently implement postMessage buffering and\n // there's no good way to feature detect that, so to increase the\n // chances of the message being delivered in Safari, we add a timeout.\n // We also do this if `resultingClientExists()` didn't return a client,\n // which means it timed out, so it's worth waiting a bit longer.\n if (!resultingWin || isSafari) {\n // 3500 is chosen because (according to CrUX data) 80% of mobile\n // websites hit the DOMContentLoaded event in less than 3.5 seconds.\n // And presumably sites implementing service worker are on the\n // higher end of the performance spectrum.\n await timeout(3500);\n }\n }\n const windows = await self.clients.matchAll({ type: 'window' });\n for (const win of windows) {\n win.postMessage(messageData);\n }\n }\n }\n}\nexport { BroadcastCacheUpdate };\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*/\nimport { dontWaitFor } from 'workbox-core/_private/dontWaitFor.js';\nimport { BroadcastCacheUpdate } from './BroadcastCacheUpdate.js';\nimport './_version.js';\n/**\n * This plugin will automatically broadcast a message whenever a cached response\n * is updated.\n *\n * @memberof module:workbox-broadcast-update\n */\nclass BroadcastUpdatePlugin {\n /**\n * Construct a BroadcastCacheUpdate instance with the passed options and\n * calls its [`notifyIfUpdated()`]{@link module:workbox-broadcast-update.BroadcastCacheUpdate~notifyIfUpdated}\n * method whenever the plugin's `cacheDidUpdate` callback is invoked.\n *\n * @param {Object} options\n * @param {Array<string>} [options.headersToCheck=['content-length', 'etag', 'last-modified']]\n * A list of headers that will be used to determine whether the responses\n * differ.\n * @param {string} [options.generatePayload] A function whose return value\n * will be used as the `payload` field in any cache update messages sent\n * to the window clients.\n */\n constructor(options) {\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 * @param {Request} options.request The request that triggered the update.\n * @param {Request} [options.event] The event that triggered the update.\n */\n this.cacheDidUpdate = async (options) => {\n dontWaitFor(this._broadcastUpdate.notifyIfUpdated(options));\n };\n this._broadcastUpdate = new BroadcastCacheUpdate(options);\n }\n}\nexport { BroadcastUpdatePlugin };\n"],"names":["self","_","e","responsesAreSame","firstResponse","secondResponse","headersToCheck","Response","WorkboxError","atLeastOneHeaderAvailable","some","header","headers","has","logger","warn","debug","every","headerStateComparison","headerValueComparison","get","CACHE_UPDATED_MESSAGE_TYPE","CACHE_UPDATED_MESSAGE_META","DEFAULT_HEADERS_TO_CHECK","isSafari","test","navigator","userAgent","defaultPayloadGenerator","data","cacheName","updatedURL","request","url","BroadcastCacheUpdate","constructor","generatePayload","_headersToCheck","_generatePayload","notifyIfUpdated","options","assert","isType","moduleName","className","funcName","paramName","isInstance","newResponse","Request","oldResponse","log","messageData","type","meta","payload","mode","resultingClientId","event","FetchEvent","resultingWin","resultingClientExists","timeout","windows","clients","matchAll","win","postMessage","BroadcastUpdatePlugin","cacheDidUpdate","dontWaitFor","_broadcastUpdate"],"mappings":";;;;IAEA,IAAI;IACAA,EAAAA,IAAI,CAAC,gCAAD,CAAJ,IAA0CC,CAAC,EAA3C;IACH,CAFD,CAGA,OAAOC,CAAP,EAAU;;ICLV;;;;;;;AAOA,IAGA;;;;;;;;;;;;AAWA,UAAMC,gBAAgB,GAAG,CAACC,aAAD,EAAgBC,cAAhB,EAAgCC,cAAhC,KAAmD;IACxE,EAA2C;IACvC,QAAI,EAAEF,aAAa,YAAYG,QAAzB,IACFF,cAAc,YAAYE,QAD1B,CAAJ,EACyC;IACrC,YAAM,IAAIC,4BAAJ,CAAiB,iCAAjB,CAAN;IACH;IACJ;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;;;;;;;;;;IAaA,SAAK6B,cAAL,GAAsB,MAAO7B,OAAP,IAAmB;IACrC8B,MAAAA,0BAAW,CAAC,KAAKC,gBAAL,CAAsBhC,eAAtB,CAAsCC,OAAtC,CAAD,CAAX;IACH,KAFD;;IAGA,SAAK+B,gBAAL,GAAwB,IAAIrC,oBAAJ,CAAyBM,OAAzB,CAAxB;IACH;;IAhCuB;;;;;;;;;;;;"}
|
@@ -0,0 +1,2 @@
|
|
1
|
+
this.workbox=this.workbox||{},this.workbox.broadcastUpdate=function(t,a,o,e){"use strict";try{self["workbox:broadcast-update:5.0.0"]&&_()}catch(t){}const s=(t,a,o)=>{return!o.some(o=>t.headers.has(o)&&a.headers.has(o))||o.every(o=>{const e=t.headers.has(o)===a.headers.has(o),s=t.headers.get(o)===a.headers.get(o);return e&&s})},n="CACHE_UPDATED",i="workbox-broadcast-update",c=["content-length","etag","last-modified"],r=/^((?!chrome|android).)*safari/i.test(navigator.userAgent);function h(t){return{cacheName:t.cacheName,updatedURL:t.request.url}}class d{constructor({headersToCheck:t,generatePayload:a}={}){this.t=t||c,this.o=a||h}async notifyIfUpdated(t){if(t.oldResponse&&!s(t.oldResponse,t.newResponse,this.t)){const e={type:n,meta:i,payload:this.o(t)};if("navigate"===t.request.mode){let e;t.event instanceof FetchEvent&&(e=t.event.resultingClientId),await o.resultingClientExists(e)&&!r||await a.timeout(3500)}const s=await self.clients.matchAll({type:"window"});for(const t of s)t.postMessage(e)}}}return t.BroadcastCacheUpdate=d,t.BroadcastUpdatePlugin=class{constructor(t){this.cacheDidUpdate=(async t=>{e.dontWaitFor(this.s.notifyIfUpdated(t))}),this.s=new d(t)}},t.responsesAreSame=s,t}({},workbox.core._private,workbox.core._private,workbox.core._private);
|
2
|
+
//# sourceMappingURL=workbox-broadcast-update.prod.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"workbox-broadcast-update.prod.js","sources":["../_version.js","../responsesAreSame.js","../utils/constants.js","../BroadcastCacheUpdate.js","../BroadcastUpdatePlugin.js"],"sourcesContent":["\"use strict\";\n// @ts-ignore\ntry {\n self['workbox:broadcast-update:5.0.0'] && _();\n}\ncatch (e) { }\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*/\nimport { WorkboxError } from 'workbox-core/_private/WorkboxError.js';\nimport { logger } from 'workbox-core/_private/logger.js';\nimport './_version.js';\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 module:workbox-broadcast-update\n */\nconst responsesAreSame = (firstResponse, secondResponse, headersToCheck) => {\n if (process.env.NODE_ENV !== 'production') {\n if (!(firstResponse instanceof Response &&\n secondResponse instanceof Response)) {\n throw new WorkboxError('invalid-responses-are-same-args');\n }\n }\n const atLeastOneHeaderAvailable = headersToCheck.some((header) => {\n return firstResponse.headers.has(header) &&\n secondResponse.headers.has(header);\n });\n if (!atLeastOneHeaderAvailable) {\n if (process.env.NODE_ENV !== 'production') {\n logger.warn(`Unable to determine where the response has been updated ` +\n `because none of the headers that would be checked are present.`);\n logger.debug(`Attempting to compare the following: `, firstResponse, secondResponse, headersToCheck);\n }\n // Just return true, indicating the that responses are the same, since we\n // can't determine otherwise.\n return true;\n }\n return headersToCheck.every((header) => {\n const headerStateComparison = firstResponse.headers.has(header) ===\n secondResponse.headers.has(header);\n const headerValueComparison = firstResponse.headers.get(header) ===\n secondResponse.headers.get(header);\n return headerStateComparison && headerValueComparison;\n });\n};\nexport { responsesAreSame };\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*/\nimport '../_version.js';\nexport const CACHE_UPDATED_MESSAGE_TYPE = 'CACHE_UPDATED';\nexport const CACHE_UPDATED_MESSAGE_META = 'workbox-broadcast-update';\nexport const DEFAULT_HEADERS_TO_CHECK = [\n 'content-length',\n 'etag',\n 'last-modified',\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*/\nimport { assert } from 'workbox-core/_private/assert.js';\nimport { timeout } from 'workbox-core/_private/timeout.js';\nimport { resultingClientExists } from 'workbox-core/_private/resultingClientExists.js';\nimport { logger } from 'workbox-core/_private/logger.js';\nimport { responsesAreSame } from './responsesAreSame.js';\nimport { CACHE_UPDATED_MESSAGE_TYPE, CACHE_UPDATED_MESSAGE_META, DEFAULT_HEADERS_TO_CHECK } from './utils/constants.js';\nimport './_version.js';\n// UA-sniff Safari: https://stackoverflow.com/questions/7944460/detect-safari-browser\n// TODO(philipwalton): remove once this Safari bug fix has been released.\n// https://bugs.webkit.org/show_bug.cgi?id=201169\nconst isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);\n/**\n * Generates the default payload used in update messages. By default the\n * payload includes the `cacheName` and `updatedURL` fields.\n *\n * @return Object\n * @private\n */\nfunction defaultPayloadGenerator(data) {\n return {\n cacheName: data.cacheName,\n updatedURL: data.request.url,\n };\n}\n/**\n * Uses the `postMessage()` API to inform any open windows/tabs when a cached\n * 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 module:workbox-broadcast-update\n */\nclass BroadcastCacheUpdate {\n /**\n * Construct a BroadcastCacheUpdate instance with a specific `channelName` to\n * broadcast messages on\n *\n * @param {Object} options\n * @param {Array<string>} [options.headersToCheck=['content-length', 'etag', 'last-modified']]\n * A list of headers that will be used to determine whether the responses\n * differ.\n * @param {string} [options.generatePayload] A function whose return value\n * will be used as the `payload` field in any cache update messages sent\n * to the window clients.\n */\n constructor({ headersToCheck, generatePayload, } = {}) {\n this._headersToCheck = headersToCheck || DEFAULT_HEADERS_TO_CHECK;\n this._generatePayload = generatePayload || defaultPayloadGenerator;\n }\n /**\n * Compares two [Responses](https://developer.mozilla.org/en-US/docs/Web/API/Response)\n * and sends a message (via `postMessage()`) to all window clients if the\n * responses differ (note: neither of the Responses can be\n * {@link http://stackoverflow.com/questions/39109789|opaque}).\n *\n * The message that's posted has the following format (where `payload` can\n * be customized via the `generatePayload` option the instance is created\n * with):\n *\n * ```\n * {\n * type: 'CACHE_UPDATED',\n * meta: 'workbox-broadcast-update',\n * payload: {\n * cacheName: 'the-cache-name',\n * updatedURL: 'https://example.com/'\n * }\n * }\n * ```\n *\n * @param {Object} options\n * @param {Response} [options.oldResponse] Cached response to compare.\n * @param {Response} options.newResponse Possibly updated response to compare.\n * @param {Request} options.request The request.\n * @param {string} options.cacheName Name of the cache the responses belong\n * to. This is included in the broadcast message.\n * @param {Event} [options.event] event An optional event that triggered\n * this possible cache update.\n * @return {Promise} Resolves once the update is sent.\n */\n async notifyIfUpdated(options) {\n if (process.env.NODE_ENV !== 'production') {\n assert.isType(options.cacheName, 'string', {\n moduleName: 'workbox-broadcast-update',\n className: 'BroadcastCacheUpdate',\n funcName: 'notifyIfUpdated',\n paramName: 'cacheName',\n });\n assert.isInstance(options.newResponse, Response, {\n moduleName: 'workbox-broadcast-update',\n className: 'BroadcastCacheUpdate',\n funcName: 'notifyIfUpdated',\n paramName: 'newResponse',\n });\n assert.isInstance(options.request, Request, {\n moduleName: 'workbox-broadcast-update',\n className: 'BroadcastCacheUpdate',\n funcName: 'notifyIfUpdated',\n paramName: 'request',\n });\n }\n // Without two responses there is nothing to compare.\n if (!options.oldResponse) {\n return;\n }\n if (!responsesAreSame(options.oldResponse, options.newResponse, this._headersToCheck)) {\n if (process.env.NODE_ENV !== 'production') {\n logger.log(`Newer response found (and cached) for:`, options.request.url);\n }\n const messageData = {\n type: CACHE_UPDATED_MESSAGE_TYPE,\n meta: CACHE_UPDATED_MESSAGE_META,\n payload: this._generatePayload(options),\n };\n // For navigation requests, wait until the new window client exists\n // before sending the message\n if (options.request.mode === 'navigate') {\n let resultingClientId;\n if (options.event instanceof FetchEvent) {\n resultingClientId = options.event.resultingClientId;\n }\n const resultingWin = await resultingClientExists(resultingClientId);\n // Safari does not currently implement postMessage buffering and\n // there's no good way to feature detect that, so to increase the\n // chances of the message being delivered in Safari, we add a timeout.\n // We also do this if `resultingClientExists()` didn't return a client,\n // which means it timed out, so it's worth waiting a bit longer.\n if (!resultingWin || isSafari) {\n // 3500 is chosen because (according to CrUX data) 80% of mobile\n // websites hit the DOMContentLoaded event in less than 3.5 seconds.\n // And presumably sites implementing service worker are on the\n // higher end of the performance spectrum.\n await timeout(3500);\n }\n }\n const windows = await self.clients.matchAll({ type: 'window' });\n for (const win of windows) {\n win.postMessage(messageData);\n }\n }\n }\n}\nexport { BroadcastCacheUpdate };\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*/\nimport { dontWaitFor } from 'workbox-core/_private/dontWaitFor.js';\nimport { BroadcastCacheUpdate } from './BroadcastCacheUpdate.js';\nimport './_version.js';\n/**\n * This plugin will automatically broadcast a message whenever a cached response\n * is updated.\n *\n * @memberof module:workbox-broadcast-update\n */\nclass BroadcastUpdatePlugin {\n /**\n * Construct a BroadcastCacheUpdate instance with the passed options and\n * calls its [`notifyIfUpdated()`]{@link module:workbox-broadcast-update.BroadcastCacheUpdate~notifyIfUpdated}\n * method whenever the plugin's `cacheDidUpdate` callback is invoked.\n *\n * @param {Object} options\n * @param {Array<string>} [options.headersToCheck=['content-length', 'etag', 'last-modified']]\n * A list of headers that will be used to determine whether the responses\n * differ.\n * @param {string} [options.generatePayload] A function whose return value\n * will be used as the `payload` field in any cache update messages sent\n * to the window clients.\n */\n constructor(options) {\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 * @param {Request} options.request The request that triggered the update.\n * @param {Request} [options.event] The event that triggered the update.\n */\n this.cacheDidUpdate = async (options) => {\n dontWaitFor(this._broadcastUpdate.notifyIfUpdated(options));\n };\n this._broadcastUpdate = new BroadcastCacheUpdate(options);\n }\n}\nexport { BroadcastUpdatePlugin };\n"],"names":["self","_","e","responsesAreSame","firstResponse","secondResponse","headersToCheck","some","header","headers","has","every","headerStateComparison","headerValueComparison","get","CACHE_UPDATED_MESSAGE_TYPE","CACHE_UPDATED_MESSAGE_META","DEFAULT_HEADERS_TO_CHECK","isSafari","test","navigator","userAgent","defaultPayloadGenerator","data","cacheName","updatedURL","request","url","BroadcastCacheUpdate","constructor","generatePayload","_headersToCheck","_generatePayload","options","oldResponse","newResponse","this","messageData","type","meta","payload","mode","resultingClientId","event","FetchEvent","resultingClientExists","timeout","windows","clients","matchAll","win","postMessage","cacheDidUpdate","async","dontWaitFor","_broadcastUpdate","notifyIfUpdated"],"mappings":"0FAEA,IACIA,KAAK,mCAAqCC,IAE9C,MAAOC,UCgBDC,EAAmB,CAACC,EAAeC,EAAgBC,YAOnBA,EAAeC,KAAMC,GAC5CJ,EAAcK,QAAQC,IAAIF,IAC7BH,EAAeI,QAAQC,IAAIF,KAY5BF,EAAeK,MAAOH,UACnBI,EAAwBR,EAAcK,QAAQC,IAAIF,KACpDH,EAAeI,QAAQC,IAAIF,GACzBK,EAAwBT,EAAcK,QAAQK,IAAIN,KACpDH,EAAeI,QAAQK,IAAIN,UACxBI,GAAyBC,KCvC3BE,EAA6B,gBAC7BC,EAA6B,2BAC7BC,EAA2B,CACpC,iBACA,OACA,iBCIEC,EAAW,iCAAiCC,KAAKC,UAAUC,WAQjE,SAASC,EAAwBC,SACtB,CACHC,UAAWD,EAAKC,UAChBC,WAAYF,EAAKG,QAAQC,KAYjC,MAAMC,EAaFC,aAAYvB,eAAEA,EAAFwB,gBAAkBA,GAAqB,SAC1CC,EAAkBzB,GAAkBW,OACpCe,EAAmBF,GAAmBR,wBAiCzBW,MAsBbA,EAAQC,cAGR/B,EAAiB8B,EAAQC,YAAaD,EAAQE,YAAaC,KAAKL,GAAkB,OAI7EM,EAAc,CAChBC,KAAMvB,EACNwB,KAAMvB,EACNwB,QAASJ,KAAKJ,EAAiBC,OAIN,aAAzBA,EAAQP,QAAQe,KAAqB,KACjCC,EACAT,EAAQU,iBAAiBC,aACzBF,EAAoBT,EAAQU,MAAMD,yBAEXG,wBAAsBH,KAM5BxB,SAKX4B,UAAQ,YAGhBC,QAAgB/C,KAAKgD,QAAQC,SAAS,CAAEX,KAAM,eAC/C,MAAMY,KAAOH,EACdG,EAAIC,YAAYd,6DCjIhC,MAcIR,YAAYI,QAcHmB,eAAiBC,OAAAA,IAClBC,cAAYlB,KAAKmB,EAAiBC,gBAAgBvB,WAEjDsB,EAAmB,IAAI3B,EAAqBK"}
|
@@ -2,9 +2,8 @@ this.workbox = this.workbox || {};
|
|
2
2
|
this.workbox.cacheableResponse = (function (exports, assert_js, WorkboxError_js, getFriendlyURL_js, logger_js) {
|
3
3
|
'use strict';
|
4
4
|
|
5
|
-
// @ts-ignore
|
6
5
|
try {
|
7
|
-
self['workbox:cacheable-response:5.0.0
|
6
|
+
self['workbox:cacheable-response:5.0.0'] && _();
|
8
7
|
} catch (e) {}
|
9
8
|
|
10
9
|
/*
|
@@ -20,7 +19,7 @@ this.workbox.cacheableResponse = (function (exports, assert_js, WorkboxError_js,
|
|
20
19
|
* [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
|
21
20
|
* to be considered cacheable.
|
22
21
|
*
|
23
|
-
* @memberof workbox
|
22
|
+
* @memberof module:workbox-cacheable-response
|
24
23
|
*/
|
25
24
|
|
26
25
|
class CacheableResponse {
|
@@ -143,12 +142,12 @@ this.workbox.cacheableResponse = (function (exports, assert_js, WorkboxError_js,
|
|
143
142
|
* easier to add in cacheability checks to requests made via Workbox's built-in
|
144
143
|
* strategies.
|
145
144
|
*
|
146
|
-
* @memberof workbox
|
145
|
+
* @memberof module:workbox-cacheable-response
|
147
146
|
*/
|
148
147
|
|
149
|
-
class
|
148
|
+
class CacheableResponsePlugin {
|
150
149
|
/**
|
151
|
-
* To construct a new
|
150
|
+
* To construct a new CacheableResponsePlugin instance you must provide at
|
152
151
|
* least one of the `config` properties.
|
153
152
|
*
|
154
153
|
* If both `statuses` and `headers` are specified, then both conditions must
|
@@ -184,7 +183,7 @@ this.workbox.cacheableResponse = (function (exports, assert_js, WorkboxError_js,
|
|
184
183
|
}
|
185
184
|
|
186
185
|
exports.CacheableResponse = CacheableResponse;
|
187
|
-
exports.
|
186
|
+
exports.CacheableResponsePlugin = CacheableResponsePlugin;
|
188
187
|
|
189
188
|
return exports;
|
190
189
|
|