jekyll-pwa-plugin 1.0.2 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/jekyll-pwa-plugin.rb +18 -36
- data/lib/vendor/workbox-v3.3.1/workbox-background-sync.dev.js +593 -0
- data/lib/vendor/workbox-v3.3.1/workbox-background-sync.dev.js.map +1 -0
- data/lib/vendor/workbox-v3.3.1/workbox-background-sync.prod.js +3 -0
- data/lib/vendor/workbox-v3.3.1/workbox-background-sync.prod.js.map +1 -0
- data/lib/vendor/workbox-v3.3.1/workbox-broadcast-cache-update.dev.js +395 -0
- data/lib/vendor/workbox-v3.3.1/workbox-broadcast-cache-update.dev.js.map +1 -0
- data/lib/vendor/workbox-v3.3.1/workbox-broadcast-cache-update.prod.js +3 -0
- data/lib/vendor/workbox-v3.3.1/workbox-broadcast-cache-update.prod.js.map +1 -0
- data/lib/vendor/workbox-v3.3.1/workbox-cache-expiration.dev.js +740 -0
- data/lib/vendor/workbox-v3.3.1/workbox-cache-expiration.dev.js.map +1 -0
- data/lib/vendor/workbox-v3.3.1/workbox-cache-expiration.prod.js +3 -0
- data/lib/vendor/workbox-v3.3.1/workbox-cache-expiration.prod.js.map +1 -0
- data/lib/vendor/workbox-v3.3.1/workbox-cacheable-response.dev.js +236 -0
- data/lib/vendor/workbox-v3.3.1/workbox-cacheable-response.dev.js.map +1 -0
- data/lib/vendor/workbox-v3.3.1/workbox-cacheable-response.prod.js +3 -0
- data/lib/vendor/workbox-v3.3.1/workbox-cacheable-response.prod.js.map +1 -0
- data/lib/vendor/workbox-v3.3.1/workbox-core.dev.js +1690 -0
- data/lib/vendor/workbox-v3.3.1/workbox-core.dev.js.map +1 -0
- data/lib/vendor/workbox-v3.3.1/workbox-core.prod.js +3 -0
- data/lib/vendor/workbox-v3.3.1/workbox-core.prod.js.map +1 -0
- data/lib/vendor/workbox-v3.3.1/workbox-google-analytics.dev.js +255 -0
- data/lib/vendor/workbox-v3.3.1/workbox-google-analytics.dev.js.map +1 -0
- data/lib/vendor/workbox-v3.3.1/workbox-google-analytics.prod.js +3 -0
- data/lib/vendor/workbox-v3.3.1/workbox-google-analytics.prod.js.map +1 -0
- data/lib/vendor/workbox-v3.3.1/workbox-precaching.dev.js +1149 -0
- data/lib/vendor/workbox-v3.3.1/workbox-precaching.dev.js.map +1 -0
- data/lib/vendor/workbox-v3.3.1/workbox-precaching.prod.js +3 -0
- data/lib/vendor/workbox-v3.3.1/workbox-precaching.prod.js.map +1 -0
- data/lib/vendor/workbox-v3.3.1/workbox-range-requests.dev.js +299 -0
- data/lib/vendor/workbox-v3.3.1/workbox-range-requests.dev.js.map +1 -0
- data/lib/vendor/workbox-v3.3.1/workbox-range-requests.prod.js +3 -0
- data/lib/vendor/workbox-v3.3.1/workbox-range-requests.prod.js.map +1 -0
- data/lib/vendor/workbox-v3.3.1/workbox-routing.dev.js +863 -0
- data/lib/vendor/workbox-v3.3.1/workbox-routing.dev.js.map +1 -0
- data/lib/vendor/workbox-v3.3.1/workbox-routing.prod.js +3 -0
- data/lib/vendor/workbox-v3.3.1/workbox-routing.prod.js.map +1 -0
- data/lib/vendor/workbox-v3.3.1/workbox-strategies.dev.js +1091 -0
- data/lib/vendor/workbox-v3.3.1/workbox-strategies.dev.js.map +1 -0
- data/lib/vendor/workbox-v3.3.1/workbox-strategies.prod.js +3 -0
- data/lib/vendor/workbox-v3.3.1/workbox-strategies.prod.js.map +1 -0
- data/lib/vendor/workbox-v3.3.1/workbox-streams.dev.js +390 -0
- data/lib/vendor/workbox-v3.3.1/workbox-streams.dev.js.map +1 -0
- data/lib/vendor/workbox-v3.3.1/workbox-streams.prod.js +3 -0
- data/lib/vendor/workbox-v3.3.1/workbox-streams.prod.js.map +1 -0
- data/lib/vendor/workbox-v3.3.1/workbox-sw.js +3 -0
- data/lib/vendor/workbox-v3.3.1/workbox-sw.js.map +1 -0
- metadata +48 -3
- data/lib/vendor/workbox-sw.prod.v2.1.1.js +0 -186
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":[],"mappings":"","sources":["packages/workbox-background-sync/browser.mjs"],"sourcesContent":["this.workbox = this.workbox || {};\nthis.workbox.backgroundSync = (function (DBWrapper_mjs,WorkboxError_mjs,logger_mjs,assert_mjs,getFriendlyURL_mjs) {\n 'use strict';\n\n try {\n self.workbox.v['workbox:background-sync:3.3.1'] = 1;\n } catch (e) {} // eslint-disable-line\n\n /*\n Copyright 2017 Google Inc. All Rights Reserved.\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n */\n\n const serializableProperties = ['method', 'referrer', 'referrerPolicy', 'mode', 'credentials', 'cache', 'redirect', 'integrity', 'keepalive'];\n\n /**\n * A class to make it easier to serialize and de-serialize requests so they\n * can be stored in IndexedDB.\n *\n * @private\n */\n class StorableRequest {\n /**\n * Converts a Request object to a plain object that can be structured\n * cloned or JSON-stringified.\n *\n * @param {Request} request\n * @return {Promise<StorableRequest>}\n *\n * @private\n */\n static fromRequest(request) {\n return babelHelpers.asyncToGenerator(function* () {\n const requestInit = { headers: {} };\n\n // Set the body if present.\n if (request.method !== 'GET') {\n // Use blob to support non-text request bodies,\n // and clone first in case the caller still needs the request.\n requestInit.body = yield request.clone().blob();\n }\n\n // Convert the headers from an iterable to an object.\n for (const [key, value] of request.headers.entries()) {\n requestInit.headers[key] = value;\n }\n\n // Add all other serializable request properties\n for (const prop of serializableProperties) {\n if (request[prop] !== undefined) {\n requestInit[prop] = request[prop];\n }\n }\n\n return new StorableRequest({ url: request.url, requestInit });\n })();\n }\n\n /**\n * Accepts a URL and RequestInit dictionary that can be used to create a\n * new Request object. A timestamp is also generated so consumers can\n * reference when the object was created.\n *\n * @param {Object} param1\n * @param {string} param1.url\n * @param {Object} param1.requestInit\n * See: https://fetch.spec.whatwg.org/#requestinit\n * @param {number} param1.timestamp The time the request was created,\n * defaulting to the current time if not specified.\n *\n * @private\n */\n constructor({ url, requestInit, timestamp = Date.now() }) {\n this.url = url;\n this.requestInit = requestInit;\n\n // \"Private\"\n this._timestamp = timestamp;\n }\n\n /**\n * Gets the private _timestamp property.\n *\n * @return {number}\n *\n * @private\n */\n get timestamp() {\n return this._timestamp;\n }\n\n /**\n * Coverts this instance to a plain Object.\n *\n * @return {Object}\n *\n * @private\n */\n toObject() {\n return {\n url: this.url,\n timestamp: this.timestamp,\n requestInit: this.requestInit\n };\n }\n\n /**\n * Converts this instance to a Request.\n *\n * @return {Request}\n *\n * @private\n */\n toRequest() {\n return new Request(this.url, this.requestInit);\n }\n\n /**\n * Creates and returns a deep clone of the instance.\n *\n * @return {StorableRequest}\n *\n * @private\n */\n clone() {\n const requestInit = Object.assign({}, this.requestInit);\n requestInit.headers = Object.assign({}, this.requestInit.headers);\n if (this.requestInit.body) {\n requestInit.body = this.requestInit.body.slice();\n }\n\n return new StorableRequest({\n url: this.url,\n timestamp: this.timestamp,\n requestInit\n });\n }\n }\n\n /*\n Copyright 2017 Google Inc. All Rights Reserved.\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n */\n\n const DB_NAME = 'workbox-background-sync';\n const OBJECT_STORE_NAME = 'requests';\n const INDEXED_PROP = 'queueName';\n const TAG_PREFIX = 'workbox-background-sync';\n const MAX_RETENTION_TIME = 60 * 24 * 7; // 7 days in minutes\n\n /*\n Copyright 2017 Google Inc. All Rights Reserved.\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n */\n\n /**\n * A class to manage storing requests from a Queue in IndexedbDB,\n * indexed by their queue name for easier access.\n *\n * @private\n */\n class QueueStore {\n /**\n * Associates this instance with a Queue instance, so entries added can be\n * identified by their queue name.\n *\n * @param {Queue} queue\n *\n * @private\n */\n constructor(queue) {\n this._queue = queue;\n this._db = new DBWrapper_mjs.DBWrapper(DB_NAME, 1, {\n onupgradeneeded: evt => evt.target.result.createObjectStore(OBJECT_STORE_NAME, { autoIncrement: true }).createIndex(INDEXED_PROP, INDEXED_PROP, { unique: false })\n });\n }\n\n /**\n * Takes a StorableRequest instance, converts it to an object and adds it\n * as an entry in the object store.\n *\n * @param {StorableRequest} storableRequest\n *\n * @private\n */\n addEntry(storableRequest) {\n var _this = this;\n\n return babelHelpers.asyncToGenerator(function* () {\n yield _this._db.add(OBJECT_STORE_NAME, {\n queueName: _this._queue.name,\n storableRequest: storableRequest.toObject()\n });\n })();\n }\n\n /**\n * Gets the oldest entry in the object store, removes it, and returns the\n * value as a StorableRequest instance. If no entry exists, it returns\n * undefined.\n *\n * @return {StorableRequest|undefined}\n *\n * @private\n */\n getAndRemoveOldestEntry() {\n var _this2 = this;\n\n return babelHelpers.asyncToGenerator(function* () {\n const [entry] = yield _this2._db.getAllMatching(OBJECT_STORE_NAME, {\n index: INDEXED_PROP,\n query: IDBKeyRange.only(_this2._queue.name),\n count: 1,\n includeKeys: true\n });\n\n if (entry) {\n yield _this2._db.delete(OBJECT_STORE_NAME, entry.primaryKey);\n return new StorableRequest(entry.value.storableRequest);\n }\n })();\n }\n }\n\n /*\n Copyright 2017 Google Inc. All Rights Reserved.\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n */\n\n const queueNames = new Set();\n\n /**\n * A class to manage storing failed requests in IndexedDB and retrying them\n * later. All parts of the storing and replaying process are observable via\n * callbacks.\n *\n * @memberof workbox.backgroundSync\n */\n class Queue {\n /**\n * Creates an instance of Queue with the given options\n *\n * @param {string} name The unique name for this queue. This name must be\n * unique as it's used to register sync events and store requests\n * in IndexedDB specific to this instance. An error will be thrown if\n * a duplicate name is detected.\n * @param {Object} [options]\n * @param {Object} [options.callbacks] Callbacks to observe the lifecycle of\n * queued requests. Use these to respond to or modify the requests\n * during the replay process.\n * @param {function(StorableRequest):undefined}\n * [options.callbacks.requestWillEnqueue]\n * Invoked immediately before the request is stored to IndexedDB. Use\n * this callback to modify request data at store time.\n * @param {function(StorableRequest):undefined}\n * [options.callbacks.requestWillReplay]\n * Invoked immediately before the request is re-fetched. Use this\n * callback to modify request data at fetch time.\n * @param {function(Array<StorableRequest>):undefined}\n * [options.callbacks.queueDidReplay]\n * Invoked after all requests in the queue have successfully replayed.\n * @param {number} [options.maxRetentionTime = 7 days] The amount of time (in\n * minutes) a request may be retried. After this amount of time has\n * passed, the request will be deleted from the queue.\n */\n constructor(name, {\n callbacks = {},\n maxRetentionTime = MAX_RETENTION_TIME\n } = {}) {\n // Ensure the store name is not already being used\n if (queueNames.has(name)) {\n throw new WorkboxError_mjs.WorkboxError('duplicate-queue-name', { name });\n } else {\n queueNames.add(name);\n }\n\n this._name = name;\n this._callbacks = callbacks;\n this._maxRetentionTime = maxRetentionTime;\n this._queueStore = new QueueStore(this);\n\n this._addSyncListener();\n }\n\n /**\n * @return {string}\n */\n get name() {\n return this._name;\n }\n\n /**\n * Stores the passed request into IndexedDB. The database used is\n * `workbox-background-sync` and the object store name is the same as\n * the name this instance was created with (to guarantee it's unique).\n *\n * @param {Request} request The request object to store.\n */\n addRequest(request) {\n var _this = this;\n\n return babelHelpers.asyncToGenerator(function* () {\n {\n assert_mjs.assert.isInstance(request, Request, {\n moduleName: 'workbox-background-sync',\n className: 'Queue',\n funcName: 'addRequest',\n paramName: 'request'\n });\n }\n\n const storableRequest = yield StorableRequest.fromRequest(request.clone());\n yield _this._runCallback('requestWillEnqueue', storableRequest);\n yield _this._queueStore.addEntry(storableRequest);\n yield _this._registerSync();\n {\n logger_mjs.logger.log(`Request for '${getFriendlyURL_mjs.getFriendlyURL(storableRequest.url)}' has been\n added to background sync queue '${_this._name}'.`);\n }\n })();\n }\n\n /**\n * Retrieves all stored requests in IndexedDB and retries them. If the\n * queue contained requests that were successfully replayed, the\n * `queueDidReplay` callback is invoked (which implies the queue is\n * now empty). If any of the requests fail, a new sync registration is\n * created to retry again later.\n */\n replayRequests() {\n var _this2 = this;\n\n return babelHelpers.asyncToGenerator(function* () {\n const now = Date.now();\n const replayedRequests = [];\n const failedRequests = [];\n\n let storableRequest;\n while (storableRequest = yield _this2._queueStore.getAndRemoveOldestEntry()) {\n // Make a copy so the unmodified request can be stored\n // in the event of a replay failure.\n const storableRequestClone = storableRequest.clone();\n\n // Ignore requests older than maxRetentionTime.\n const maxRetentionTimeInMs = _this2._maxRetentionTime * 60 * 1000;\n if (now - storableRequest.timestamp > maxRetentionTimeInMs) {\n continue;\n }\n\n yield _this2._runCallback('requestWillReplay', storableRequest);\n\n const replay = { request: storableRequest.toRequest() };\n\n try {\n // Clone the request before fetching so callbacks get an unused one.\n replay.response = yield fetch(replay.request.clone());\n {\n logger_mjs.logger.log(`Request for '${getFriendlyURL_mjs.getFriendlyURL(storableRequest.url)}'\n has been replayed`);\n }\n } catch (err) {\n {\n logger_mjs.logger.log(`Request for '${getFriendlyURL_mjs.getFriendlyURL(storableRequest.url)}'\n failed to replay`);\n }\n replay.error = err;\n failedRequests.push(storableRequestClone);\n }\n\n replayedRequests.push(replay);\n }\n\n yield _this2._runCallback('queueDidReplay', replayedRequests);\n\n // If any requests failed, put the failed requests back in the queue\n // and rethrow the failed requests count.\n if (failedRequests.length) {\n yield Promise.all(failedRequests.map(function (storableRequest) {\n return _this2._queueStore.addEntry(storableRequest);\n }));\n\n throw new WorkboxError_mjs.WorkboxError('queue-replay-failed', { name: _this2._name, count: failedRequests.length });\n }\n })();\n }\n\n /**\n * Runs the passed callback if it exists.\n *\n * @private\n * @param {string} name The name of the callback on this._callbacks.\n * @param {...*} args The arguments to invoke the callback with.\n */\n _runCallback(name, ...args) {\n var _this3 = this;\n\n return babelHelpers.asyncToGenerator(function* () {\n if (typeof _this3._callbacks[name] === 'function') {\n yield _this3._callbacks[name].apply(null, args);\n }\n })();\n }\n\n /**\n * In sync-supporting browsers, this adds a listener for the sync event.\n * In non-sync-supporting browsers, this will retry the queue on service\n * worker startup.\n *\n * @private\n */\n _addSyncListener() {\n if ('sync' in registration) {\n self.addEventListener('sync', event => {\n if (event.tag === `${TAG_PREFIX}:${this._name}`) {\n {\n logger_mjs.logger.log(`Background sync for tag '${event.tag}'\n has been received, starting replay now`);\n }\n event.waitUntil(this.replayRequests());\n }\n });\n } else {\n {\n logger_mjs.logger.log(`Background sync replaying without background sync event`);\n }\n // If the browser doesn't support background sync, retry\n // every time the service worker starts up as a fallback.\n this.replayRequests();\n }\n }\n\n /**\n * Registers a sync event with a tag unique to this instance.\n *\n * @private\n */\n _registerSync() {\n var _this4 = this;\n\n return babelHelpers.asyncToGenerator(function* () {\n if ('sync' in registration) {\n try {\n yield registration.sync.register(`${TAG_PREFIX}:${_this4._name}`);\n } catch (err) {\n // This means the registration failed for some reason, possibly due to\n // the user disabling it.\n {\n logger_mjs.logger.warn(`Unable to register sync event for '${_this4._name}'.`, err);\n }\n }\n }\n })();\n }\n\n /**\n * Returns the set of queue names. This is primarily used to reset the list\n * of queue names in tests.\n *\n * @return {Set}\n *\n * @private\n */\n static get _queueNames() {\n return queueNames;\n }\n }\n\n /*\n Copyright 2017 Google Inc. All Rights Reserved.\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n */\n\n /**\n * A class implementing the `fetchDidFail` lifecycle callback. This makes it\n * easier to add failed requests to a background sync Queue.\n *\n * @memberof workbox.backgroundSync\n */\n class Plugin {\n /**\n * @param {...*} queueArgs Args to forward to the composed Queue instance.\n * See the [Queue]{@link workbox.backgroundSync.Queue} documentation for\n * parameter details.\n */\n constructor(...queueArgs) {\n this._queue = new Queue(...queueArgs);\n this.fetchDidFail = this.fetchDidFail.bind(this);\n }\n\n /**\n * @param {Object} options\n * @param {Request} options.request\n * @private\n */\n fetchDidFail({ request }) {\n var _this = this;\n\n return babelHelpers.asyncToGenerator(function* () {\n yield _this._queue.addRequest(request);\n })();\n }\n }\n\n /*\n Copyright 2017 Google Inc. All Rights Reserved.\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n */\n\n var publicAPI = /*#__PURE__*/Object.freeze({\n Queue: Queue,\n Plugin: Plugin\n });\n\n /*\n Copyright 2017 Google Inc. All Rights Reserved.\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n */\n\n return publicAPI;\n\n}(workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private));\n"],"file":"workbox-background-sync.dev.js"}
|
@@ -0,0 +1,3 @@
|
|
1
|
+
this.workbox=this.workbox||{},this.workbox.backgroundSync=function(e,t){"use strict";try{self.workbox.v["workbox:background-sync:3.3.1"]=1}catch(e){}const r=["method","referrer","referrerPolicy","mode","credentials","cache","redirect","integrity","keepalive"];class s{static fromRequest(e){return babelHelpers.asyncToGenerator(function*(){const t={headers:{}};"GET"!==e.method&&(t.body=yield e.clone().blob());for(const[r,s]of e.headers.entries())t.headers[r]=s;for(const s of r)void 0!==e[s]&&(t[s]=e[s]);return new s({url:e.url,requestInit:t})})()}constructor({url:e,requestInit:t,timestamp:r=Date.now()}){this.url=e,this.requestInit=t,this.e=r}get timestamp(){return this.e}toObject(){return{url:this.url,timestamp:this.timestamp,requestInit:this.requestInit}}toRequest(){return new Request(this.url,this.requestInit)}clone(){const e=Object.assign({},this.requestInit);return e.headers=Object.assign({},this.requestInit.headers),this.requestInit.body&&(e.body=this.requestInit.body.slice()),new s({url:this.url,timestamp:this.timestamp,requestInit:e})}}const i="workbox-background-sync",n="requests",u="queueName",c="workbox-background-sync",o=10080;class l{constructor(t){this.t=t,this.r=new e.DBWrapper(i,1,{onupgradeneeded:e=>e.target.result.createObjectStore(n,{autoIncrement:!0}).createIndex(u,u,{unique:!1})})}addEntry(e){var t=this;return babelHelpers.asyncToGenerator(function*(){yield t.r.add(n,{queueName:t.t.name,storableRequest:e.toObject()})})()}getAndRemoveOldestEntry(){var e=this;return babelHelpers.asyncToGenerator(function*(){const[t]=yield e.r.getAllMatching(n,{index:u,query:IDBKeyRange.only(e.t.name),count:1,includeKeys:!0});if(t)return yield e.r.delete(n,t.primaryKey),new s(t.value.storableRequest)})()}}const a=new Set;class h{constructor(e,{callbacks:r={},maxRetentionTime:s=o}={}){if(a.has(e))throw new t.WorkboxError("duplicate-queue-name",{name:e});a.add(e),this.s=e,this.i=r,this.n=s,this.u=new l(this),this.c()}get name(){return this.s}addRequest(e){var t=this;return babelHelpers.asyncToGenerator(function*(){const r=yield s.fromRequest(e.clone());yield t.o("requestWillEnqueue",r),yield t.u.addEntry(r),yield t.l()})()}replayRequests(){var e=this;return babelHelpers.asyncToGenerator(function*(){const r=Date.now(),s=[],i=[];let n;for(;n=yield e.u.getAndRemoveOldestEntry();){const t=n.clone(),u=60*e.n*1e3;if(r-n.timestamp>u)continue;yield e.o("requestWillReplay",n);const c={request:n.toRequest()};try{c.response=yield fetch(c.request.clone())}catch(e){c.error=e,i.push(t)}s.push(c)}if(yield e.o("queueDidReplay",s),i.length)throw yield Promise.all(i.map(function(t){return e.u.addEntry(t)})),new t.WorkboxError("queue-replay-failed",{name:e.s,count:i.length})})()}o(e,...t){var r=this;return babelHelpers.asyncToGenerator(function*(){"function"==typeof r.i[e]&&(yield r.i[e].apply(null,t))})()}c(){"sync"in registration?self.addEventListener("sync",e=>{e.tag===`${c}:${this.s}`&&e.waitUntil(this.replayRequests())}):this.replayRequests()}l(){var e=this;return babelHelpers.asyncToGenerator(function*(){if("sync"in registration)try{yield registration.sync.register(`${c}:${e.s}`)}catch(e){}})()}static get a(){return a}}return Object.freeze({Queue:h,Plugin:class{constructor(...e){this.t=new h(...e),this.fetchDidFail=this.fetchDidFail.bind(this)}fetchDidFail({request:e}){var t=this;return babelHelpers.asyncToGenerator(function*(){yield t.t.addRequest(e)})()}}})}(workbox.core._private,workbox.core._private);
|
2
|
+
|
3
|
+
//# sourceMappingURL=workbox-background-sync.prod.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":[],"mappings":"","sources":["packages/workbox-background-sync/browser.mjs"],"sourcesContent":["this.workbox=this.workbox||{},this.workbox.backgroundSync=function(e,t){\"use strict\";try{self.workbox.v[\"workbox:background-sync:3.3.1\"]=1}catch(e){}const r=[\"method\",\"referrer\",\"referrerPolicy\",\"mode\",\"credentials\",\"cache\",\"redirect\",\"integrity\",\"keepalive\"];class s{static fromRequest(e){return babelHelpers.asyncToGenerator(function*(){const t={headers:{}};\"GET\"!==e.method&&(t.body=yield e.clone().blob());for(const[r,s]of e.headers.entries())t.headers[r]=s;for(const s of r)void 0!==e[s]&&(t[s]=e[s]);return new s({url:e.url,requestInit:t})})()}constructor({url:e,requestInit:t,timestamp:r=Date.now()}){this.url=e,this.requestInit=t,this.e=r}get timestamp(){return this.e}toObject(){return{url:this.url,timestamp:this.timestamp,requestInit:this.requestInit}}toRequest(){return new Request(this.url,this.requestInit)}clone(){const e=Object.assign({},this.requestInit);return e.headers=Object.assign({},this.requestInit.headers),this.requestInit.body&&(e.body=this.requestInit.body.slice()),new s({url:this.url,timestamp:this.timestamp,requestInit:e})}}const i=\"workbox-background-sync\",n=\"requests\",u=\"queueName\",c=\"workbox-background-sync\",o=10080;class l{constructor(t){this.t=t,this.r=new e.DBWrapper(i,1,{onupgradeneeded:e=>e.target.result.createObjectStore(n,{autoIncrement:!0}).createIndex(u,u,{unique:!1})})}addEntry(e){var t=this;return babelHelpers.asyncToGenerator(function*(){yield t.r.add(n,{queueName:t.t.name,storableRequest:e.toObject()})})()}getAndRemoveOldestEntry(){var e=this;return babelHelpers.asyncToGenerator(function*(){const[t]=yield e.r.getAllMatching(n,{index:u,query:IDBKeyRange.only(e.t.name),count:1,includeKeys:!0});if(t)return yield e.r.delete(n,t.primaryKey),new s(t.value.storableRequest)})()}}const a=new Set;class h{constructor(e,{callbacks:r={},maxRetentionTime:s=o}={}){if(a.has(e))throw new t.WorkboxError(\"duplicate-queue-name\",{name:e});a.add(e),this.s=e,this.i=r,this.n=s,this.u=new l(this),this.c()}get name(){return this.s}addRequest(e){var t=this;return babelHelpers.asyncToGenerator(function*(){const r=yield s.fromRequest(e.clone());yield t.o(\"requestWillEnqueue\",r),yield t.u.addEntry(r),yield t.l()})()}replayRequests(){var e=this;return babelHelpers.asyncToGenerator(function*(){const r=Date.now(),s=[],i=[];let n;for(;n=yield e.u.getAndRemoveOldestEntry();){const t=n.clone(),u=60*e.n*1e3;if(r-n.timestamp>u)continue;yield e.o(\"requestWillReplay\",n);const c={request:n.toRequest()};try{c.response=yield fetch(c.request.clone())}catch(e){c.error=e,i.push(t)}s.push(c)}if(yield e.o(\"queueDidReplay\",s),i.length)throw yield Promise.all(i.map(function(t){return e.u.addEntry(t)})),new t.WorkboxError(\"queue-replay-failed\",{name:e.s,count:i.length})})()}o(e,...t){var r=this;return babelHelpers.asyncToGenerator(function*(){\"function\"==typeof r.i[e]&&(yield r.i[e].apply(null,t))})()}c(){\"sync\"in registration?self.addEventListener(\"sync\",e=>{e.tag===`${c}:${this.s}`&&e.waitUntil(this.replayRequests())}):this.replayRequests()}l(){var e=this;return babelHelpers.asyncToGenerator(function*(){if(\"sync\"in registration)try{yield registration.sync.register(`${c}:${e.s}`)}catch(e){}})()}static get a(){return a}}return Object.freeze({Queue:h,Plugin:class{constructor(...e){this.t=new h(...e),this.fetchDidFail=this.fetchDidFail.bind(this)}fetchDidFail({request:e}){var t=this;return babelHelpers.asyncToGenerator(function*(){yield t.t.addRequest(e)})()}}})}(workbox.core._private,workbox.core._private);\n"],"file":"workbox-background-sync.prod.js"}
|
@@ -0,0 +1,395 @@
|
|
1
|
+
this.workbox = this.workbox || {};
|
2
|
+
this.workbox.broadcastUpdate = (function (exports,WorkboxError_mjs,logger_mjs,assert_mjs) {
|
3
|
+
'use strict';
|
4
|
+
|
5
|
+
try {
|
6
|
+
self.workbox.v['workbox:broadcast-cache-update:3.3.1'] = 1;
|
7
|
+
} catch (e) {} // eslint-disable-line
|
8
|
+
|
9
|
+
/*
|
10
|
+
Copyright 2016 Google Inc. All Rights Reserved.
|
11
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
12
|
+
you may not use this file except in compliance with the License.
|
13
|
+
You may obtain a copy of the License at
|
14
|
+
|
15
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
16
|
+
|
17
|
+
Unless required by applicable law or agreed to in writing, software
|
18
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
19
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
20
|
+
See the License for the specific language governing permissions and
|
21
|
+
limitations under the License.
|
22
|
+
*/
|
23
|
+
|
24
|
+
/**
|
25
|
+
* Given two `Response's`, compares several header values to see if they are
|
26
|
+
* the same or not.
|
27
|
+
*
|
28
|
+
* @param {Response} firstResponse
|
29
|
+
* @param {Response} secondResponse
|
30
|
+
* @param {Array<string>} headersToCheck
|
31
|
+
* @return {boolean}
|
32
|
+
*
|
33
|
+
* @memberof workbox.broadcastUpdate
|
34
|
+
* @private
|
35
|
+
*/
|
36
|
+
const responsesAreSame = (firstResponse, secondResponse, headersToCheck) => {
|
37
|
+
{
|
38
|
+
if (!(firstResponse instanceof Response && secondResponse instanceof Response)) {
|
39
|
+
throw new WorkboxError_mjs.WorkboxError('invalid-responses-are-same-args');
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
const atLeastOneHeaderAvailable = headersToCheck.some(header => {
|
44
|
+
return firstResponse.headers.has(header) && secondResponse.headers.has(header);
|
45
|
+
});
|
46
|
+
|
47
|
+
if (!atLeastOneHeaderAvailable) {
|
48
|
+
{
|
49
|
+
logger_mjs.logger.warn(`Unable to determine where the response has been updated ` + `because none of the headers that would be checked are present.`);
|
50
|
+
logger_mjs.logger.debug(`Attempting to compare the following: `, firstResponse, secondResponse, headersToCheck);
|
51
|
+
}
|
52
|
+
|
53
|
+
// Just return true, indicating the that responses are the same, since we
|
54
|
+
// can't determine otherwise.
|
55
|
+
return true;
|
56
|
+
}
|
57
|
+
|
58
|
+
return headersToCheck.every(header => {
|
59
|
+
const headerStateComparison = firstResponse.headers.has(header) === secondResponse.headers.has(header);
|
60
|
+
const headerValueComparison = firstResponse.headers.get(header) === secondResponse.headers.get(header);
|
61
|
+
|
62
|
+
return headerStateComparison && headerValueComparison;
|
63
|
+
});
|
64
|
+
};
|
65
|
+
|
66
|
+
/*
|
67
|
+
Copyright 2016 Google Inc. All Rights Reserved.
|
68
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
69
|
+
you may not use this file except in compliance with the License.
|
70
|
+
You may obtain a copy of the License at
|
71
|
+
|
72
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
73
|
+
|
74
|
+
Unless required by applicable law or agreed to in writing, software
|
75
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
76
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
77
|
+
See the License for the specific language governing permissions and
|
78
|
+
limitations under the License.
|
79
|
+
*/
|
80
|
+
|
81
|
+
var messageTypes = {
|
82
|
+
CACHE_UPDATED: 'CACHE_UPDATED'
|
83
|
+
};
|
84
|
+
|
85
|
+
/*
|
86
|
+
Copyright 2016 Google Inc. All Rights Reserved.
|
87
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
88
|
+
you may not use this file except in compliance with the License.
|
89
|
+
You may obtain a copy of the License at
|
90
|
+
|
91
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
92
|
+
|
93
|
+
Unless required by applicable law or agreed to in writing, software
|
94
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
95
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
96
|
+
See the License for the specific language governing permissions and
|
97
|
+
limitations under the License.
|
98
|
+
*/
|
99
|
+
|
100
|
+
/**
|
101
|
+
* You would not normally call this method directly; it's called automatically
|
102
|
+
* by an instance of the {@link BroadcastCacheUpdate} class. It's exposed here
|
103
|
+
* for the benefit of developers who would rather not use the full
|
104
|
+
* `BroadcastCacheUpdate` implementation.
|
105
|
+
*
|
106
|
+
* Calling this will dispatch a message on the provided
|
107
|
+
* {@link https://developers.google.com/web/updates/2016/09/broadcastchannel|Broadcast Channel}
|
108
|
+
* to notify interested subscribers about a change to a cached resource.
|
109
|
+
*
|
110
|
+
* The message that's posted has a formation inspired by the
|
111
|
+
* [Flux standard action](https://github.com/acdlite/flux-standard-action#introduction)
|
112
|
+
* format like so:
|
113
|
+
*
|
114
|
+
* ```
|
115
|
+
* {
|
116
|
+
* type: 'CACHE_UPDATED',
|
117
|
+
* meta: 'workbox-broadcast-cache-update',
|
118
|
+
* payload: {
|
119
|
+
* cacheName: 'the-cache-name',
|
120
|
+
* updatedUrl: 'https://example.com/'
|
121
|
+
* }
|
122
|
+
* }
|
123
|
+
* ```
|
124
|
+
*
|
125
|
+
* (Usage of [Flux](https://facebook.github.io/flux/) itself is not at
|
126
|
+
* all required.)
|
127
|
+
*
|
128
|
+
* @param {BroadcastChannel} channel The `BroadcastChannel` to use.
|
129
|
+
* @param {string} cacheName The name of the cache in which the updated
|
130
|
+
* `Response` was stored.
|
131
|
+
* @param {string} url The URL associated with the updated `Response`.
|
132
|
+
* @param {string} source A string identifying this library as the source
|
133
|
+
* of the update message.
|
134
|
+
*
|
135
|
+
* @memberof workbox.broadcastUpdate
|
136
|
+
*/
|
137
|
+
const broadcastUpdate = (channel, cacheName, url, source) => {
|
138
|
+
// There are browsers which support service workers but don't support the
|
139
|
+
// Broadcast Channel API.
|
140
|
+
// See https://github.com/GoogleChrome/workbox/issues/1304
|
141
|
+
if (!('BroadcastChannel' in self && channel)) {
|
142
|
+
{
|
143
|
+
logger_mjs.logger.debug(`${url} was updated, but the Broadcast Channel API is not ` + `available in the current browser.`);
|
144
|
+
}
|
145
|
+
return;
|
146
|
+
}
|
147
|
+
|
148
|
+
{
|
149
|
+
assert_mjs.assert.isInstance(channel, BroadcastChannel, {
|
150
|
+
moduleName: 'workbox-broadcast-cache-update',
|
151
|
+
className: '~',
|
152
|
+
funcName: 'broadcastUpdate',
|
153
|
+
paramName: 'channel'
|
154
|
+
});
|
155
|
+
assert_mjs.assert.isType(cacheName, 'string', {
|
156
|
+
moduleName: 'workbox-broadcast-cache-update',
|
157
|
+
className: '~',
|
158
|
+
funcName: 'broadcastUpdate',
|
159
|
+
paramName: 'cacheName'
|
160
|
+
});
|
161
|
+
assert_mjs.assert.isType(url, 'string', {
|
162
|
+
moduleName: 'workbox-broadcast-cache-update',
|
163
|
+
className: '~',
|
164
|
+
funcName: 'broadcastUpdate',
|
165
|
+
paramName: 'url'
|
166
|
+
});
|
167
|
+
assert_mjs.assert.isType(source, 'string', {
|
168
|
+
moduleName: 'workbox-broadcast-cache-update',
|
169
|
+
className: '~',
|
170
|
+
funcName: 'broadcastUpdate',
|
171
|
+
paramName: 'source'
|
172
|
+
});
|
173
|
+
}
|
174
|
+
|
175
|
+
channel.postMessage({
|
176
|
+
type: messageTypes.CACHE_UPDATED,
|
177
|
+
meta: source,
|
178
|
+
payload: {
|
179
|
+
cacheName: cacheName,
|
180
|
+
updatedUrl: url
|
181
|
+
}
|
182
|
+
});
|
183
|
+
};
|
184
|
+
|
185
|
+
/*
|
186
|
+
Copyright 2016 Google Inc. All Rights Reserved.
|
187
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
188
|
+
you may not use this file except in compliance with the License.
|
189
|
+
You may obtain a copy of the License at
|
190
|
+
|
191
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
192
|
+
|
193
|
+
Unless required by applicable law or agreed to in writing, software
|
194
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
195
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
196
|
+
See the License for the specific language governing permissions and
|
197
|
+
limitations under the License.
|
198
|
+
*/
|
199
|
+
|
200
|
+
/**
|
201
|
+
* Uses the [Broadcast Channel API]{@link https://developers.google.com/web/updates/2016/09/broadcastchannel}
|
202
|
+
* to notify interested parties when a cached response has been updated.
|
203
|
+
*
|
204
|
+
* For efficiency's sake, the underlying response bodies are not compared;
|
205
|
+
* only specific response headers are checked.
|
206
|
+
*
|
207
|
+
* @memberof workbox.broadcastUpdate
|
208
|
+
*/
|
209
|
+
class BroadcastCacheUpdate {
|
210
|
+
/**
|
211
|
+
* Construct a BroadcastCacheUpdate instance with a specific `channelName` to
|
212
|
+
* broadcast messages on
|
213
|
+
*
|
214
|
+
* @param {string} channelName The name that will be used when creating
|
215
|
+
* the `BroadcastChannel`.
|
216
|
+
* @param {Object} options
|
217
|
+
* @param {Array<string>}
|
218
|
+
* [options.headersToCheck=['content-length', 'etag', 'last-modified']] A
|
219
|
+
* list of headers that will be used to determine whether the responses
|
220
|
+
* differ.
|
221
|
+
* @param {string} [options.source='workbox-broadcast-cache-update'] An
|
222
|
+
* attribution value that indicates where the update originated.
|
223
|
+
*/
|
224
|
+
constructor(channelName, { headersToCheck, source } = {}) {
|
225
|
+
{
|
226
|
+
if (typeof channelName !== 'string' || channelName.length === 0) {
|
227
|
+
throw new WorkboxError_mjs.WorkboxError('channel-name-required');
|
228
|
+
}
|
229
|
+
}
|
230
|
+
|
231
|
+
this._channelName = channelName;
|
232
|
+
this._headersToCheck = headersToCheck || ['content-length', 'etag', 'last-modified'];
|
233
|
+
this._source = source || 'workbox-broadcast-cache-update';
|
234
|
+
|
235
|
+
// TODO assert typeof headersToCheck instanceof Array
|
236
|
+
}
|
237
|
+
|
238
|
+
/**
|
239
|
+
* @return {BroadcastChannel|undefined} The BroadcastChannel instance used for
|
240
|
+
* broadcasting updates, or undefined if the browser doesn't support the
|
241
|
+
* Broadcast Channel API.
|
242
|
+
*
|
243
|
+
* @private
|
244
|
+
*/
|
245
|
+
_getChannel() {
|
246
|
+
if ('BroadcastChannel' in self && !this._channel) {
|
247
|
+
this._channel = new BroadcastChannel(this._channelName);
|
248
|
+
}
|
249
|
+
return this._channel;
|
250
|
+
}
|
251
|
+
|
252
|
+
/**
|
253
|
+
* Compare two [Responses](https://developer.mozilla.org/en-US/docs/Web/API/Response)
|
254
|
+
* and send a message via the
|
255
|
+
* {@link https://developers.google.com/web/updates/2016/09/broadcastchannel|Broadcast Channel API}
|
256
|
+
* if they differ.
|
257
|
+
*
|
258
|
+
* Neither of the Responses can be {@link http://stackoverflow.com/questions/39109789|opaque}.
|
259
|
+
*
|
260
|
+
* @param {Response} firstResponse First responses to compare.
|
261
|
+
* @param {Response} secondResponse Second responses to compare.
|
262
|
+
* @param {string} url The URL of the updated request.
|
263
|
+
* @param {string} cacheName Name of the cache the responses belong to.
|
264
|
+
* This is included in the message posted on the broadcast channel.
|
265
|
+
*/
|
266
|
+
notifyIfUpdated(firstResponse, secondResponse, url, cacheName) {
|
267
|
+
if (!responsesAreSame(firstResponse, secondResponse, this._headersToCheck)) {
|
268
|
+
broadcastUpdate(this._getChannel(), cacheName, url, this._source);
|
269
|
+
}
|
270
|
+
}
|
271
|
+
}
|
272
|
+
|
273
|
+
/*
|
274
|
+
Copyright 2016 Google Inc. All Rights Reserved.
|
275
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
276
|
+
you may not use this file except in compliance with the License.
|
277
|
+
You may obtain a copy of the License at
|
278
|
+
|
279
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
280
|
+
|
281
|
+
Unless required by applicable law or agreed to in writing, software
|
282
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
283
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
284
|
+
See the License for the specific language governing permissions and
|
285
|
+
limitations under the License.
|
286
|
+
*/
|
287
|
+
|
288
|
+
/**
|
289
|
+
* This plugin will automatically broadcast a message whenever a cached response
|
290
|
+
* is updated.
|
291
|
+
*
|
292
|
+
* @memberof workbox.broadcastUpdate
|
293
|
+
*/
|
294
|
+
class Plugin {
|
295
|
+
/**
|
296
|
+
* Construct a new instance with a specific `channelName` to
|
297
|
+
* broadcast messages on
|
298
|
+
*
|
299
|
+
* @param {string} channelName The name that will be used when creating
|
300
|
+
* the `BroadcastChannel`.
|
301
|
+
* @param {Object} options
|
302
|
+
* @param {Array<string>}
|
303
|
+
* [options.headersToCheck=['content-length', 'etag', 'last-modified']] A
|
304
|
+
* list of headers that will be used to determine whether the responses
|
305
|
+
* differ.
|
306
|
+
* @param {string} [options.source='workbox-broadcast-cache-update'] An
|
307
|
+
* attribution value that indicates where the update originated.
|
308
|
+
*/
|
309
|
+
constructor(channelName, options) {
|
310
|
+
this._broadcastUpdate = new BroadcastCacheUpdate(channelName, options);
|
311
|
+
}
|
312
|
+
/**
|
313
|
+
* A "lifecycle" callback that will be triggered automatically by the
|
314
|
+
* `workbox-sw` and `workbox-runtime-caching` handlers when an entry is
|
315
|
+
* added to a cache.
|
316
|
+
*
|
317
|
+
* @private
|
318
|
+
* @param {Object} input The input object to this function.
|
319
|
+
* @param {string} input.cacheName Name of the cache the responses belong to.
|
320
|
+
* @param {Response} [input.oldResponse] The previous cached value, if any.
|
321
|
+
* @param {Response} input.newResponse The new value in the cache.
|
322
|
+
*/
|
323
|
+
cacheDidUpdate({ cacheName, oldResponse, newResponse, request }) {
|
324
|
+
{
|
325
|
+
assert_mjs.assert.isType(cacheName, 'string', {
|
326
|
+
moduleName: 'workbox-broadcast-cache-update',
|
327
|
+
className: 'Plugin',
|
328
|
+
funcName: 'cacheDidUpdate',
|
329
|
+
paramName: 'cacheName'
|
330
|
+
});
|
331
|
+
assert_mjs.assert.isInstance(newResponse, Response, {
|
332
|
+
moduleName: 'workbox-broadcast-cache-update',
|
333
|
+
className: 'Plugin',
|
334
|
+
funcName: 'cacheDidUpdate',
|
335
|
+
paramName: 'newResponse'
|
336
|
+
});
|
337
|
+
assert_mjs.assert.isInstance(request, Request, {
|
338
|
+
moduleName: 'workbox-broadcast-cache-update',
|
339
|
+
className: 'Plugin',
|
340
|
+
funcName: 'cacheDidUpdate',
|
341
|
+
paramName: 'request'
|
342
|
+
});
|
343
|
+
}
|
344
|
+
|
345
|
+
if (!oldResponse) {
|
346
|
+
// Without a two responses there is nothing to compare.
|
347
|
+
return;
|
348
|
+
}
|
349
|
+
|
350
|
+
this._broadcastUpdate.notifyIfUpdated(oldResponse, newResponse, request.url, cacheName);
|
351
|
+
}
|
352
|
+
}
|
353
|
+
|
354
|
+
/*
|
355
|
+
Copyright 2017 Google Inc.
|
356
|
+
|
357
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
358
|
+
you may not use this file except in compliance with the License.
|
359
|
+
You may obtain a copy of the License at
|
360
|
+
|
361
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
362
|
+
|
363
|
+
Unless required by applicable law or agreed to in writing, software
|
364
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
365
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
366
|
+
See the License for the specific language governing permissions and
|
367
|
+
limitations under the License.
|
368
|
+
*/
|
369
|
+
|
370
|
+
/*
|
371
|
+
Copyright 2017 Google Inc.
|
372
|
+
|
373
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
374
|
+
you may not use this file except in compliance with the License.
|
375
|
+
You may obtain a copy of the License at
|
376
|
+
|
377
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
378
|
+
|
379
|
+
Unless required by applicable law or agreed to in writing, software
|
380
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
381
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
382
|
+
See the License for the specific language governing permissions and
|
383
|
+
limitations under the License.
|
384
|
+
*/
|
385
|
+
|
386
|
+
exports.BroadcastCacheUpdate = BroadcastCacheUpdate;
|
387
|
+
exports.Plugin = Plugin;
|
388
|
+
exports.broadcastUpdate = broadcastUpdate;
|
389
|
+
exports.messageTypes = messageTypes;
|
390
|
+
|
391
|
+
return exports;
|
392
|
+
|
393
|
+
}({},workbox.core._private,workbox.core._private,workbox.core._private));
|
394
|
+
|
395
|
+
//# sourceMappingURL=workbox-broadcast-cache-update.dev.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":[],"mappings":"","sources":["packages/workbox-broadcast-cache-update/browser.mjs"],"sourcesContent":["this.workbox = this.workbox || {};\nthis.workbox.broadcastUpdate = (function (exports,WorkboxError_mjs,logger_mjs,assert_mjs) {\n 'use strict';\n\n try {\n self.workbox.v['workbox:broadcast-cache-update:3.3.1'] = 1;\n } catch (e) {} // eslint-disable-line\n\n /*\n Copyright 2016 Google Inc. All Rights Reserved.\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n */\n\n /**\n * Given two `Response's`, compares several header values to see if they are\n * the same or not.\n *\n * @param {Response} firstResponse\n * @param {Response} secondResponse\n * @param {Array<string>} headersToCheck\n * @return {boolean}\n *\n * @memberof workbox.broadcastUpdate\n * @private\n */\n const responsesAreSame = (firstResponse, secondResponse, headersToCheck) => {\n {\n if (!(firstResponse instanceof Response && secondResponse instanceof Response)) {\n throw new WorkboxError_mjs.WorkboxError('invalid-responses-are-same-args');\n }\n }\n\n const atLeastOneHeaderAvailable = headersToCheck.some(header => {\n return firstResponse.headers.has(header) && secondResponse.headers.has(header);\n });\n\n if (!atLeastOneHeaderAvailable) {\n {\n logger_mjs.logger.warn(`Unable to determine where the response has been updated ` + `because none of the headers that would be checked are present.`);\n logger_mjs.logger.debug(`Attempting to compare the following: `, firstResponse, secondResponse, headersToCheck);\n }\n\n // Just return true, indicating the that responses are the same, since we\n // can't determine otherwise.\n return true;\n }\n\n return headersToCheck.every(header => {\n const headerStateComparison = firstResponse.headers.has(header) === secondResponse.headers.has(header);\n const headerValueComparison = firstResponse.headers.get(header) === secondResponse.headers.get(header);\n\n return headerStateComparison && headerValueComparison;\n });\n };\n\n /*\n Copyright 2016 Google Inc. All Rights Reserved.\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n */\n\n var messageTypes = {\n CACHE_UPDATED: 'CACHE_UPDATED'\n };\n\n /*\n Copyright 2016 Google Inc. All Rights Reserved.\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n */\n\n /**\n * You would not normally call this method directly; it's called automatically\n * by an instance of the {@link BroadcastCacheUpdate} class. It's exposed here\n * for the benefit of developers who would rather not use the full\n * `BroadcastCacheUpdate` implementation.\n *\n * Calling this will dispatch a message on the provided\n * {@link https://developers.google.com/web/updates/2016/09/broadcastchannel|Broadcast Channel}\n * to notify interested subscribers about a change to a cached resource.\n *\n * The message that's posted has a formation inspired by the\n * [Flux standard action](https://github.com/acdlite/flux-standard-action#introduction)\n * format like so:\n *\n * ```\n * {\n * type: 'CACHE_UPDATED',\n * meta: 'workbox-broadcast-cache-update',\n * payload: {\n * cacheName: 'the-cache-name',\n * updatedUrl: 'https://example.com/'\n * }\n * }\n * ```\n *\n * (Usage of [Flux](https://facebook.github.io/flux/) itself is not at\n * all required.)\n *\n * @param {BroadcastChannel} channel The `BroadcastChannel` to use.\n * @param {string} cacheName The name of the cache in which the updated\n * `Response` was stored.\n * @param {string} url The URL associated with the updated `Response`.\n * @param {string} source A string identifying this library as the source\n * of the update message.\n *\n * @memberof workbox.broadcastUpdate\n */\n const broadcastUpdate = (channel, cacheName, url, source) => {\n // There are browsers which support service workers but don't support the\n // Broadcast Channel API.\n // See https://github.com/GoogleChrome/workbox/issues/1304\n if (!('BroadcastChannel' in self && channel)) {\n {\n logger_mjs.logger.debug(`${url} was updated, but the Broadcast Channel API is not ` + `available in the current browser.`);\n }\n return;\n }\n\n {\n assert_mjs.assert.isInstance(channel, BroadcastChannel, {\n moduleName: 'workbox-broadcast-cache-update',\n className: '~',\n funcName: 'broadcastUpdate',\n paramName: 'channel'\n });\n assert_mjs.assert.isType(cacheName, 'string', {\n moduleName: 'workbox-broadcast-cache-update',\n className: '~',\n funcName: 'broadcastUpdate',\n paramName: 'cacheName'\n });\n assert_mjs.assert.isType(url, 'string', {\n moduleName: 'workbox-broadcast-cache-update',\n className: '~',\n funcName: 'broadcastUpdate',\n paramName: 'url'\n });\n assert_mjs.assert.isType(source, 'string', {\n moduleName: 'workbox-broadcast-cache-update',\n className: '~',\n funcName: 'broadcastUpdate',\n paramName: 'source'\n });\n }\n\n channel.postMessage({\n type: messageTypes.CACHE_UPDATED,\n meta: source,\n payload: {\n cacheName: cacheName,\n updatedUrl: url\n }\n });\n };\n\n /*\n Copyright 2016 Google Inc. All Rights Reserved.\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n */\n\n /**\n * Uses the [Broadcast Channel API]{@link https://developers.google.com/web/updates/2016/09/broadcastchannel}\n * to notify interested parties when a cached response has been updated.\n *\n * For efficiency's sake, the underlying response bodies are not compared;\n * only specific response headers are checked.\n *\n * @memberof workbox.broadcastUpdate\n */\n class BroadcastCacheUpdate {\n /**\n * Construct a BroadcastCacheUpdate instance with a specific `channelName` to\n * broadcast messages on\n *\n * @param {string} channelName The name that will be used when creating\n * the `BroadcastChannel`.\n * @param {Object} options\n * @param {Array<string>}\n * [options.headersToCheck=['content-length', 'etag', 'last-modified']] A\n * list of headers that will be used to determine whether the responses\n * differ.\n * @param {string} [options.source='workbox-broadcast-cache-update'] An\n * attribution value that indicates where the update originated.\n */\n constructor(channelName, { headersToCheck, source } = {}) {\n {\n if (typeof channelName !== 'string' || channelName.length === 0) {\n throw new WorkboxError_mjs.WorkboxError('channel-name-required');\n }\n }\n\n this._channelName = channelName;\n this._headersToCheck = headersToCheck || ['content-length', 'etag', 'last-modified'];\n this._source = source || 'workbox-broadcast-cache-update';\n\n // TODO assert typeof headersToCheck instanceof Array\n }\n\n /**\n * @return {BroadcastChannel|undefined} The BroadcastChannel instance used for\n * broadcasting updates, or undefined if the browser doesn't support the\n * Broadcast Channel API.\n *\n * @private\n */\n _getChannel() {\n if ('BroadcastChannel' in self && !this._channel) {\n this._channel = new BroadcastChannel(this._channelName);\n }\n return this._channel;\n }\n\n /**\n * Compare two [Responses](https://developer.mozilla.org/en-US/docs/Web/API/Response)\n * and send a message via the\n * {@link https://developers.google.com/web/updates/2016/09/broadcastchannel|Broadcast Channel API}\n * if they differ.\n *\n * Neither of the Responses can be {@link http://stackoverflow.com/questions/39109789|opaque}.\n *\n * @param {Response} firstResponse First responses to compare.\n * @param {Response} secondResponse Second responses to compare.\n * @param {string} url The URL of the updated request.\n * @param {string} cacheName Name of the cache the responses belong to.\n * This is included in the message posted on the broadcast channel.\n */\n notifyIfUpdated(firstResponse, secondResponse, url, cacheName) {\n if (!responsesAreSame(firstResponse, secondResponse, this._headersToCheck)) {\n broadcastUpdate(this._getChannel(), cacheName, url, this._source);\n }\n }\n }\n\n /*\n Copyright 2016 Google Inc. All Rights Reserved.\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n */\n\n /**\n * This plugin will automatically broadcast a message whenever a cached response\n * is updated.\n *\n * @memberof workbox.broadcastUpdate\n */\n class Plugin {\n /**\n * Construct a new instance with a specific `channelName` to\n * broadcast messages on\n *\n * @param {string} channelName The name that will be used when creating\n * the `BroadcastChannel`.\n * @param {Object} options\n * @param {Array<string>}\n * [options.headersToCheck=['content-length', 'etag', 'last-modified']] A\n * list of headers that will be used to determine whether the responses\n * differ.\n * @param {string} [options.source='workbox-broadcast-cache-update'] An\n * attribution value that indicates where the update originated.\n */\n constructor(channelName, options) {\n this._broadcastUpdate = new BroadcastCacheUpdate(channelName, options);\n }\n /**\n * A \"lifecycle\" callback that will be triggered automatically by the\n * `workbox-sw` and `workbox-runtime-caching` handlers when an entry is\n * added to a cache.\n *\n * @private\n * @param {Object} input The input object to this function.\n * @param {string} input.cacheName Name of the cache the responses belong to.\n * @param {Response} [input.oldResponse] The previous cached value, if any.\n * @param {Response} input.newResponse The new value in the cache.\n */\n cacheDidUpdate({ cacheName, oldResponse, newResponse, request }) {\n {\n assert_mjs.assert.isType(cacheName, 'string', {\n moduleName: 'workbox-broadcast-cache-update',\n className: 'Plugin',\n funcName: 'cacheDidUpdate',\n paramName: 'cacheName'\n });\n assert_mjs.assert.isInstance(newResponse, Response, {\n moduleName: 'workbox-broadcast-cache-update',\n className: 'Plugin',\n funcName: 'cacheDidUpdate',\n paramName: 'newResponse'\n });\n assert_mjs.assert.isInstance(request, Request, {\n moduleName: 'workbox-broadcast-cache-update',\n className: 'Plugin',\n funcName: 'cacheDidUpdate',\n paramName: 'request'\n });\n }\n\n if (!oldResponse) {\n // Without a two responses there is nothing to compare.\n return;\n }\n\n this._broadcastUpdate.notifyIfUpdated(oldResponse, newResponse, request.url, cacheName);\n }\n }\n\n /*\n Copyright 2017 Google Inc.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n https://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n */\n\n /*\n Copyright 2017 Google Inc.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n https://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n */\n\n exports.BroadcastCacheUpdate = BroadcastCacheUpdate;\n exports.Plugin = Plugin;\n exports.broadcastUpdate = broadcastUpdate;\n exports.messageTypes = messageTypes;\n\n return exports;\n\n}({},workbox.core._private,workbox.core._private,workbox.core._private));\n"],"file":"workbox-broadcast-cache-update.dev.js"}
|
@@ -0,0 +1,3 @@
|
|
1
|
+
this.workbox=this.workbox||{},this.workbox.broadcastUpdate=function(t){"use strict";try{self.workbox.v["workbox:broadcast-cache-update:3.3.1"]=1}catch(t){}const e=(t,e,s)=>{return!s.some(s=>t.headers.has(s)&&e.headers.has(s))||s.every(s=>{const a=t.headers.has(s)===e.headers.has(s),n=t.headers.get(s)===e.headers.get(s);return a&&n})};var s={CACHE_UPDATED:"CACHE_UPDATED"};const a=(t,e,a,n)=>{"BroadcastChannel"in self&&t&&t.postMessage({type:s.CACHE_UPDATED,meta:n,payload:{cacheName:e,updatedUrl:a}})};class n{constructor(t,{headersToCheck:e,source:s}={}){this.t=t,this.e=e||["content-length","etag","last-modified"],this.s=s||"workbox-broadcast-cache-update"}a(){return"BroadcastChannel"in self&&!this.n&&(this.n=new BroadcastChannel(this.t)),this.n}notifyIfUpdated(t,s,n,c){e(t,s,this.e)||a(this.a(),c,n,this.s)}}return t.BroadcastCacheUpdate=n,t.Plugin=class{constructor(t,e){this.c=new n(t,e)}cacheDidUpdate({cacheName:t,oldResponse:e,newResponse:s,request:a}){e&&this.c.notifyIfUpdated(e,s,a.url,t)}},t.broadcastUpdate=a,t.messageTypes=s,t}({});
|
2
|
+
|
3
|
+
//# sourceMappingURL=workbox-broadcast-cache-update.prod.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":[],"mappings":"","sources":["packages/workbox-broadcast-cache-update/browser.mjs"],"sourcesContent":["this.workbox=this.workbox||{},this.workbox.broadcastUpdate=function(t){\"use strict\";try{self.workbox.v[\"workbox:broadcast-cache-update:3.3.1\"]=1}catch(t){}const e=(t,e,s)=>{return!s.some(s=>t.headers.has(s)&&e.headers.has(s))||s.every(s=>{const a=t.headers.has(s)===e.headers.has(s),n=t.headers.get(s)===e.headers.get(s);return a&&n})};var s={CACHE_UPDATED:\"CACHE_UPDATED\"};const a=(t,e,a,n)=>{\"BroadcastChannel\"in self&&t&&t.postMessage({type:s.CACHE_UPDATED,meta:n,payload:{cacheName:e,updatedUrl:a}})};class n{constructor(t,{headersToCheck:e,source:s}={}){this.t=t,this.e=e||[\"content-length\",\"etag\",\"last-modified\"],this.s=s||\"workbox-broadcast-cache-update\"}a(){return\"BroadcastChannel\"in self&&!this.n&&(this.n=new BroadcastChannel(this.t)),this.n}notifyIfUpdated(t,s,n,c){e(t,s,this.e)||a(this.a(),c,n,this.s)}}return t.BroadcastCacheUpdate=n,t.Plugin=class{constructor(t,e){this.c=new n(t,e)}cacheDidUpdate({cacheName:t,oldResponse:e,newResponse:s,request:a}){e&&this.c.notifyIfUpdated(e,s,a.url,t)}},t.broadcastUpdate=a,t.messageTypes=s,t}({});\n"],"file":"workbox-broadcast-cache-update.prod.js"}
|