jekyll-pwa-workbox 0.0.6 → 0.0.7.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jekyll-pwa-workbox.rb +1 -1
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-background-sync.dev.js +819 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-background-sync.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-background-sync.prod.js +2 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-background-sync.prod.js.map +1 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-broadcast-update.dev.js +486 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-broadcast-update.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-broadcast-update.prod.js +2 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-broadcast-update.prod.js.map +1 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-cacheable-response.dev.js +192 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-cacheable-response.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-cacheable-response.prod.js +2 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-cacheable-response.prod.js.map +1 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-core.dev.js +1643 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-core.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-core.prod.js +2 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-core.prod.js.map +1 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-expiration.dev.js +652 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-expiration.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-expiration.prod.js +2 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-expiration.prod.js.map +1 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-navigation-preload.dev.js +103 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-navigation-preload.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-navigation-preload.prod.js +2 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-navigation-preload.prod.js.map +1 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-offline-ga.dev.js +236 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-offline-ga.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-offline-ga.prod.js +2 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-offline-ga.prod.js.map +1 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-precaching.dev.js +994 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-precaching.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-precaching.prod.js +2 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-precaching.prod.js.map +1 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-range-requests.dev.js +263 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-range-requests.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-range-requests.prod.js +2 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-range-requests.prod.js.map +1 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-routing.dev.js +1026 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-routing.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-routing.prod.js +2 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-routing.prod.js.map +1 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-strategies.dev.js +1127 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-strategies.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-strategies.prod.js +2 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-strategies.prod.js.map +1 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-streams.dev.js +333 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-streams.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-streams.prod.js +2 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-streams.prod.js.map +1 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-sw.js +2 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-sw.js.map +1 -0
- data/lib/vendor/{workbox-v4.3.1 → workbox-v5.0.0.alpha1}/workbox-window.dev.es5.mjs +248 -262
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.dev.es5.mjs.map +1 -0
- data/lib/vendor/{workbox-v4.3.1 → workbox-v5.0.0.alpha1}/workbox-window.dev.mjs +234 -242
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.dev.mjs.map +1 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.dev.umd.js +882 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.dev.umd.js.map +1 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.prod.es5.mjs +2 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.prod.es5.mjs.map +1 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.prod.mjs +2 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.prod.mjs.map +1 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.prod.umd.js +2 -0
- data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.prod.umd.js.map +1 -0
- metadata +75 -80
- data/lib/vendor/workbox-v4.3.1/workbox-background-sync.dev.js +0 -822
- data/lib/vendor/workbox-v4.3.1/workbox-background-sync.dev.js.map +0 -1
- data/lib/vendor/workbox-v4.3.1/workbox-background-sync.prod.js +0 -2
- data/lib/vendor/workbox-v4.3.1/workbox-background-sync.prod.js.map +0 -1
- data/lib/vendor/workbox-v4.3.1/workbox-broadcast-update.dev.js +0 -496
- data/lib/vendor/workbox-v4.3.1/workbox-broadcast-update.dev.js.map +0 -1
- data/lib/vendor/workbox-v4.3.1/workbox-broadcast-update.prod.js +0 -2
- data/lib/vendor/workbox-v4.3.1/workbox-broadcast-update.prod.js.map +0 -1
- data/lib/vendor/workbox-v4.3.1/workbox-cacheable-response.dev.js +0 -200
- data/lib/vendor/workbox-v4.3.1/workbox-cacheable-response.dev.js.map +0 -1
- data/lib/vendor/workbox-v4.3.1/workbox-cacheable-response.prod.js +0 -2
- data/lib/vendor/workbox-v4.3.1/workbox-cacheable-response.prod.js.map +0 -1
- data/lib/vendor/workbox-v4.3.1/workbox-core.dev.js +0 -1712
- data/lib/vendor/workbox-v4.3.1/workbox-core.dev.js.map +0 -1
- data/lib/vendor/workbox-v4.3.1/workbox-core.prod.js +0 -2
- data/lib/vendor/workbox-v4.3.1/workbox-core.prod.js.map +0 -1
- data/lib/vendor/workbox-v4.3.1/workbox-expiration.dev.js +0 -652
- data/lib/vendor/workbox-v4.3.1/workbox-expiration.dev.js.map +0 -1
- data/lib/vendor/workbox-v4.3.1/workbox-expiration.prod.js +0 -2
- data/lib/vendor/workbox-v4.3.1/workbox-expiration.prod.js.map +0 -1
- data/lib/vendor/workbox-v4.3.1/workbox-navigation-preload.dev.js +0 -110
- data/lib/vendor/workbox-v4.3.1/workbox-navigation-preload.dev.js.map +0 -1
- data/lib/vendor/workbox-v4.3.1/workbox-navigation-preload.prod.js +0 -2
- data/lib/vendor/workbox-v4.3.1/workbox-navigation-preload.prod.js.map +0 -1
- data/lib/vendor/workbox-v4.3.1/workbox-offline-ga.dev.js +0 -243
- data/lib/vendor/workbox-v4.3.1/workbox-offline-ga.dev.js.map +0 -1
- data/lib/vendor/workbox-v4.3.1/workbox-offline-ga.prod.js +0 -2
- data/lib/vendor/workbox-v4.3.1/workbox-offline-ga.prod.js.map +0 -1
- data/lib/vendor/workbox-v4.3.1/workbox-precaching.dev.js +0 -989
- data/lib/vendor/workbox-v4.3.1/workbox-precaching.dev.js.map +0 -1
- data/lib/vendor/workbox-v4.3.1/workbox-precaching.prod.js +0 -2
- data/lib/vendor/workbox-v4.3.1/workbox-precaching.prod.js.map +0 -1
- data/lib/vendor/workbox-v4.3.1/workbox-range-requests.dev.js +0 -268
- data/lib/vendor/workbox-v4.3.1/workbox-range-requests.dev.js.map +0 -1
- data/lib/vendor/workbox-v4.3.1/workbox-range-requests.prod.js +0 -2
- data/lib/vendor/workbox-v4.3.1/workbox-range-requests.prod.js.map +0 -1
- data/lib/vendor/workbox-v4.3.1/workbox-routing.dev.js +0 -1020
- data/lib/vendor/workbox-v4.3.1/workbox-routing.dev.js.map +0 -1
- data/lib/vendor/workbox-v4.3.1/workbox-routing.prod.js +0 -2
- data/lib/vendor/workbox-v4.3.1/workbox-routing.prod.js.map +0 -1
- data/lib/vendor/workbox-v4.3.1/workbox-strategies.dev.js +0 -1138
- data/lib/vendor/workbox-v4.3.1/workbox-strategies.dev.js.map +0 -1
- data/lib/vendor/workbox-v4.3.1/workbox-strategies.prod.js +0 -2
- data/lib/vendor/workbox-v4.3.1/workbox-strategies.prod.js.map +0 -1
- data/lib/vendor/workbox-v4.3.1/workbox-streams.dev.js +0 -337
- data/lib/vendor/workbox-v4.3.1/workbox-streams.dev.js.map +0 -1
- data/lib/vendor/workbox-v4.3.1/workbox-streams.prod.js +0 -2
- data/lib/vendor/workbox-v4.3.1/workbox-streams.prod.js.map +0 -1
- data/lib/vendor/workbox-v4.3.1/workbox-sw.js +0 -2
- data/lib/vendor/workbox-v4.3.1/workbox-sw.js.map +0 -1
- data/lib/vendor/workbox-v4.3.1/workbox-window.dev.es5.mjs.map +0 -1
- data/lib/vendor/workbox-v4.3.1/workbox-window.dev.mjs.map +0 -1
- data/lib/vendor/workbox-v4.3.1/workbox-window.dev.umd.js +0 -896
- data/lib/vendor/workbox-v4.3.1/workbox-window.dev.umd.js.map +0 -1
- data/lib/vendor/workbox-v4.3.1/workbox-window.prod.es5.mjs +0 -2
- data/lib/vendor/workbox-v4.3.1/workbox-window.prod.es5.mjs.map +0 -1
- data/lib/vendor/workbox-v4.3.1/workbox-window.prod.mjs +0 -2
- data/lib/vendor/workbox-v4.3.1/workbox-window.prod.mjs.map +0 -1
- data/lib/vendor/workbox-v4.3.1/workbox-window.prod.umd.js +0 -2
- data/lib/vendor/workbox-v4.3.1/workbox-window.prod.umd.js.map +0 -1
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"workbox-broadcast-update.dev.js","sources":["../_version.mjs","../responsesAreSame.mjs","../utils/constants.mjs","../broadcastUpdate.mjs","../BroadcastCacheUpdate.mjs","../Plugin.mjs","../index.mjs"],"sourcesContent":["try{self['workbox:broadcast-update:4.3.1']&&_()}catch(e){}// eslint-disable-line","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\n\nimport {WorkboxError} from 'workbox-core/_private/WorkboxError.mjs';\nimport {logger} from 'workbox-core/_private/logger.mjs';\nimport './_version.mjs';\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 */\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\n const atLeastOneHeaderAvailable = headersToCheck.some((header) => {\n return firstResponse.headers.has(header) &&\n secondResponse.headers.has(header);\n });\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: `,\n 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) ===\n secondResponse.headers.has(header);\n const headerValueComparison = firstResponse.headers.get(header) ===\n secondResponse.headers.get(header);\n\n return headerStateComparison && headerValueComparison;\n });\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*/\n\nimport '../_version.mjs';\n\nexport const CACHE_UPDATED_MESSAGE_TYPE = 'CACHE_UPDATED';\nexport const CACHE_UPDATED_MESSAGE_META = 'workbox-broadcast-update';\nexport const DEFAULT_BROADCAST_CHANNEL_NAME = 'workbox';\nexport const DEFAULT_DEFER_NOTIFICATION_TIMEOUT = 10000;\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*/\n\nimport {assert} from 'workbox-core/_private/assert.mjs';\nimport {CACHE_UPDATED_MESSAGE_TYPE, CACHE_UPDATED_MESSAGE_META}\n from './utils/constants.mjs';\n\nimport './_version.mjs';\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-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 {Object} options\n * @param {string} options.cacheName The name of the cache in which the updated\n * `Response` was stored.\n * @param {string} options.url The URL associated with the updated `Response`.\n * @param {BroadcastChannel} [options.channel] The `BroadcastChannel` to use.\n * If no channel is set or the browser doesn't support the BroadcastChannel\n * api, then an attempt will be made to `postMessage` each window client.\n *\n * @memberof workbox.broadcastUpdate\n */\nconst broadcastUpdate = async ({channel, cacheName, url}) => {\n if (process.env.NODE_ENV !== 'production') {\n assert.isType(cacheName, 'string', {\n moduleName: 'workbox-broadcast-update',\n className: '~',\n funcName: 'broadcastUpdate',\n paramName: 'cacheName',\n });\n assert.isType(url, 'string', {\n moduleName: 'workbox-broadcast-update',\n className: '~',\n funcName: 'broadcastUpdate',\n paramName: 'url',\n });\n }\n\n const data = {\n type: CACHE_UPDATED_MESSAGE_TYPE,\n meta: CACHE_UPDATED_MESSAGE_META,\n payload: {\n cacheName: cacheName,\n updatedURL: url,\n },\n };\n\n if (channel) {\n channel.postMessage(data);\n } else {\n const windows = await clients.matchAll({type: 'window'});\n for (const win of windows) {\n win.postMessage(data);\n }\n }\n};\n\nexport {broadcastUpdate};\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\n\nimport {assert} from 'workbox-core/_private/assert.mjs';\nimport {getFriendlyURL} from 'workbox-core/_private/getFriendlyURL.mjs';\nimport {logger} from 'workbox-core/_private/logger.mjs';\nimport {Deferred} from 'workbox-core/_private/Deferred.mjs';\nimport {responsesAreSame} from './responsesAreSame.mjs';\nimport {broadcastUpdate} from './broadcastUpdate.mjs';\n\nimport {DEFAULT_HEADERS_TO_CHECK, DEFAULT_BROADCAST_CHANNEL_NAME,\n DEFAULT_DEFER_NOTIFICATION_TIMEOUT} from './utils/constants.mjs';\n\nimport './_version.mjs';\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 * In browsers that do not support the Broadcast Channel API, the instance\n * falls back to sending the update via `postMessage()` to all window clients.\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 */\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>}\n * [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.channelName='workbox'] The name that will be used\n *. when creating the `BroadcastChannel`, which defaults to 'workbox' (the\n * channel name used by the `workbox-window` package).\n * @param {string} [options.deferNoticationTimeout=10000] The amount of time\n * to wait for a ready message from the window on navigation requests\n * before sending the update.\n */\n constructor({headersToCheck, channelName, deferNoticationTimeout} = {}) {\n this._headersToCheck = headersToCheck || DEFAULT_HEADERS_TO_CHECK;\n this._channelName = channelName || DEFAULT_BROADCAST_CHANNEL_NAME;\n this._deferNoticationTimeout =\n deferNoticationTimeout || DEFAULT_DEFER_NOTIFICATION_TIMEOUT;\n\n if (process.env.NODE_ENV !== 'production') {\n assert.isType(this._channelName, 'string', {\n moduleName: 'workbox-broadcast-update',\n className: 'BroadcastCacheUpdate',\n funcName: 'constructor',\n paramName: 'channelName',\n });\n assert.isArray(this._headersToCheck, {\n moduleName: 'workbox-broadcast-update',\n className: 'BroadcastCacheUpdate',\n funcName: 'constructor',\n paramName: 'headersToCheck',\n });\n }\n\n this._initWindowReadyDeferreds();\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 {Object} options\n * @param {Response} options.oldResponse Cached response to compare.\n * @param {Response} options.newResponse Possibly updated response to compare.\n * @param {string} options.url The URL of 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 notifyIfUpdated({oldResponse, newResponse, url, cacheName, event}) {\n if (!responsesAreSame(oldResponse, newResponse, this._headersToCheck)) {\n if (process.env.NODE_ENV !== 'production') {\n logger.log(`Newer response found (and cached) for:`, url);\n }\n\n const sendUpdate = async () => {\n // In the case of a navigation request, the requesting page will likely\n // not have loaded its JavaScript in time to recevied the update\n // notification, so we defer it until ready (or we timeout waiting).\n if (event && event.request && event.request.mode === 'navigate') {\n if (process.env.NODE_ENV !== 'production') {\n logger.debug(`Original request was a navigation request, ` +\n `waiting for a ready message from the window`, event.request);\n }\n await this._windowReadyOrTimeout(event);\n }\n await this._broadcastUpdate({\n channel: this._getChannel(),\n cacheName,\n url,\n });\n };\n\n // Send the update and ensure the SW stays alive until it's sent.\n const done = sendUpdate();\n\n if (event) {\n try {\n event.waitUntil(done);\n } catch (error) {\n if (process.env.NODE_ENV !== 'production') {\n logger.warn(`Unable to ensure service worker stays alive ` +\n `when broadcasting cache update for ` +\n `${getFriendlyURL(event.request.url)}'.`);\n }\n }\n }\n return done;\n }\n }\n\n /**\n * NOTE: this is exposed on the instance primarily so it can be spied on\n * in tests.\n *\n * @param {Object} opts\n * @private\n */\n async _broadcastUpdate(opts) {\n await broadcastUpdate(opts);\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 * Waits for a message from the window indicating that it's capable of\n * receiving broadcasts. By default, this will only wait for the amount of\n * time specified via the `deferNoticationTimeout` option.\n *\n * @param {Event} event The navigation fetch event.\n * @return {Promise}\n * @private\n */\n _windowReadyOrTimeout(event) {\n if (!this._navigationEventsDeferreds.has(event)) {\n const deferred = new Deferred();\n\n // Set the deferred on the `_navigationEventsDeferreds` map so it will\n // be resolved when the next ready message event comes.\n this._navigationEventsDeferreds.set(event, deferred);\n\n // But don't wait too long for the message since it may never come.\n const timeout = setTimeout(() => {\n if (process.env.NODE_ENV !== 'production') {\n logger.debug(`Timed out after ${this._deferNoticationTimeout}` +\n `ms waiting for message from window`);\n }\n deferred.resolve();\n }, this._deferNoticationTimeout);\n\n // Ensure the timeout is cleared if the deferred promise is resolved.\n deferred.promise.then(() => clearTimeout(timeout));\n }\n return this._navigationEventsDeferreds.get(event).promise;\n }\n\n /**\n * Creates a mapping between navigation fetch events and deferreds, and adds\n * a listener for message events from the window. When message events arrive,\n * all deferreds in the mapping are resolved.\n *\n * Note: it would be easier if we could only resolve the deferred of\n * navigation fetch event whose client ID matched the source ID of the\n * message event, but currently client IDs are not exposed on navigation\n * fetch events: https://www.chromestatus.com/feature/4846038800138240\n *\n * @private\n */\n _initWindowReadyDeferreds() {\n // A mapping between navigation events and their deferreds.\n this._navigationEventsDeferreds = new Map();\n\n // The message listener needs to be added in the initial run of the\n // service worker, but since we don't actually need to be listening for\n // messages until the cache updates, we only invoke the callback if set.\n self.addEventListener('message', (event) => {\n if (event.data.type === 'WINDOW_READY' &&\n event.data.meta === 'workbox-window' &&\n this._navigationEventsDeferreds.size > 0) {\n if (process.env.NODE_ENV !== 'production') {\n logger.debug(`Received WINDOW_READY event: `, event);\n }\n // Resolve any pending deferreds.\n for (const deferred of this._navigationEventsDeferreds.values()) {\n deferred.resolve();\n }\n this._navigationEventsDeferreds.clear();\n }\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*/\n\nimport {assert} from 'workbox-core/_private/assert.mjs';\nimport {BroadcastCacheUpdate} from './BroadcastCacheUpdate.mjs';\nimport './_version.mjs';\n\n/**\n * This plugin will automatically broadcast a message whenever a cached response\n * is updated.\n *\n * @memberof workbox.broadcastUpdate\n */\nclass Plugin {\n /**\n * Construct a BroadcastCacheUpdate instance with the passed options and\n * calls its `notifyIfUpdated()` method whenever the plugin's\n * `cacheDidUpdate` callback is invoked.\n *\n * @param {Object} options\n * @param {Array<string>}\n * [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.channelName='workbox'] The name that will be used\n *. when creating the `BroadcastChannel`, which defaults to 'workbox' (the\n * channel name used by the `workbox-window` package).\n * @param {string} [options.deferNoticationTimeout=10000] The amount of time\n * to wait for a ready message from the window on navigation requests\n * before sending the update.\n */\n constructor(options) {\n this._broadcastUpdate = new BroadcastCacheUpdate(options);\n }\n\n /**\n * A \"lifecycle\" callback that will be triggered automatically by the\n * `workbox-sw` and `workbox-runtime-caching` handlers when an entry is\n * added to a cache.\n *\n * @private\n * @param {Object} options The input object to this function.\n * @param {string} options.cacheName Name of the cache being updated.\n * @param {Response} [options.oldResponse] The previous cached value, if any.\n * @param {Response} options.newResponse The new value in the cache.\n * @param {Request} options.request The request that triggered the udpate.\n * @param {Request} [options.event] The event that triggered the update.\n */\n cacheDidUpdate({cacheName, oldResponse, newResponse, request, event}) {\n if (process.env.NODE_ENV !== 'production') {\n assert.isType(cacheName, 'string', {\n moduleName: 'workbox-broadcast-update',\n className: 'Plugin',\n funcName: 'cacheDidUpdate',\n paramName: 'cacheName',\n });\n assert.isInstance(newResponse, Response, {\n moduleName: 'workbox-broadcast-update',\n className: 'Plugin',\n funcName: 'cacheDidUpdate',\n paramName: 'newResponse',\n });\n assert.isInstance(request, Request, {\n moduleName: 'workbox-broadcast-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 this._broadcastUpdate.notifyIfUpdated({\n cacheName,\n oldResponse,\n newResponse,\n event,\n url: request.url,\n });\n }\n}\n\nexport {Plugin};\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\n\nimport {BroadcastCacheUpdate} from './BroadcastCacheUpdate.mjs';\nimport {Plugin} from './Plugin.mjs';\nimport {broadcastUpdate} from './broadcastUpdate.mjs';\nimport {responsesAreSame} from './responsesAreSame.mjs';\nimport './_version.mjs';\n\n\n/**\n * @namespace workbox.broadcastUpdate\n */\n\nexport {\n BroadcastCacheUpdate,\n Plugin,\n broadcastUpdate,\n responsesAreSame,\n};\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_BROADCAST_CHANNEL_NAME","DEFAULT_DEFER_NOTIFICATION_TIMEOUT","DEFAULT_HEADERS_TO_CHECK","broadcastUpdate","channel","cacheName","url","assert","isType","moduleName","className","funcName","paramName","data","type","meta","payload","updatedURL","postMessage","windows","clients","matchAll","win","BroadcastCacheUpdate","constructor","channelName","deferNoticationTimeout","_headersToCheck","_channelName","_deferNoticationTimeout","isArray","_initWindowReadyDeferreds","notifyIfUpdated","oldResponse","newResponse","event","log","sendUpdate","request","mode","_windowReadyOrTimeout","_broadcastUpdate","_getChannel","done","waitUntil","error","getFriendlyURL","opts","_channel","BroadcastChannel","_navigationEventsDeferreds","deferred","Deferred","set","timeout","setTimeout","resolve","promise","then","clearTimeout","Map","addEventListener","size","values","clear","Plugin","options","cacheDidUpdate","isInstance","Request"],"mappings":";;;;EAAA,IAAG;EAACA,EAAAA,IAAI,CAAC,gCAAD,CAAJ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AChB;EACA;EACD;;EACD,SAAKQ,gBAAL,CAAsBT,eAAtB,CAAsC;EACpC3B,MAAAA,SADoC;EAEpC4B,MAAAA,WAFoC;EAGpCC,MAAAA,WAHoC;EAIpCC,MAAAA,KAJoC;EAKpC7B,MAAAA,GAAG,EAAEgC,OAAO,CAAChC;EALuB,KAAtC;EAOD;;EApEU;;EClBb;;;;;;;;;;;;;;;;;;;"}
|
@@ -1,2 +0,0 @@
|
|
1
|
-
this.workbox=this.workbox||{},this.workbox.broadcastUpdate=function(e,t){"use strict";try{self["workbox:broadcast-update:4.3.1"]&&_()}catch(e){}const s=(e,t,s)=>{return!s.some(s=>e.headers.has(s)&&t.headers.has(s))||s.every(s=>{const n=e.headers.has(s)===t.headers.has(s),a=e.headers.get(s)===t.headers.get(s);return n&&a})},n="workbox",a=1e4,i=["content-length","etag","last-modified"],o=async({channel:e,cacheName:t,url:s})=>{const n={type:"CACHE_UPDATED",meta:"workbox-broadcast-update",payload:{cacheName:t,updatedURL:s}};if(e)e.postMessage(n);else{const e=await clients.matchAll({type:"window"});for(const t of e)t.postMessage(n)}};class c{constructor({headersToCheck:e,channelName:t,deferNoticationTimeout:s}={}){this.t=e||i,this.s=t||n,this.i=s||a,this.o()}notifyIfUpdated({oldResponse:e,newResponse:t,url:n,cacheName:a,event:i}){if(!s(e,t,this.t)){const e=(async()=>{i&&i.request&&"navigate"===i.request.mode&&await this.h(i),await this.l({channel:this.u(),cacheName:a,url:n})})();if(i)try{i.waitUntil(e)}catch(e){}return e}}async l(e){await o(e)}u(){return"BroadcastChannel"in self&&!this.p&&(this.p=new BroadcastChannel(this.s)),this.p}h(e){if(!this.m.has(e)){const s=new t.Deferred;this.m.set(e,s);const n=setTimeout(()=>{s.resolve()},this.i);s.promise.then(()=>clearTimeout(n))}return this.m.get(e).promise}o(){this.m=new Map,self.addEventListener("message",e=>{if("WINDOW_READY"===e.data.type&&"workbox-window"===e.data.meta&&this.m.size>0){for(const e of this.m.values())e.resolve();this.m.clear()}})}}return e.BroadcastCacheUpdate=c,e.Plugin=class{constructor(e){this.l=new c(e)}cacheDidUpdate({cacheName:e,oldResponse:t,newResponse:s,request:n,event:a}){t&&this.l.notifyIfUpdated({cacheName:e,oldResponse:t,newResponse:s,event:a,url:n.url})}},e.broadcastUpdate=o,e.responsesAreSame=s,e}({},workbox.core._private);
|
2
|
-
//# sourceMappingURL=workbox-broadcast-update.prod.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"workbox-broadcast-update.prod.js","sources":["../_version.mjs","../responsesAreSame.mjs","../utils/constants.mjs","../broadcastUpdate.mjs","../BroadcastCacheUpdate.mjs","../Plugin.mjs"],"sourcesContent":["try{self['workbox:broadcast-update:4.3.1']&&_()}catch(e){}// eslint-disable-line","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\n\nimport {WorkboxError} from 'workbox-core/_private/WorkboxError.mjs';\nimport {logger} from 'workbox-core/_private/logger.mjs';\nimport './_version.mjs';\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 */\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\n const atLeastOneHeaderAvailable = headersToCheck.some((header) => {\n return firstResponse.headers.has(header) &&\n secondResponse.headers.has(header);\n });\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: `,\n 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) ===\n secondResponse.headers.has(header);\n const headerValueComparison = firstResponse.headers.get(header) ===\n secondResponse.headers.get(header);\n\n return headerStateComparison && headerValueComparison;\n });\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*/\n\nimport '../_version.mjs';\n\nexport const CACHE_UPDATED_MESSAGE_TYPE = 'CACHE_UPDATED';\nexport const CACHE_UPDATED_MESSAGE_META = 'workbox-broadcast-update';\nexport const DEFAULT_BROADCAST_CHANNEL_NAME = 'workbox';\nexport const DEFAULT_DEFER_NOTIFICATION_TIMEOUT = 10000;\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*/\n\nimport {assert} from 'workbox-core/_private/assert.mjs';\nimport {CACHE_UPDATED_MESSAGE_TYPE, CACHE_UPDATED_MESSAGE_META}\n from './utils/constants.mjs';\n\nimport './_version.mjs';\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-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 {Object} options\n * @param {string} options.cacheName The name of the cache in which the updated\n * `Response` was stored.\n * @param {string} options.url The URL associated with the updated `Response`.\n * @param {BroadcastChannel} [options.channel] The `BroadcastChannel` to use.\n * If no channel is set or the browser doesn't support the BroadcastChannel\n * api, then an attempt will be made to `postMessage` each window client.\n *\n * @memberof workbox.broadcastUpdate\n */\nconst broadcastUpdate = async ({channel, cacheName, url}) => {\n if (process.env.NODE_ENV !== 'production') {\n assert.isType(cacheName, 'string', {\n moduleName: 'workbox-broadcast-update',\n className: '~',\n funcName: 'broadcastUpdate',\n paramName: 'cacheName',\n });\n assert.isType(url, 'string', {\n moduleName: 'workbox-broadcast-update',\n className: '~',\n funcName: 'broadcastUpdate',\n paramName: 'url',\n });\n }\n\n const data = {\n type: CACHE_UPDATED_MESSAGE_TYPE,\n meta: CACHE_UPDATED_MESSAGE_META,\n payload: {\n cacheName: cacheName,\n updatedURL: url,\n },\n };\n\n if (channel) {\n channel.postMessage(data);\n } else {\n const windows = await clients.matchAll({type: 'window'});\n for (const win of windows) {\n win.postMessage(data);\n }\n }\n};\n\nexport {broadcastUpdate};\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\n\nimport {assert} from 'workbox-core/_private/assert.mjs';\nimport {getFriendlyURL} from 'workbox-core/_private/getFriendlyURL.mjs';\nimport {logger} from 'workbox-core/_private/logger.mjs';\nimport {Deferred} from 'workbox-core/_private/Deferred.mjs';\nimport {responsesAreSame} from './responsesAreSame.mjs';\nimport {broadcastUpdate} from './broadcastUpdate.mjs';\n\nimport {DEFAULT_HEADERS_TO_CHECK, DEFAULT_BROADCAST_CHANNEL_NAME,\n DEFAULT_DEFER_NOTIFICATION_TIMEOUT} from './utils/constants.mjs';\n\nimport './_version.mjs';\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 * In browsers that do not support the Broadcast Channel API, the instance\n * falls back to sending the update via `postMessage()` to all window clients.\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 */\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>}\n * [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.channelName='workbox'] The name that will be used\n *. when creating the `BroadcastChannel`, which defaults to 'workbox' (the\n * channel name used by the `workbox-window` package).\n * @param {string} [options.deferNoticationTimeout=10000] The amount of time\n * to wait for a ready message from the window on navigation requests\n * before sending the update.\n */\n constructor({headersToCheck, channelName, deferNoticationTimeout} = {}) {\n this._headersToCheck = headersToCheck || DEFAULT_HEADERS_TO_CHECK;\n this._channelName = channelName || DEFAULT_BROADCAST_CHANNEL_NAME;\n this._deferNoticationTimeout =\n deferNoticationTimeout || DEFAULT_DEFER_NOTIFICATION_TIMEOUT;\n\n if (process.env.NODE_ENV !== 'production') {\n assert.isType(this._channelName, 'string', {\n moduleName: 'workbox-broadcast-update',\n className: 'BroadcastCacheUpdate',\n funcName: 'constructor',\n paramName: 'channelName',\n });\n assert.isArray(this._headersToCheck, {\n moduleName: 'workbox-broadcast-update',\n className: 'BroadcastCacheUpdate',\n funcName: 'constructor',\n paramName: 'headersToCheck',\n });\n }\n\n this._initWindowReadyDeferreds();\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 {Object} options\n * @param {Response} options.oldResponse Cached response to compare.\n * @param {Response} options.newResponse Possibly updated response to compare.\n * @param {string} options.url The URL of 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 notifyIfUpdated({oldResponse, newResponse, url, cacheName, event}) {\n if (!responsesAreSame(oldResponse, newResponse, this._headersToCheck)) {\n if (process.env.NODE_ENV !== 'production') {\n logger.log(`Newer response found (and cached) for:`, url);\n }\n\n const sendUpdate = async () => {\n // In the case of a navigation request, the requesting page will likely\n // not have loaded its JavaScript in time to recevied the update\n // notification, so we defer it until ready (or we timeout waiting).\n if (event && event.request && event.request.mode === 'navigate') {\n if (process.env.NODE_ENV !== 'production') {\n logger.debug(`Original request was a navigation request, ` +\n `waiting for a ready message from the window`, event.request);\n }\n await this._windowReadyOrTimeout(event);\n }\n await this._broadcastUpdate({\n channel: this._getChannel(),\n cacheName,\n url,\n });\n };\n\n // Send the update and ensure the SW stays alive until it's sent.\n const done = sendUpdate();\n\n if (event) {\n try {\n event.waitUntil(done);\n } catch (error) {\n if (process.env.NODE_ENV !== 'production') {\n logger.warn(`Unable to ensure service worker stays alive ` +\n `when broadcasting cache update for ` +\n `${getFriendlyURL(event.request.url)}'.`);\n }\n }\n }\n return done;\n }\n }\n\n /**\n * NOTE: this is exposed on the instance primarily so it can be spied on\n * in tests.\n *\n * @param {Object} opts\n * @private\n */\n async _broadcastUpdate(opts) {\n await broadcastUpdate(opts);\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 * Waits for a message from the window indicating that it's capable of\n * receiving broadcasts. By default, this will only wait for the amount of\n * time specified via the `deferNoticationTimeout` option.\n *\n * @param {Event} event The navigation fetch event.\n * @return {Promise}\n * @private\n */\n _windowReadyOrTimeout(event) {\n if (!this._navigationEventsDeferreds.has(event)) {\n const deferred = new Deferred();\n\n // Set the deferred on the `_navigationEventsDeferreds` map so it will\n // be resolved when the next ready message event comes.\n this._navigationEventsDeferreds.set(event, deferred);\n\n // But don't wait too long for the message since it may never come.\n const timeout = setTimeout(() => {\n if (process.env.NODE_ENV !== 'production') {\n logger.debug(`Timed out after ${this._deferNoticationTimeout}` +\n `ms waiting for message from window`);\n }\n deferred.resolve();\n }, this._deferNoticationTimeout);\n\n // Ensure the timeout is cleared if the deferred promise is resolved.\n deferred.promise.then(() => clearTimeout(timeout));\n }\n return this._navigationEventsDeferreds.get(event).promise;\n }\n\n /**\n * Creates a mapping between navigation fetch events and deferreds, and adds\n * a listener for message events from the window. When message events arrive,\n * all deferreds in the mapping are resolved.\n *\n * Note: it would be easier if we could only resolve the deferred of\n * navigation fetch event whose client ID matched the source ID of the\n * message event, but currently client IDs are not exposed on navigation\n * fetch events: https://www.chromestatus.com/feature/4846038800138240\n *\n * @private\n */\n _initWindowReadyDeferreds() {\n // A mapping between navigation events and their deferreds.\n this._navigationEventsDeferreds = new Map();\n\n // The message listener needs to be added in the initial run of the\n // service worker, but since we don't actually need to be listening for\n // messages until the cache updates, we only invoke the callback if set.\n self.addEventListener('message', (event) => {\n if (event.data.type === 'WINDOW_READY' &&\n event.data.meta === 'workbox-window' &&\n this._navigationEventsDeferreds.size > 0) {\n if (process.env.NODE_ENV !== 'production') {\n logger.debug(`Received WINDOW_READY event: `, event);\n }\n // Resolve any pending deferreds.\n for (const deferred of this._navigationEventsDeferreds.values()) {\n deferred.resolve();\n }\n this._navigationEventsDeferreds.clear();\n }\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*/\n\nimport {assert} from 'workbox-core/_private/assert.mjs';\nimport {BroadcastCacheUpdate} from './BroadcastCacheUpdate.mjs';\nimport './_version.mjs';\n\n/**\n * This plugin will automatically broadcast a message whenever a cached response\n * is updated.\n *\n * @memberof workbox.broadcastUpdate\n */\nclass Plugin {\n /**\n * Construct a BroadcastCacheUpdate instance with the passed options and\n * calls its `notifyIfUpdated()` method whenever the plugin's\n * `cacheDidUpdate` callback is invoked.\n *\n * @param {Object} options\n * @param {Array<string>}\n * [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.channelName='workbox'] The name that will be used\n *. when creating the `BroadcastChannel`, which defaults to 'workbox' (the\n * channel name used by the `workbox-window` package).\n * @param {string} [options.deferNoticationTimeout=10000] The amount of time\n * to wait for a ready message from the window on navigation requests\n * before sending the update.\n */\n constructor(options) {\n this._broadcastUpdate = new BroadcastCacheUpdate(options);\n }\n\n /**\n * A \"lifecycle\" callback that will be triggered automatically by the\n * `workbox-sw` and `workbox-runtime-caching` handlers when an entry is\n * added to a cache.\n *\n * @private\n * @param {Object} options The input object to this function.\n * @param {string} options.cacheName Name of the cache being updated.\n * @param {Response} [options.oldResponse] The previous cached value, if any.\n * @param {Response} options.newResponse The new value in the cache.\n * @param {Request} options.request The request that triggered the udpate.\n * @param {Request} [options.event] The event that triggered the update.\n */\n cacheDidUpdate({cacheName, oldResponse, newResponse, request, event}) {\n if (process.env.NODE_ENV !== 'production') {\n assert.isType(cacheName, 'string', {\n moduleName: 'workbox-broadcast-update',\n className: 'Plugin',\n funcName: 'cacheDidUpdate',\n paramName: 'cacheName',\n });\n assert.isInstance(newResponse, Response, {\n moduleName: 'workbox-broadcast-update',\n className: 'Plugin',\n funcName: 'cacheDidUpdate',\n paramName: 'newResponse',\n });\n assert.isInstance(request, Request, {\n moduleName: 'workbox-broadcast-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 this._broadcastUpdate.notifyIfUpdated({\n cacheName,\n oldResponse,\n newResponse,\n event,\n url: request.url,\n });\n }\n}\n\nexport {Plugin};\n"],"names":["self","_","e","responsesAreSame","firstResponse","secondResponse","headersToCheck","some","header","headers","has","every","headerStateComparison","headerValueComparison","get","DEFAULT_BROADCAST_CHANNEL_NAME","DEFAULT_DEFER_NOTIFICATION_TIMEOUT","DEFAULT_HEADERS_TO_CHECK","broadcastUpdate","async","channel","cacheName","url","data","type","meta","payload","updatedURL","postMessage","windows","clients","matchAll","win","BroadcastCacheUpdate","constructor","channelName","deferNoticationTimeout","_headersToCheck","_channelName","_deferNoticationTimeout","_initWindowReadyDeferreds","notifyIfUpdated","oldResponse","newResponse","event","this","done","request","mode","_windowReadyOrTimeout","_broadcastUpdate","_getChannel","sendUpdate","waitUntil","error","opts","_channel","BroadcastChannel","_navigationEventsDeferreds","deferred","Deferred","set","timeout","setTimeout","resolve","promise","then","clearTimeout","Map","addEventListener","size","values","clear","options","cacheDidUpdate"],"mappings":"sFAAA,IAAIA,KAAK,mCAAmCC,IAAI,MAAMC,UCwBhDC,EAAmB,CAACC,EAAeC,EAAgBC,YAQrBA,EAAeC,KAAMC,GAC9CJ,EAAcK,QAAQC,IAAIF,IAC/BH,EAAeI,QAAQC,IAAIF,KAgBxBF,EAAeK,MAAOH,UACrBI,EAAwBR,EAAcK,QAAQC,IAAIF,KACtDH,EAAeI,QAAQC,IAAIF,GACvBK,EAAwBT,EAAcK,QAAQK,IAAIN,KACtDH,EAAeI,QAAQK,IAAIN,UAEtBI,GAAyBC,KC5CvBE,EAAiC,UACjCC,EAAqC,IACrCC,EAA2B,CACtC,iBACA,OACA,iBCmCIC,EAAkBC,OAAQC,QAAAA,EAASC,UAAAA,EAAWC,IAAAA,YAgB5CC,EAAO,CACXC,KD3DsC,gBC4DtCC,KD3DsC,2BC4DtCC,QAAS,CACPL,UAAWA,EACXM,WAAYL,OAIZF,EACFA,EAAQQ,YAAYL,OACf,OACCM,QAAgBC,QAAQC,SAAS,CAACP,KAAM,eACzC,MAAMQ,KAAOH,EAChB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AAYA,EAAZC,YAAyBA,EAAzBI,QAAsCA,EAAtCH,MAA+CA,IAsBvDF,QAIAQ,EAAiBT,gBAAgB,CACpCpB,UAAAA,EACAqB,YAAAA,EACAC,YAAAA,EACAC,MAAAA,EACAtB,IAAKyB,EAAQzB"}
|
@@ -1,200 +0,0 @@
|
|
1
|
-
this.workbox = this.workbox || {};
|
2
|
-
this.workbox.cacheableResponse = (function (exports, WorkboxError_mjs, assert_mjs, getFriendlyURL_mjs, logger_mjs) {
|
3
|
-
'use strict';
|
4
|
-
|
5
|
-
try {
|
6
|
-
self['workbox:cacheable-response:4.3.1'] && _();
|
7
|
-
} catch (e) {} // eslint-disable-line
|
8
|
-
|
9
|
-
/*
|
10
|
-
Copyright 2018 Google LLC
|
11
|
-
|
12
|
-
Use of this source code is governed by an MIT-style
|
13
|
-
license that can be found in the LICENSE file or at
|
14
|
-
https://opensource.org/licenses/MIT.
|
15
|
-
*/
|
16
|
-
/**
|
17
|
-
* This class allows you to set up rules determining what
|
18
|
-
* status codes and/or headers need to be present in order for a
|
19
|
-
* [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
|
20
|
-
* to be considered cacheable.
|
21
|
-
*
|
22
|
-
* @memberof workbox.cacheableResponse
|
23
|
-
*/
|
24
|
-
|
25
|
-
class CacheableResponse {
|
26
|
-
/**
|
27
|
-
* To construct a new CacheableResponse instance you must provide at least
|
28
|
-
* one of the `config` properties.
|
29
|
-
*
|
30
|
-
* If both `statuses` and `headers` are specified, then both conditions must
|
31
|
-
* be met for the `Response` to be considered cacheable.
|
32
|
-
*
|
33
|
-
* @param {Object} config
|
34
|
-
* @param {Array<number>} [config.statuses] One or more status codes that a
|
35
|
-
* `Response` can have and be considered cacheable.
|
36
|
-
* @param {Object<string,string>} [config.headers] A mapping of header names
|
37
|
-
* and expected values that a `Response` can have and be considered cacheable.
|
38
|
-
* If multiple headers are provided, only one needs to be present.
|
39
|
-
*/
|
40
|
-
constructor(config = {}) {
|
41
|
-
{
|
42
|
-
if (!(config.statuses || config.headers)) {
|
43
|
-
throw new WorkboxError_mjs.WorkboxError('statuses-or-headers-required', {
|
44
|
-
moduleName: 'workbox-cacheable-response',
|
45
|
-
className: 'CacheableResponse',
|
46
|
-
funcName: 'constructor'
|
47
|
-
});
|
48
|
-
}
|
49
|
-
|
50
|
-
if (config.statuses) {
|
51
|
-
assert_mjs.assert.isArray(config.statuses, {
|
52
|
-
moduleName: 'workbox-cacheable-response',
|
53
|
-
className: 'CacheableResponse',
|
54
|
-
funcName: 'constructor',
|
55
|
-
paramName: 'config.statuses'
|
56
|
-
});
|
57
|
-
}
|
58
|
-
|
59
|
-
if (config.headers) {
|
60
|
-
assert_mjs.assert.isType(config.headers, 'object', {
|
61
|
-
moduleName: 'workbox-cacheable-response',
|
62
|
-
className: 'CacheableResponse',
|
63
|
-
funcName: 'constructor',
|
64
|
-
paramName: 'config.headers'
|
65
|
-
});
|
66
|
-
}
|
67
|
-
}
|
68
|
-
|
69
|
-
this._statuses = config.statuses;
|
70
|
-
this._headers = config.headers;
|
71
|
-
}
|
72
|
-
/**
|
73
|
-
* Checks a response to see whether it's cacheable or not, based on this
|
74
|
-
* object's configuration.
|
75
|
-
*
|
76
|
-
* @param {Response} response The response whose cacheability is being
|
77
|
-
* checked.
|
78
|
-
* @return {boolean} `true` if the `Response` is cacheable, and `false`
|
79
|
-
* otherwise.
|
80
|
-
*/
|
81
|
-
|
82
|
-
|
83
|
-
isResponseCacheable(response) {
|
84
|
-
{
|
85
|
-
assert_mjs.assert.isInstance(response, Response, {
|
86
|
-
moduleName: 'workbox-cacheable-response',
|
87
|
-
className: 'CacheableResponse',
|
88
|
-
funcName: 'isResponseCacheable',
|
89
|
-
paramName: 'response'
|
90
|
-
});
|
91
|
-
}
|
92
|
-
|
93
|
-
let cacheable = true;
|
94
|
-
|
95
|
-
if (this._statuses) {
|
96
|
-
cacheable = this._statuses.includes(response.status);
|
97
|
-
}
|
98
|
-
|
99
|
-
if (this._headers && cacheable) {
|
100
|
-
cacheable = Object.keys(this._headers).some(headerName => {
|
101
|
-
return response.headers.get(headerName) === this._headers[headerName];
|
102
|
-
});
|
103
|
-
}
|
104
|
-
|
105
|
-
{
|
106
|
-
if (!cacheable) {
|
107
|
-
logger_mjs.logger.groupCollapsed(`The request for ` + `'${getFriendlyURL_mjs.getFriendlyURL(response.url)}' returned a response that does ` + `not meet the criteria for being cached.`);
|
108
|
-
logger_mjs.logger.groupCollapsed(`View cacheability criteria here.`);
|
109
|
-
logger_mjs.logger.log(`Cacheable statuses: ` + JSON.stringify(this._statuses));
|
110
|
-
logger_mjs.logger.log(`Cacheable headers: ` + JSON.stringify(this._headers, null, 2));
|
111
|
-
logger_mjs.logger.groupEnd();
|
112
|
-
const logFriendlyHeaders = {};
|
113
|
-
response.headers.forEach((value, key) => {
|
114
|
-
logFriendlyHeaders[key] = value;
|
115
|
-
});
|
116
|
-
logger_mjs.logger.groupCollapsed(`View response status and headers here.`);
|
117
|
-
logger_mjs.logger.log(`Response status: ` + response.status);
|
118
|
-
logger_mjs.logger.log(`Response headers: ` + JSON.stringify(logFriendlyHeaders, null, 2));
|
119
|
-
logger_mjs.logger.groupEnd();
|
120
|
-
logger_mjs.logger.groupCollapsed(`View full response details here.`);
|
121
|
-
logger_mjs.logger.log(response.headers);
|
122
|
-
logger_mjs.logger.log(response);
|
123
|
-
logger_mjs.logger.groupEnd();
|
124
|
-
logger_mjs.logger.groupEnd();
|
125
|
-
}
|
126
|
-
}
|
127
|
-
|
128
|
-
return cacheable;
|
129
|
-
}
|
130
|
-
|
131
|
-
}
|
132
|
-
|
133
|
-
/*
|
134
|
-
Copyright 2018 Google LLC
|
135
|
-
|
136
|
-
Use of this source code is governed by an MIT-style
|
137
|
-
license that can be found in the LICENSE file or at
|
138
|
-
https://opensource.org/licenses/MIT.
|
139
|
-
*/
|
140
|
-
/**
|
141
|
-
* A class implementing the `cacheWillUpdate` lifecycle callback. This makes it
|
142
|
-
* easier to add in cacheability checks to requests made via Workbox's built-in
|
143
|
-
* strategies.
|
144
|
-
*
|
145
|
-
* @memberof workbox.cacheableResponse
|
146
|
-
*/
|
147
|
-
|
148
|
-
class Plugin {
|
149
|
-
/**
|
150
|
-
* To construct a new cacheable response Plugin instance you must provide at
|
151
|
-
* least one of the `config` properties.
|
152
|
-
*
|
153
|
-
* If both `statuses` and `headers` are specified, then both conditions must
|
154
|
-
* be met for the `Response` to be considered cacheable.
|
155
|
-
*
|
156
|
-
* @param {Object} config
|
157
|
-
* @param {Array<number>} [config.statuses] One or more status codes that a
|
158
|
-
* `Response` can have and be considered cacheable.
|
159
|
-
* @param {Object<string,string>} [config.headers] A mapping of header names
|
160
|
-
* and expected values that a `Response` can have and be considered cacheable.
|
161
|
-
* If multiple headers are provided, only one needs to be present.
|
162
|
-
*/
|
163
|
-
constructor(config) {
|
164
|
-
this._cacheableResponse = new CacheableResponse(config);
|
165
|
-
}
|
166
|
-
/**
|
167
|
-
* @param {Object} options
|
168
|
-
* @param {Response} options.response
|
169
|
-
* @return {boolean}
|
170
|
-
* @private
|
171
|
-
*/
|
172
|
-
|
173
|
-
|
174
|
-
cacheWillUpdate({
|
175
|
-
response
|
176
|
-
}) {
|
177
|
-
if (this._cacheableResponse.isResponseCacheable(response)) {
|
178
|
-
return response;
|
179
|
-
}
|
180
|
-
|
181
|
-
return null;
|
182
|
-
}
|
183
|
-
|
184
|
-
}
|
185
|
-
|
186
|
-
/*
|
187
|
-
Copyright 2018 Google LLC
|
188
|
-
|
189
|
-
Use of this source code is governed by an MIT-style
|
190
|
-
license that can be found in the LICENSE file or at
|
191
|
-
https://opensource.org/licenses/MIT.
|
192
|
-
*/
|
193
|
-
|
194
|
-
exports.CacheableResponse = CacheableResponse;
|
195
|
-
exports.Plugin = Plugin;
|
196
|
-
|
197
|
-
return exports;
|
198
|
-
|
199
|
-
}({}, workbox.core._private, workbox.core._private, workbox.core._private, workbox.core._private));
|
200
|
-
//# sourceMappingURL=workbox-cacheable-response.dev.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"workbox-cacheable-response.dev.js","sources":["../_version.mjs","../CacheableResponse.mjs","../Plugin.mjs","../index.mjs"],"sourcesContent":["try{self['workbox:cacheable-response:4.3.1']&&_()}catch(e){}// eslint-disable-line","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\n\nimport {WorkboxError} from 'workbox-core/_private/WorkboxError.mjs';\nimport {assert} from 'workbox-core/_private/assert.mjs';\nimport {getFriendlyURL} from 'workbox-core/_private/getFriendlyURL.mjs';\nimport {logger} from 'workbox-core/_private/logger.mjs';\nimport './_version.mjs';\n\n/**\n * This class allows you to set up rules determining what\n * status codes and/or headers need to be present in order for a\n * [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)\n * to be considered cacheable.\n *\n * @memberof workbox.cacheableResponse\n */\nclass CacheableResponse {\n /**\n * To construct a new CacheableResponse instance you must provide at least\n * one of the `config` properties.\n *\n * If both `statuses` and `headers` are specified, then both conditions must\n * be met for the `Response` to be considered cacheable.\n *\n * @param {Object} config\n * @param {Array<number>} [config.statuses] One or more status codes that a\n * `Response` can have and be considered cacheable.\n * @param {Object<string,string>} [config.headers] A mapping of header names\n * and expected values that a `Response` can have and be considered cacheable.\n * If multiple headers are provided, only one needs to be present.\n */\n constructor(config = {}) {\n if (process.env.NODE_ENV !== 'production') {\n if (!(config.statuses || config.headers)) {\n throw new WorkboxError('statuses-or-headers-required', {\n moduleName: 'workbox-cacheable-response',\n className: 'CacheableResponse',\n funcName: 'constructor',\n });\n }\n\n if (config.statuses) {\n assert.isArray(config.statuses, {\n moduleName: 'workbox-cacheable-response',\n className: 'CacheableResponse',\n funcName: 'constructor',\n paramName: 'config.statuses',\n });\n }\n\n if (config.headers) {\n assert.isType(config.headers, 'object', {\n moduleName: 'workbox-cacheable-response',\n className: 'CacheableResponse',\n funcName: 'constructor',\n paramName: 'config.headers',\n });\n }\n }\n\n this._statuses = config.statuses;\n this._headers = config.headers;\n }\n\n /**\n * Checks a response to see whether it's cacheable or not, based on this\n * object's configuration.\n *\n * @param {Response} response The response whose cacheability is being\n * checked.\n * @return {boolean} `true` if the `Response` is cacheable, and `false`\n * otherwise.\n */\n isResponseCacheable(response) {\n if (process.env.NODE_ENV !== 'production') {\n assert.isInstance(response, Response, {\n moduleName: 'workbox-cacheable-response',\n className: 'CacheableResponse',\n funcName: 'isResponseCacheable',\n paramName: 'response',\n });\n }\n\n let cacheable = true;\n\n if (this._statuses) {\n cacheable = this._statuses.includes(response.status);\n }\n\n if (this._headers && cacheable) {\n cacheable = Object.keys(this._headers).some((headerName) => {\n return response.headers.get(headerName) === this._headers[headerName];\n });\n }\n\n if (process.env.NODE_ENV !== 'production') {\n if (!cacheable) {\n logger.groupCollapsed(`The request for ` +\n `'${getFriendlyURL(response.url)}' returned a response that does ` +\n `not meet the criteria for being cached.`);\n\n logger.groupCollapsed(`View cacheability criteria here.`);\n logger.log(`Cacheable statuses: ` +\n JSON.stringify(this._statuses));\n logger.log(`Cacheable headers: ` +\n JSON.stringify(this._headers, null, 2));\n logger.groupEnd();\n\n const logFriendlyHeaders = {};\n response.headers.forEach((value, key) => {\n logFriendlyHeaders[key] = value;\n });\n\n logger.groupCollapsed(`View response status and headers here.`);\n logger.log(`Response status: ` + response.status);\n logger.log(`Response headers: ` +\n JSON.stringify(logFriendlyHeaders, null, 2));\n logger.groupEnd();\n\n logger.groupCollapsed(`View full response details here.`);\n logger.log(response.headers);\n logger.log(response);\n logger.groupEnd();\n\n logger.groupEnd();\n }\n }\n\n return cacheable;\n }\n}\n\nexport {CacheableResponse};\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\n\nimport {CacheableResponse} from './CacheableResponse.mjs';\nimport './_version.mjs';\n\n/**\n * A class implementing the `cacheWillUpdate` lifecycle callback. This makes it\n * easier to add in cacheability checks to requests made via Workbox's built-in\n * strategies.\n *\n * @memberof workbox.cacheableResponse\n */\nclass Plugin {\n /**\n * To construct a new cacheable response Plugin instance you must provide at\n * least one of the `config` properties.\n *\n * If both `statuses` and `headers` are specified, then both conditions must\n * be met for the `Response` to be considered cacheable.\n *\n * @param {Object} config\n * @param {Array<number>} [config.statuses] One or more status codes that a\n * `Response` can have and be considered cacheable.\n * @param {Object<string,string>} [config.headers] A mapping of header names\n * and expected values that a `Response` can have and be considered cacheable.\n * If multiple headers are provided, only one needs to be present.\n */\n constructor(config) {\n this._cacheableResponse = new CacheableResponse(config);\n }\n\n /**\n * @param {Object} options\n * @param {Response} options.response\n * @return {boolean}\n * @private\n */\n cacheWillUpdate({response}) {\n if (this._cacheableResponse.isResponseCacheable(response)) {\n return response;\n }\n return null;\n }\n}\n\nexport {Plugin};\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\n\nimport {CacheableResponse} from './CacheableResponse.mjs';\nimport {Plugin} from './Plugin.mjs';\nimport './_version.mjs';\n\n\n/**\n * @namespace workbox.cacheableResponse\n */\n\nexport {\n CacheableResponse,\n Plugin,\n};\n"],"names":["self","_","e","CacheableResponse","constructor","config","statuses","headers","WorkboxError","moduleName","className","funcName","assert","isArray","paramName","isType","_statuses","_headers","isResponseCacheable","response","isInstance","Response","cacheable","includes","status","Object","keys","some","headerName","get","logger","groupCollapsed","getFriendlyURL","url","log","JSON","stringify","groupEnd","logFriendlyHeaders","forEach","value","key","Plugin","_cacheableResponse","cacheWillUpdate"],"mappings":";;;;EAAA,IAAG;EAACA,EAAAA,IAAI,CAAC,kCAAD,CAAJ,IAA0CC,CAAC,EAA3C;EAA8C,CAAlD,CAAkD,OAAMC,CAAN,EAAQ;;ECA1D;;;;;;;AAQA,EAMA;;;;;;;;;EAQA,MAAMC,iBAAN,CAAwB;EACtB;;;;;;;;;;;;;;EAcAC,EAAAA,WAAW,CAAC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EACAM,QAAAA,iBAAM,CAACI,GAAP,CAAY,oBAAD,GACTC,IAAI,CAACC,SAAL,CAAeE,kBAAf,EAAmC,IAAnC,EAAyC,CAAzC,CADF;EAEAR,QAAAA,iBAAM,CAACO,QAAP;EAEAP,QAAAA,iBAAM,CAACC,cAAP,CAAuB,kCAAvB;EACAD,QAAAA,iBAAM,CAACI,GAAP,CAAWf,QAAQ,CAACZ,OAApB;EACAuB,QAAAA,iBAAM,CAACI,GAAP,CAAWf,QAAX;EACAW,QAAAA,iBAAM,CAACO,QAAP;EAEAP,QAAAA,iBAAM,CAACO,QAAP;EACD;EACF;;EAED,WAAOf,SAAP;EACD;;EAjHqB;;ECtBxB;;;;;;;AAQA,EAGA;;;;;;;;EAOA,MAAMoB,MAAN,CAAa;EACX;;;;;;;;;;;;;;EAcAtC,EAAAA,WAAW,CAACC,MAAD,EAAS;EAClB,SAAKsC,kBAAL,GAA0B,IAAIxC,iBAAJ,CAAsBE,MAAtB,CAA1B;EACD;EAED;;;;;;;;EAMAuC,EAAAA,eAAe,CAAC;EAACzB,IAAAA;EAAD,GAAD,EAAa;EAC1B,QAAI,KAAKwB,kBAAL,CAAwBzB,mBAAxB,CAA4CC,QAA5C,CAAJ,EAA2D;EACzD,aAAOA,QAAP;EACD;;EACD,WAAO,IAAP;EACD;;EA9BU;;EClBb;;;;;;;;;;;;;;;;;"}
|
@@ -1,2 +0,0 @@
|
|
1
|
-
this.workbox=this.workbox||{},this.workbox.cacheableResponse=function(t){"use strict";try{self["workbox:cacheable-response:4.3.1"]&&_()}catch(t){}class s{constructor(t={}){this.t=t.statuses,this.s=t.headers}isResponseCacheable(t){let s=!0;return this.t&&(s=this.t.includes(t.status)),this.s&&s&&(s=Object.keys(this.s).some(s=>t.headers.get(s)===this.s[s])),s}}return t.CacheableResponse=s,t.Plugin=class{constructor(t){this.i=new s(t)}cacheWillUpdate({response:t}){return this.i.isResponseCacheable(t)?t:null}},t}({});
|
2
|
-
//# sourceMappingURL=workbox-cacheable-response.prod.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"workbox-cacheable-response.prod.js","sources":["../_version.mjs","../CacheableResponse.mjs","../Plugin.mjs"],"sourcesContent":["try{self['workbox:cacheable-response:4.3.1']&&_()}catch(e){}// eslint-disable-line","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\n\nimport {WorkboxError} from 'workbox-core/_private/WorkboxError.mjs';\nimport {assert} from 'workbox-core/_private/assert.mjs';\nimport {getFriendlyURL} from 'workbox-core/_private/getFriendlyURL.mjs';\nimport {logger} from 'workbox-core/_private/logger.mjs';\nimport './_version.mjs';\n\n/**\n * This class allows you to set up rules determining what\n * status codes and/or headers need to be present in order for a\n * [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)\n * to be considered cacheable.\n *\n * @memberof workbox.cacheableResponse\n */\nclass CacheableResponse {\n /**\n * To construct a new CacheableResponse instance you must provide at least\n * one of the `config` properties.\n *\n * If both `statuses` and `headers` are specified, then both conditions must\n * be met for the `Response` to be considered cacheable.\n *\n * @param {Object} config\n * @param {Array<number>} [config.statuses] One or more status codes that a\n * `Response` can have and be considered cacheable.\n * @param {Object<string,string>} [config.headers] A mapping of header names\n * and expected values that a `Response` can have and be considered cacheable.\n * If multiple headers are provided, only one needs to be present.\n */\n constructor(config = {}) {\n if (process.env.NODE_ENV !== 'production') {\n if (!(config.statuses || config.headers)) {\n throw new WorkboxError('statuses-or-headers-required', {\n moduleName: 'workbox-cacheable-response',\n className: 'CacheableResponse',\n funcName: 'constructor',\n });\n }\n\n if (config.statuses) {\n assert.isArray(config.statuses, {\n moduleName: 'workbox-cacheable-response',\n className: 'CacheableResponse',\n funcName: 'constructor',\n paramName: 'config.statuses',\n });\n }\n\n if (config.headers) {\n assert.isType(config.headers, 'object', {\n moduleName: 'workbox-cacheable-response',\n className: 'CacheableResponse',\n funcName: 'constructor',\n paramName: 'config.headers',\n });\n }\n }\n\n this._statuses = config.statuses;\n this._headers = config.headers;\n }\n\n /**\n * Checks a response to see whether it's cacheable or not, based on this\n * object's configuration.\n *\n * @param {Response} response The response whose cacheability is being\n * checked.\n * @return {boolean} `true` if the `Response` is cacheable, and `false`\n * otherwise.\n */\n isResponseCacheable(response) {\n if (process.env.NODE_ENV !== 'production') {\n assert.isInstance(response, Response, {\n moduleName: 'workbox-cacheable-response',\n className: 'CacheableResponse',\n funcName: 'isResponseCacheable',\n paramName: 'response',\n });\n }\n\n let cacheable = true;\n\n if (this._statuses) {\n cacheable = this._statuses.includes(response.status);\n }\n\n if (this._headers && cacheable) {\n cacheable = Object.keys(this._headers).some((headerName) => {\n return response.headers.get(headerName) === this._headers[headerName];\n });\n }\n\n if (process.env.NODE_ENV !== 'production') {\n if (!cacheable) {\n logger.groupCollapsed(`The request for ` +\n `'${getFriendlyURL(response.url)}' returned a response that does ` +\n `not meet the criteria for being cached.`);\n\n logger.groupCollapsed(`View cacheability criteria here.`);\n logger.log(`Cacheable statuses: ` +\n JSON.stringify(this._statuses));\n logger.log(`Cacheable headers: ` +\n JSON.stringify(this._headers, null, 2));\n logger.groupEnd();\n\n const logFriendlyHeaders = {};\n response.headers.forEach((value, key) => {\n logFriendlyHeaders[key] = value;\n });\n\n logger.groupCollapsed(`View response status and headers here.`);\n logger.log(`Response status: ` + response.status);\n logger.log(`Response headers: ` +\n JSON.stringify(logFriendlyHeaders, null, 2));\n logger.groupEnd();\n\n logger.groupCollapsed(`View full response details here.`);\n logger.log(response.headers);\n logger.log(response);\n logger.groupEnd();\n\n logger.groupEnd();\n }\n }\n\n return cacheable;\n }\n}\n\nexport {CacheableResponse};\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\n\nimport {CacheableResponse} from './CacheableResponse.mjs';\nimport './_version.mjs';\n\n/**\n * A class implementing the `cacheWillUpdate` lifecycle callback. This makes it\n * easier to add in cacheability checks to requests made via Workbox's built-in\n * strategies.\n *\n * @memberof workbox.cacheableResponse\n */\nclass Plugin {\n /**\n * To construct a new cacheable response Plugin instance you must provide at\n * least one of the `config` properties.\n *\n * If both `statuses` and `headers` are specified, then both conditions must\n * be met for the `Response` to be considered cacheable.\n *\n * @param {Object} config\n * @param {Array<number>} [config.statuses] One or more status codes that a\n * `Response` can have and be considered cacheable.\n * @param {Object<string,string>} [config.headers] A mapping of header names\n * and expected values that a `Response` can have and be considered cacheable.\n * If multiple headers are provided, only one needs to be present.\n */\n constructor(config) {\n this._cacheableResponse = new CacheableResponse(config);\n }\n\n /**\n * @param {Object} options\n * @param {Response} options.response\n * @return {boolean}\n * @private\n */\n cacheWillUpdate({response}) {\n if (this._cacheableResponse.isResponseCacheable(response)) {\n return response;\n }\n return null;\n }\n}\n\nexport {Plugin};\n"],"names":["self","_","e","CacheableResponse","constructor","config","_statuses","statuses","_headers","headers","isResponseCacheable","response","cacheable","this","includes","status","Object","keys","some","headerName","get","_cacheableResponse","cacheWillUpdate"],"mappings":"sFAAA,IAAIA,KAAK,qCAAqCC,IAAI,MAAMC,ICsBxD,MAAMC,EAeJC,YAAYC,EAAS,SA6BdC,EAAYD,EAAOE,cACnBC,EAAWH,EAAOI,QAYzBC,oBAAoBC,OAUdC,GAAY,SAEZC,KAAKP,IACPM,EAAYC,KAAKP,EAAUQ,SAASH,EAASI,SAG3CF,KAAKL,GAAYI,IACnBA,EAAYI,OAAOC,KAAKJ,KAAKL,GAAUU,KAAMC,GACpCR,EAASF,QAAQW,IAAID,KAAgBN,KAAKL,EAASW,KAqCvDP,yCCpHX,MAeER,YAAYC,QACLgB,EAAqB,IAAIlB,EAAkBE,GASlDiB,iBAAgBX,SAACA,WACXE,KAAKQ,EAAmBX,oBAAoBC,GACvCA,EAEF"}
|
@@ -1,1712 +0,0 @@
|
|
1
|
-
this.workbox = this.workbox || {};
|
2
|
-
this.workbox.core = (function (exports) {
|
3
|
-
'use strict';
|
4
|
-
|
5
|
-
try {
|
6
|
-
self['workbox:core:4.3.1'] && _();
|
7
|
-
} catch (e) {} // eslint-disable-line
|
8
|
-
|
9
|
-
/*
|
10
|
-
Copyright 2019 Google LLC
|
11
|
-
Use of this source code is governed by an MIT-style
|
12
|
-
license that can be found in the LICENSE file or at
|
13
|
-
https://opensource.org/licenses/MIT.
|
14
|
-
*/
|
15
|
-
const logger = (() => {
|
16
|
-
let inGroup = false;
|
17
|
-
const methodToColorMap = {
|
18
|
-
debug: `#7f8c8d`,
|
19
|
-
// Gray
|
20
|
-
log: `#2ecc71`,
|
21
|
-
// Green
|
22
|
-
warn: `#f39c12`,
|
23
|
-
// Yellow
|
24
|
-
error: `#c0392b`,
|
25
|
-
// Red
|
26
|
-
groupCollapsed: `#3498db`,
|
27
|
-
// Blue
|
28
|
-
groupEnd: null // No colored prefix on groupEnd
|
29
|
-
|
30
|
-
};
|
31
|
-
|
32
|
-
const print = function (method, args) {
|
33
|
-
if (method === 'groupCollapsed') {
|
34
|
-
// Safari doesn't print all console.groupCollapsed() arguments:
|
35
|
-
// https://bugs.webkit.org/show_bug.cgi?id=182754
|
36
|
-
if (/^((?!chrome|android).)*safari/i.test(navigator.userAgent)) {
|
37
|
-
console[method](...args);
|
38
|
-
return;
|
39
|
-
}
|
40
|
-
}
|
41
|
-
|
42
|
-
const styles = [`background: ${methodToColorMap[method]}`, `border-radius: 0.5em`, `color: white`, `font-weight: bold`, `padding: 2px 0.5em`]; // When in a group, the workbox prefix is not displayed.
|
43
|
-
|
44
|
-
const logPrefix = inGroup ? [] : ['%cworkbox', styles.join(';')];
|
45
|
-
console[method](...logPrefix, ...args);
|
46
|
-
|
47
|
-
if (method === 'groupCollapsed') {
|
48
|
-
inGroup = true;
|
49
|
-
}
|
50
|
-
|
51
|
-
if (method === 'groupEnd') {
|
52
|
-
inGroup = false;
|
53
|
-
}
|
54
|
-
};
|
55
|
-
|
56
|
-
const api = {};
|
57
|
-
|
58
|
-
for (const method of Object.keys(methodToColorMap)) {
|
59
|
-
api[method] = (...args) => {
|
60
|
-
print(method, args);
|
61
|
-
};
|
62
|
-
}
|
63
|
-
|
64
|
-
return api;
|
65
|
-
})();
|
66
|
-
|
67
|
-
/*
|
68
|
-
Copyright 2018 Google LLC
|
69
|
-
|
70
|
-
Use of this source code is governed by an MIT-style
|
71
|
-
license that can be found in the LICENSE file or at
|
72
|
-
https://opensource.org/licenses/MIT.
|
73
|
-
*/
|
74
|
-
const messages = {
|
75
|
-
'invalid-value': ({
|
76
|
-
paramName,
|
77
|
-
validValueDescription,
|
78
|
-
value
|
79
|
-
}) => {
|
80
|
-
if (!paramName || !validValueDescription) {
|
81
|
-
throw new Error(`Unexpected input to 'invalid-value' error.`);
|
82
|
-
}
|
83
|
-
|
84
|
-
return `The '${paramName}' parameter was given a value with an ` + `unexpected value. ${validValueDescription} Received a value of ` + `${JSON.stringify(value)}.`;
|
85
|
-
},
|
86
|
-
'not-in-sw': ({
|
87
|
-
moduleName
|
88
|
-
}) => {
|
89
|
-
if (!moduleName) {
|
90
|
-
throw new Error(`Unexpected input to 'not-in-sw' error.`);
|
91
|
-
}
|
92
|
-
|
93
|
-
return `The '${moduleName}' must be used in a service worker.`;
|
94
|
-
},
|
95
|
-
'not-an-array': ({
|
96
|
-
moduleName,
|
97
|
-
className,
|
98
|
-
funcName,
|
99
|
-
paramName
|
100
|
-
}) => {
|
101
|
-
if (!moduleName || !className || !funcName || !paramName) {
|
102
|
-
throw new Error(`Unexpected input to 'not-an-array' error.`);
|
103
|
-
}
|
104
|
-
|
105
|
-
return `The parameter '${paramName}' passed into ` + `'${moduleName}.${className}.${funcName}()' must be an array.`;
|
106
|
-
},
|
107
|
-
'incorrect-type': ({
|
108
|
-
expectedType,
|
109
|
-
paramName,
|
110
|
-
moduleName,
|
111
|
-
className,
|
112
|
-
funcName
|
113
|
-
}) => {
|
114
|
-
if (!expectedType || !paramName || !moduleName || !funcName) {
|
115
|
-
throw new Error(`Unexpected input to 'incorrect-type' error.`);
|
116
|
-
}
|
117
|
-
|
118
|
-
return `The parameter '${paramName}' passed into ` + `'${moduleName}.${className ? className + '.' : ''}` + `${funcName}()' must be of type ${expectedType}.`;
|
119
|
-
},
|
120
|
-
'incorrect-class': ({
|
121
|
-
expectedClass,
|
122
|
-
paramName,
|
123
|
-
moduleName,
|
124
|
-
className,
|
125
|
-
funcName,
|
126
|
-
isReturnValueProblem
|
127
|
-
}) => {
|
128
|
-
if (!expectedClass || !moduleName || !funcName) {
|
129
|
-
throw new Error(`Unexpected input to 'incorrect-class' error.`);
|
130
|
-
}
|
131
|
-
|
132
|
-
if (isReturnValueProblem) {
|
133
|
-
return `The return value from ` + `'${moduleName}.${className ? className + '.' : ''}${funcName}()' ` + `must be an instance of class ${expectedClass.name}.`;
|
134
|
-
}
|
135
|
-
|
136
|
-
return `The parameter '${paramName}' passed into ` + `'${moduleName}.${className ? className + '.' : ''}${funcName}()' ` + `must be an instance of class ${expectedClass.name}.`;
|
137
|
-
},
|
138
|
-
'missing-a-method': ({
|
139
|
-
expectedMethod,
|
140
|
-
paramName,
|
141
|
-
moduleName,
|
142
|
-
className,
|
143
|
-
funcName
|
144
|
-
}) => {
|
145
|
-
if (!expectedMethod || !paramName || !moduleName || !className || !funcName) {
|
146
|
-
throw new Error(`Unexpected input to 'missing-a-method' error.`);
|
147
|
-
}
|
148
|
-
|
149
|
-
return `${moduleName}.${className}.${funcName}() expected the ` + `'${paramName}' parameter to expose a '${expectedMethod}' method.`;
|
150
|
-
},
|
151
|
-
'add-to-cache-list-unexpected-type': ({
|
152
|
-
entry
|
153
|
-
}) => {
|
154
|
-
return `An unexpected entry was passed to ` + `'workbox-precaching.PrecacheController.addToCacheList()' The entry ` + `'${JSON.stringify(entry)}' isn't supported. You must supply an array of ` + `strings with one or more characters, objects with a url property or ` + `Request objects.`;
|
155
|
-
},
|
156
|
-
'add-to-cache-list-conflicting-entries': ({
|
157
|
-
firstEntry,
|
158
|
-
secondEntry
|
159
|
-
}) => {
|
160
|
-
if (!firstEntry || !secondEntry) {
|
161
|
-
throw new Error(`Unexpected input to ` + `'add-to-cache-list-duplicate-entries' error.`);
|
162
|
-
}
|
163
|
-
|
164
|
-
return `Two of the entries passed to ` + `'workbox-precaching.PrecacheController.addToCacheList()' had the URL ` + `${firstEntry._entryId} but different revision details. Workbox is ` + `is unable to cache and version the asset correctly. Please remove one ` + `of the entries.`;
|
165
|
-
},
|
166
|
-
'plugin-error-request-will-fetch': ({
|
167
|
-
thrownError
|
168
|
-
}) => {
|
169
|
-
if (!thrownError) {
|
170
|
-
throw new Error(`Unexpected input to ` + `'plugin-error-request-will-fetch', error.`);
|
171
|
-
}
|
172
|
-
|
173
|
-
return `An error was thrown by a plugins 'requestWillFetch()' method. ` + `The thrown error message was: '${thrownError.message}'.`;
|
174
|
-
},
|
175
|
-
'invalid-cache-name': ({
|
176
|
-
cacheNameId,
|
177
|
-
value
|
178
|
-
}) => {
|
179
|
-
if (!cacheNameId) {
|
180
|
-
throw new Error(`Expected a 'cacheNameId' for error 'invalid-cache-name'`);
|
181
|
-
}
|
182
|
-
|
183
|
-
return `You must provide a name containing at least one character for ` + `setCacheDeatils({${cacheNameId}: '...'}). Received a value of ` + `'${JSON.stringify(value)}'`;
|
184
|
-
},
|
185
|
-
'unregister-route-but-not-found-with-method': ({
|
186
|
-
method
|
187
|
-
}) => {
|
188
|
-
if (!method) {
|
189
|
-
throw new Error(`Unexpected input to ` + `'unregister-route-but-not-found-with-method' error.`);
|
190
|
-
}
|
191
|
-
|
192
|
-
return `The route you're trying to unregister was not previously ` + `registered for the method type '${method}'.`;
|
193
|
-
},
|
194
|
-
'unregister-route-route-not-registered': () => {
|
195
|
-
return `The route you're trying to unregister was not previously ` + `registered.`;
|
196
|
-
},
|
197
|
-
'queue-replay-failed': ({
|
198
|
-
name
|
199
|
-
}) => {
|
200
|
-
return `Replaying the background sync queue '${name}' failed.`;
|
201
|
-
},
|
202
|
-
'duplicate-queue-name': ({
|
203
|
-
name
|
204
|
-
}) => {
|
205
|
-
return `The Queue name '${name}' is already being used. ` + `All instances of backgroundSync.Queue must be given unique names.`;
|
206
|
-
},
|
207
|
-
'expired-test-without-max-age': ({
|
208
|
-
methodName,
|
209
|
-
paramName
|
210
|
-
}) => {
|
211
|
-
return `The '${methodName}()' method can only be used when the ` + `'${paramName}' is used in the constructor.`;
|
212
|
-
},
|
213
|
-
'unsupported-route-type': ({
|
214
|
-
moduleName,
|
215
|
-
className,
|
216
|
-
funcName,
|
217
|
-
paramName
|
218
|
-
}) => {
|
219
|
-
return `The supplied '${paramName}' parameter was an unsupported type. ` + `Please check the docs for ${moduleName}.${className}.${funcName} for ` + `valid input types.`;
|
220
|
-
},
|
221
|
-
'not-array-of-class': ({
|
222
|
-
value,
|
223
|
-
expectedClass,
|
224
|
-
moduleName,
|
225
|
-
className,
|
226
|
-
funcName,
|
227
|
-
paramName
|
228
|
-
}) => {
|
229
|
-
return `The supplied '${paramName}' parameter must be an array of ` + `'${expectedClass}' objects. Received '${JSON.stringify(value)},'. ` + `Please check the call to ${moduleName}.${className}.${funcName}() ` + `to fix the issue.`;
|
230
|
-
},
|
231
|
-
'max-entries-or-age-required': ({
|
232
|
-
moduleName,
|
233
|
-
className,
|
234
|
-
funcName
|
235
|
-
}) => {
|
236
|
-
return `You must define either config.maxEntries or config.maxAgeSeconds` + `in ${moduleName}.${className}.${funcName}`;
|
237
|
-
},
|
238
|
-
'statuses-or-headers-required': ({
|
239
|
-
moduleName,
|
240
|
-
className,
|
241
|
-
funcName
|
242
|
-
}) => {
|
243
|
-
return `You must define either config.statuses or config.headers` + `in ${moduleName}.${className}.${funcName}`;
|
244
|
-
},
|
245
|
-
'invalid-string': ({
|
246
|
-
moduleName,
|
247
|
-
className,
|
248
|
-
funcName,
|
249
|
-
paramName
|
250
|
-
}) => {
|
251
|
-
if (!paramName || !moduleName || !funcName) {
|
252
|
-
throw new Error(`Unexpected input to 'invalid-string' error.`);
|
253
|
-
}
|
254
|
-
|
255
|
-
return `When using strings, the '${paramName}' parameter must start with ` + `'http' (for cross-origin matches) or '/' (for same-origin matches). ` + `Please see the docs for ${moduleName}.${funcName}() for ` + `more info.`;
|
256
|
-
},
|
257
|
-
'channel-name-required': () => {
|
258
|
-
return `You must provide a channelName to construct a ` + `BroadcastCacheUpdate instance.`;
|
259
|
-
},
|
260
|
-
'invalid-responses-are-same-args': () => {
|
261
|
-
return `The arguments passed into responsesAreSame() appear to be ` + `invalid. Please ensure valid Responses are used.`;
|
262
|
-
},
|
263
|
-
'expire-custom-caches-only': () => {
|
264
|
-
return `You must provide a 'cacheName' property when using the ` + `expiration plugin with a runtime caching strategy.`;
|
265
|
-
},
|
266
|
-
'unit-must-be-bytes': ({
|
267
|
-
normalizedRangeHeader
|
268
|
-
}) => {
|
269
|
-
if (!normalizedRangeHeader) {
|
270
|
-
throw new Error(`Unexpected input to 'unit-must-be-bytes' error.`);
|
271
|
-
}
|
272
|
-
|
273
|
-
return `The 'unit' portion of the Range header must be set to 'bytes'. ` + `The Range header provided was "${normalizedRangeHeader}"`;
|
274
|
-
},
|
275
|
-
'single-range-only': ({
|
276
|
-
normalizedRangeHeader
|
277
|
-
}) => {
|
278
|
-
if (!normalizedRangeHeader) {
|
279
|
-
throw new Error(`Unexpected input to 'single-range-only' error.`);
|
280
|
-
}
|
281
|
-
|
282
|
-
return `Multiple ranges are not supported. Please use a single start ` + `value, and optional end value. The Range header provided was ` + `"${normalizedRangeHeader}"`;
|
283
|
-
},
|
284
|
-
'invalid-range-values': ({
|
285
|
-
normalizedRangeHeader
|
286
|
-
}) => {
|
287
|
-
if (!normalizedRangeHeader) {
|
288
|
-
throw new Error(`Unexpected input to 'invalid-range-values' error.`);
|
289
|
-
}
|
290
|
-
|
291
|
-
return `The Range header is missing both start and end values. At least ` + `one of those values is needed. The Range header provided was ` + `"${normalizedRangeHeader}"`;
|
292
|
-
},
|
293
|
-
'no-range-header': () => {
|
294
|
-
return `No Range header was found in the Request provided.`;
|
295
|
-
},
|
296
|
-
'range-not-satisfiable': ({
|
297
|
-
size,
|
298
|
-
start,
|
299
|
-
end
|
300
|
-
}) => {
|
301
|
-
return `The start (${start}) and end (${end}) values in the Range are ` + `not satisfiable by the cached response, which is ${size} bytes.`;
|
302
|
-
},
|
303
|
-
'attempt-to-cache-non-get-request': ({
|
304
|
-
url,
|
305
|
-
method
|
306
|
-
}) => {
|
307
|
-
return `Unable to cache '${url}' because it is a '${method}' request and ` + `only 'GET' requests can be cached.`;
|
308
|
-
},
|
309
|
-
'cache-put-with-no-response': ({
|
310
|
-
url
|
311
|
-
}) => {
|
312
|
-
return `There was an attempt to cache '${url}' but the response was not ` + `defined.`;
|
313
|
-
},
|
314
|
-
'no-response': ({
|
315
|
-
url,
|
316
|
-
error
|
317
|
-
}) => {
|
318
|
-
let message = `The strategy could not generate a response for '${url}'.`;
|
319
|
-
|
320
|
-
if (error) {
|
321
|
-
message += ` The underlying error is ${error}.`;
|
322
|
-
}
|
323
|
-
|
324
|
-
return message;
|
325
|
-
},
|
326
|
-
'bad-precaching-response': ({
|
327
|
-
url,
|
328
|
-
status
|
329
|
-
}) => {
|
330
|
-
return `The precaching request for '${url}' failed with an HTTP ` + `status of ${status}.`;
|
331
|
-
}
|
332
|
-
};
|
333
|
-
|
334
|
-
/*
|
335
|
-
Copyright 2018 Google LLC
|
336
|
-
|
337
|
-
Use of this source code is governed by an MIT-style
|
338
|
-
license that can be found in the LICENSE file or at
|
339
|
-
https://opensource.org/licenses/MIT.
|
340
|
-
*/
|
341
|
-
|
342
|
-
const generatorFunction = (code, ...args) => {
|
343
|
-
const message = messages[code];
|
344
|
-
|
345
|
-
if (!message) {
|
346
|
-
throw new Error(`Unable to find message for code '${code}'.`);
|
347
|
-
}
|
348
|
-
|
349
|
-
return message(...args);
|
350
|
-
};
|
351
|
-
|
352
|
-
const messageGenerator = generatorFunction;
|
353
|
-
|
354
|
-
/*
|
355
|
-
Copyright 2018 Google LLC
|
356
|
-
|
357
|
-
Use of this source code is governed by an MIT-style
|
358
|
-
license that can be found in the LICENSE file or at
|
359
|
-
https://opensource.org/licenses/MIT.
|
360
|
-
*/
|
361
|
-
/**
|
362
|
-
* Workbox errors should be thrown with this class.
|
363
|
-
* This allows use to ensure the type easily in tests,
|
364
|
-
* helps developers identify errors from workbox
|
365
|
-
* easily and allows use to optimise error
|
366
|
-
* messages correctly.
|
367
|
-
*
|
368
|
-
* @private
|
369
|
-
*/
|
370
|
-
|
371
|
-
class WorkboxError extends Error {
|
372
|
-
/**
|
373
|
-
*
|
374
|
-
* @param {string} errorCode The error code that
|
375
|
-
* identifies this particular error.
|
376
|
-
* @param {Object=} details Any relevant arguments
|
377
|
-
* that will help developers identify issues should
|
378
|
-
* be added as a key on the context object.
|
379
|
-
*/
|
380
|
-
constructor(errorCode, details) {
|
381
|
-
let message = messageGenerator(errorCode, details);
|
382
|
-
super(message);
|
383
|
-
this.name = errorCode;
|
384
|
-
this.details = details;
|
385
|
-
}
|
386
|
-
|
387
|
-
}
|
388
|
-
|
389
|
-
/*
|
390
|
-
Copyright 2018 Google LLC
|
391
|
-
|
392
|
-
Use of this source code is governed by an MIT-style
|
393
|
-
license that can be found in the LICENSE file or at
|
394
|
-
https://opensource.org/licenses/MIT.
|
395
|
-
*/
|
396
|
-
/*
|
397
|
-
* This method returns true if the current context is a service worker.
|
398
|
-
*/
|
399
|
-
|
400
|
-
const isSWEnv = moduleName => {
|
401
|
-
if (!('ServiceWorkerGlobalScope' in self)) {
|
402
|
-
throw new WorkboxError('not-in-sw', {
|
403
|
-
moduleName
|
404
|
-
});
|
405
|
-
}
|
406
|
-
};
|
407
|
-
/*
|
408
|
-
* This method throws if the supplied value is not an array.
|
409
|
-
* The destructed values are required to produce a meaningful error for users.
|
410
|
-
* The destructed and restructured object is so it's clear what is
|
411
|
-
* needed.
|
412
|
-
*/
|
413
|
-
|
414
|
-
|
415
|
-
const isArray = (value, {
|
416
|
-
moduleName,
|
417
|
-
className,
|
418
|
-
funcName,
|
419
|
-
paramName
|
420
|
-
}) => {
|
421
|
-
if (!Array.isArray(value)) {
|
422
|
-
throw new WorkboxError('not-an-array', {
|
423
|
-
moduleName,
|
424
|
-
className,
|
425
|
-
funcName,
|
426
|
-
paramName
|
427
|
-
});
|
428
|
-
}
|
429
|
-
};
|
430
|
-
|
431
|
-
const hasMethod = (object, expectedMethod, {
|
432
|
-
moduleName,
|
433
|
-
className,
|
434
|
-
funcName,
|
435
|
-
paramName
|
436
|
-
}) => {
|
437
|
-
const type = typeof object[expectedMethod];
|
438
|
-
|
439
|
-
if (type !== 'function') {
|
440
|
-
throw new WorkboxError('missing-a-method', {
|
441
|
-
paramName,
|
442
|
-
expectedMethod,
|
443
|
-
moduleName,
|
444
|
-
className,
|
445
|
-
funcName
|
446
|
-
});
|
447
|
-
}
|
448
|
-
};
|
449
|
-
|
450
|
-
const isType = (object, expectedType, {
|
451
|
-
moduleName,
|
452
|
-
className,
|
453
|
-
funcName,
|
454
|
-
paramName
|
455
|
-
}) => {
|
456
|
-
if (typeof object !== expectedType) {
|
457
|
-
throw new WorkboxError('incorrect-type', {
|
458
|
-
paramName,
|
459
|
-
expectedType,
|
460
|
-
moduleName,
|
461
|
-
className,
|
462
|
-
funcName
|
463
|
-
});
|
464
|
-
}
|
465
|
-
};
|
466
|
-
|
467
|
-
const isInstance = (object, expectedClass, {
|
468
|
-
moduleName,
|
469
|
-
className,
|
470
|
-
funcName,
|
471
|
-
paramName,
|
472
|
-
isReturnValueProblem
|
473
|
-
}) => {
|
474
|
-
if (!(object instanceof expectedClass)) {
|
475
|
-
throw new WorkboxError('incorrect-class', {
|
476
|
-
paramName,
|
477
|
-
expectedClass,
|
478
|
-
moduleName,
|
479
|
-
className,
|
480
|
-
funcName,
|
481
|
-
isReturnValueProblem
|
482
|
-
});
|
483
|
-
}
|
484
|
-
};
|
485
|
-
|
486
|
-
const isOneOf = (value, validValues, {
|
487
|
-
paramName
|
488
|
-
}) => {
|
489
|
-
if (!validValues.includes(value)) {
|
490
|
-
throw new WorkboxError('invalid-value', {
|
491
|
-
paramName,
|
492
|
-
value,
|
493
|
-
validValueDescription: `Valid values are ${JSON.stringify(validValues)}.`
|
494
|
-
});
|
495
|
-
}
|
496
|
-
};
|
497
|
-
|
498
|
-
const isArrayOfClass = (value, expectedClass, {
|
499
|
-
moduleName,
|
500
|
-
className,
|
501
|
-
funcName,
|
502
|
-
paramName
|
503
|
-
}) => {
|
504
|
-
const error = new WorkboxError('not-array-of-class', {
|
505
|
-
value,
|
506
|
-
expectedClass,
|
507
|
-
moduleName,
|
508
|
-
className,
|
509
|
-
funcName,
|
510
|
-
paramName
|
511
|
-
});
|
512
|
-
|
513
|
-
if (!Array.isArray(value)) {
|
514
|
-
throw error;
|
515
|
-
}
|
516
|
-
|
517
|
-
for (let item of value) {
|
518
|
-
if (!(item instanceof expectedClass)) {
|
519
|
-
throw error;
|
520
|
-
}
|
521
|
-
}
|
522
|
-
};
|
523
|
-
|
524
|
-
const finalAssertExports = {
|
525
|
-
hasMethod,
|
526
|
-
isArray,
|
527
|
-
isInstance,
|
528
|
-
isOneOf,
|
529
|
-
isSWEnv,
|
530
|
-
isType,
|
531
|
-
isArrayOfClass
|
532
|
-
};
|
533
|
-
|
534
|
-
/*
|
535
|
-
Copyright 2018 Google LLC
|
536
|
-
|
537
|
-
Use of this source code is governed by an MIT-style
|
538
|
-
license that can be found in the LICENSE file or at
|
539
|
-
https://opensource.org/licenses/MIT.
|
540
|
-
*/
|
541
|
-
|
542
|
-
const quotaErrorCallbacks = new Set();
|
543
|
-
|
544
|
-
/*
|
545
|
-
Copyright 2019 Google LLC
|
546
|
-
|
547
|
-
Use of this source code is governed by an MIT-style
|
548
|
-
license that can be found in the LICENSE file or at
|
549
|
-
https://opensource.org/licenses/MIT.
|
550
|
-
*/
|
551
|
-
/**
|
552
|
-
* Adds a function to the set of quotaErrorCallbacks that will be executed if
|
553
|
-
* there's a quota error.
|
554
|
-
*
|
555
|
-
* @param {Function} callback
|
556
|
-
* @memberof workbox.core
|
557
|
-
*/
|
558
|
-
|
559
|
-
function registerQuotaErrorCallback(callback) {
|
560
|
-
{
|
561
|
-
finalAssertExports.isType(callback, 'function', {
|
562
|
-
moduleName: 'workbox-core',
|
563
|
-
funcName: 'register',
|
564
|
-
paramName: 'callback'
|
565
|
-
});
|
566
|
-
}
|
567
|
-
|
568
|
-
quotaErrorCallbacks.add(callback);
|
569
|
-
|
570
|
-
{
|
571
|
-
logger.log('Registered a callback to respond to quota errors.', callback);
|
572
|
-
}
|
573
|
-
}
|
574
|
-
|
575
|
-
/*
|
576
|
-
Copyright 2018 Google LLC
|
577
|
-
|
578
|
-
Use of this source code is governed by an MIT-style
|
579
|
-
license that can be found in the LICENSE file or at
|
580
|
-
https://opensource.org/licenses/MIT.
|
581
|
-
*/
|
582
|
-
const _cacheNameDetails = {
|
583
|
-
googleAnalytics: 'googleAnalytics',
|
584
|
-
precache: 'precache-v2',
|
585
|
-
prefix: 'workbox',
|
586
|
-
runtime: 'runtime',
|
587
|
-
suffix: self.registration.scope
|
588
|
-
};
|
589
|
-
|
590
|
-
const _createCacheName = cacheName => {
|
591
|
-
return [_cacheNameDetails.prefix, cacheName, _cacheNameDetails.suffix].filter(value => value.length > 0).join('-');
|
592
|
-
};
|
593
|
-
|
594
|
-
const cacheNames = {
|
595
|
-
updateDetails: details => {
|
596
|
-
Object.keys(_cacheNameDetails).forEach(key => {
|
597
|
-
if (typeof details[key] !== 'undefined') {
|
598
|
-
_cacheNameDetails[key] = details[key];
|
599
|
-
}
|
600
|
-
});
|
601
|
-
},
|
602
|
-
getGoogleAnalyticsName: userCacheName => {
|
603
|
-
return userCacheName || _createCacheName(_cacheNameDetails.googleAnalytics);
|
604
|
-
},
|
605
|
-
getPrecacheName: userCacheName => {
|
606
|
-
return userCacheName || _createCacheName(_cacheNameDetails.precache);
|
607
|
-
},
|
608
|
-
getPrefix: () => {
|
609
|
-
return _cacheNameDetails.prefix;
|
610
|
-
},
|
611
|
-
getRuntimeName: userCacheName => {
|
612
|
-
return userCacheName || _createCacheName(_cacheNameDetails.runtime);
|
613
|
-
},
|
614
|
-
getSuffix: () => {
|
615
|
-
return _cacheNameDetails.suffix;
|
616
|
-
}
|
617
|
-
};
|
618
|
-
|
619
|
-
/*
|
620
|
-
Copyright 2018 Google LLC
|
621
|
-
|
622
|
-
Use of this source code is governed by an MIT-style
|
623
|
-
license that can be found in the LICENSE file or at
|
624
|
-
https://opensource.org/licenses/MIT.
|
625
|
-
*/
|
626
|
-
|
627
|
-
const getFriendlyURL = url => {
|
628
|
-
const urlObj = new URL(url, location);
|
629
|
-
|
630
|
-
if (urlObj.origin === location.origin) {
|
631
|
-
return urlObj.pathname;
|
632
|
-
}
|
633
|
-
|
634
|
-
return urlObj.href;
|
635
|
-
};
|
636
|
-
|
637
|
-
/*
|
638
|
-
Copyright 2018 Google LLC
|
639
|
-
|
640
|
-
Use of this source code is governed by an MIT-style
|
641
|
-
license that can be found in the LICENSE file or at
|
642
|
-
https://opensource.org/licenses/MIT.
|
643
|
-
*/
|
644
|
-
/**
|
645
|
-
* Runs all of the callback functions, one at a time sequentially, in the order
|
646
|
-
* in which they were registered.
|
647
|
-
*
|
648
|
-
* @memberof workbox.core
|
649
|
-
* @private
|
650
|
-
*/
|
651
|
-
|
652
|
-
async function executeQuotaErrorCallbacks() {
|
653
|
-
{
|
654
|
-
logger.log(`About to run ${quotaErrorCallbacks.size} ` + `callbacks to clean up caches.`);
|
655
|
-
}
|
656
|
-
|
657
|
-
for (const callback of quotaErrorCallbacks) {
|
658
|
-
await callback();
|
659
|
-
|
660
|
-
{
|
661
|
-
logger.log(callback, 'is complete.');
|
662
|
-
}
|
663
|
-
}
|
664
|
-
|
665
|
-
{
|
666
|
-
logger.log('Finished running callbacks.');
|
667
|
-
}
|
668
|
-
}
|
669
|
-
|
670
|
-
/*
|
671
|
-
Copyright 2018 Google LLC
|
672
|
-
|
673
|
-
Use of this source code is governed by an MIT-style
|
674
|
-
license that can be found in the LICENSE file or at
|
675
|
-
https://opensource.org/licenses/MIT.
|
676
|
-
*/
|
677
|
-
const pluginEvents = {
|
678
|
-
CACHE_DID_UPDATE: 'cacheDidUpdate',
|
679
|
-
CACHE_KEY_WILL_BE_USED: 'cacheKeyWillBeUsed',
|
680
|
-
CACHE_WILL_UPDATE: 'cacheWillUpdate',
|
681
|
-
CACHED_RESPONSE_WILL_BE_USED: 'cachedResponseWillBeUsed',
|
682
|
-
FETCH_DID_FAIL: 'fetchDidFail',
|
683
|
-
FETCH_DID_SUCCEED: 'fetchDidSucceed',
|
684
|
-
REQUEST_WILL_FETCH: 'requestWillFetch'
|
685
|
-
};
|
686
|
-
|
687
|
-
/*
|
688
|
-
Copyright 2018 Google LLC
|
689
|
-
|
690
|
-
Use of this source code is governed by an MIT-style
|
691
|
-
license that can be found in the LICENSE file or at
|
692
|
-
https://opensource.org/licenses/MIT.
|
693
|
-
*/
|
694
|
-
const pluginUtils = {
|
695
|
-
filter: (plugins, callbackName) => {
|
696
|
-
return plugins.filter(plugin => callbackName in plugin);
|
697
|
-
}
|
698
|
-
};
|
699
|
-
|
700
|
-
/*
|
701
|
-
Copyright 2018 Google LLC
|
702
|
-
|
703
|
-
Use of this source code is governed by an MIT-style
|
704
|
-
license that can be found in the LICENSE file or at
|
705
|
-
https://opensource.org/licenses/MIT.
|
706
|
-
*/
|
707
|
-
/**
|
708
|
-
* Wrapper around cache.put().
|
709
|
-
*
|
710
|
-
* Will call `cacheDidUpdate` on plugins if the cache was updated, using
|
711
|
-
* `matchOptions` when determining what the old entry is.
|
712
|
-
*
|
713
|
-
* @param {Object} options
|
714
|
-
* @param {string} options.cacheName
|
715
|
-
* @param {Request} options.request
|
716
|
-
* @param {Response} options.response
|
717
|
-
* @param {Event} [options.event]
|
718
|
-
* @param {Array<Object>} [options.plugins=[]]
|
719
|
-
* @param {Object} [options.matchOptions]
|
720
|
-
*
|
721
|
-
* @private
|
722
|
-
* @memberof module:workbox-core
|
723
|
-
*/
|
724
|
-
|
725
|
-
const putWrapper = async ({
|
726
|
-
cacheName,
|
727
|
-
request,
|
728
|
-
response,
|
729
|
-
event,
|
730
|
-
plugins = [],
|
731
|
-
matchOptions
|
732
|
-
} = {}) => {
|
733
|
-
{
|
734
|
-
if (request.method && request.method !== 'GET') {
|
735
|
-
throw new WorkboxError('attempt-to-cache-non-get-request', {
|
736
|
-
url: getFriendlyURL(request.url),
|
737
|
-
method: request.method
|
738
|
-
});
|
739
|
-
}
|
740
|
-
}
|
741
|
-
|
742
|
-
const effectiveRequest = await _getEffectiveRequest({
|
743
|
-
plugins,
|
744
|
-
request,
|
745
|
-
mode: 'write'
|
746
|
-
});
|
747
|
-
|
748
|
-
if (!response) {
|
749
|
-
{
|
750
|
-
logger.error(`Cannot cache non-existent response for ` + `'${getFriendlyURL(effectiveRequest.url)}'.`);
|
751
|
-
}
|
752
|
-
|
753
|
-
throw new WorkboxError('cache-put-with-no-response', {
|
754
|
-
url: getFriendlyURL(effectiveRequest.url)
|
755
|
-
});
|
756
|
-
}
|
757
|
-
|
758
|
-
let responseToCache = await _isResponseSafeToCache({
|
759
|
-
event,
|
760
|
-
plugins,
|
761
|
-
response,
|
762
|
-
request: effectiveRequest
|
763
|
-
});
|
764
|
-
|
765
|
-
if (!responseToCache) {
|
766
|
-
{
|
767
|
-
logger.debug(`Response '${getFriendlyURL(effectiveRequest.url)}' will ` + `not be cached.`, responseToCache);
|
768
|
-
}
|
769
|
-
|
770
|
-
return;
|
771
|
-
}
|
772
|
-
|
773
|
-
const cache = await caches.open(cacheName);
|
774
|
-
const updatePlugins = pluginUtils.filter(plugins, pluginEvents.CACHE_DID_UPDATE);
|
775
|
-
let oldResponse = updatePlugins.length > 0 ? await matchWrapper({
|
776
|
-
cacheName,
|
777
|
-
matchOptions,
|
778
|
-
request: effectiveRequest
|
779
|
-
}) : null;
|
780
|
-
|
781
|
-
{
|
782
|
-
logger.debug(`Updating the '${cacheName}' cache with a new Response for ` + `${getFriendlyURL(effectiveRequest.url)}.`);
|
783
|
-
}
|
784
|
-
|
785
|
-
try {
|
786
|
-
await cache.put(effectiveRequest, responseToCache);
|
787
|
-
} catch (error) {
|
788
|
-
// See https://developer.mozilla.org/en-US/docs/Web/API/DOMException#exception-QuotaExceededError
|
789
|
-
if (error.name === 'QuotaExceededError') {
|
790
|
-
await executeQuotaErrorCallbacks();
|
791
|
-
}
|
792
|
-
|
793
|
-
throw error;
|
794
|
-
}
|
795
|
-
|
796
|
-
for (let plugin of updatePlugins) {
|
797
|
-
await plugin[pluginEvents.CACHE_DID_UPDATE].call(plugin, {
|
798
|
-
cacheName,
|
799
|
-
event,
|
800
|
-
oldResponse,
|
801
|
-
newResponse: responseToCache,
|
802
|
-
request: effectiveRequest
|
803
|
-
});
|
804
|
-
}
|
805
|
-
};
|
806
|
-
/**
|
807
|
-
* This is a wrapper around cache.match().
|
808
|
-
*
|
809
|
-
* @param {Object} options
|
810
|
-
* @param {string} options.cacheName Name of the cache to match against.
|
811
|
-
* @param {Request} options.request The Request that will be used to look up
|
812
|
-
* cache entries.
|
813
|
-
* @param {Event} [options.event] The event that propted the action.
|
814
|
-
* @param {Object} [options.matchOptions] Options passed to cache.match().
|
815
|
-
* @param {Array<Object>} [options.plugins=[]] Array of plugins.
|
816
|
-
* @return {Response} A cached response if available.
|
817
|
-
*
|
818
|
-
* @private
|
819
|
-
* @memberof module:workbox-core
|
820
|
-
*/
|
821
|
-
|
822
|
-
|
823
|
-
const matchWrapper = async ({
|
824
|
-
cacheName,
|
825
|
-
request,
|
826
|
-
event,
|
827
|
-
matchOptions,
|
828
|
-
plugins = []
|
829
|
-
}) => {
|
830
|
-
const cache = await caches.open(cacheName);
|
831
|
-
const effectiveRequest = await _getEffectiveRequest({
|
832
|
-
plugins,
|
833
|
-
request,
|
834
|
-
mode: 'read'
|
835
|
-
});
|
836
|
-
let cachedResponse = await cache.match(effectiveRequest, matchOptions);
|
837
|
-
|
838
|
-
{
|
839
|
-
if (cachedResponse) {
|
840
|
-
logger.debug(`Found a cached response in '${cacheName}'.`);
|
841
|
-
} else {
|
842
|
-
logger.debug(`No cached response found in '${cacheName}'.`);
|
843
|
-
}
|
844
|
-
}
|
845
|
-
|
846
|
-
for (const plugin of plugins) {
|
847
|
-
if (pluginEvents.CACHED_RESPONSE_WILL_BE_USED in plugin) {
|
848
|
-
cachedResponse = await plugin[pluginEvents.CACHED_RESPONSE_WILL_BE_USED].call(plugin, {
|
849
|
-
cacheName,
|
850
|
-
event,
|
851
|
-
matchOptions,
|
852
|
-
cachedResponse,
|
853
|
-
request: effectiveRequest
|
854
|
-
});
|
855
|
-
|
856
|
-
{
|
857
|
-
if (cachedResponse) {
|
858
|
-
finalAssertExports.isInstance(cachedResponse, Response, {
|
859
|
-
moduleName: 'Plugin',
|
860
|
-
funcName: pluginEvents.CACHED_RESPONSE_WILL_BE_USED,
|
861
|
-
isReturnValueProblem: true
|
862
|
-
});
|
863
|
-
}
|
864
|
-
}
|
865
|
-
}
|
866
|
-
}
|
867
|
-
|
868
|
-
return cachedResponse;
|
869
|
-
};
|
870
|
-
/**
|
871
|
-
* This method will call cacheWillUpdate on the available plugins (or use
|
872
|
-
* status === 200) to determine if the Response is safe and valid to cache.
|
873
|
-
*
|
874
|
-
* @param {Object} options
|
875
|
-
* @param {Request} options.request
|
876
|
-
* @param {Response} options.response
|
877
|
-
* @param {Event} [options.event]
|
878
|
-
* @param {Array<Object>} [options.plugins=[]]
|
879
|
-
* @return {Promise<Response>}
|
880
|
-
*
|
881
|
-
* @private
|
882
|
-
* @memberof module:workbox-core
|
883
|
-
*/
|
884
|
-
|
885
|
-
|
886
|
-
const _isResponseSafeToCache = async ({
|
887
|
-
request,
|
888
|
-
response,
|
889
|
-
event,
|
890
|
-
plugins
|
891
|
-
}) => {
|
892
|
-
let responseToCache = response;
|
893
|
-
let pluginsUsed = false;
|
894
|
-
|
895
|
-
for (let plugin of plugins) {
|
896
|
-
if (pluginEvents.CACHE_WILL_UPDATE in plugin) {
|
897
|
-
pluginsUsed = true;
|
898
|
-
responseToCache = await plugin[pluginEvents.CACHE_WILL_UPDATE].call(plugin, {
|
899
|
-
request,
|
900
|
-
response: responseToCache,
|
901
|
-
event
|
902
|
-
});
|
903
|
-
|
904
|
-
{
|
905
|
-
if (responseToCache) {
|
906
|
-
finalAssertExports.isInstance(responseToCache, Response, {
|
907
|
-
moduleName: 'Plugin',
|
908
|
-
funcName: pluginEvents.CACHE_WILL_UPDATE,
|
909
|
-
isReturnValueProblem: true
|
910
|
-
});
|
911
|
-
}
|
912
|
-
}
|
913
|
-
|
914
|
-
if (!responseToCache) {
|
915
|
-
break;
|
916
|
-
}
|
917
|
-
}
|
918
|
-
}
|
919
|
-
|
920
|
-
if (!pluginsUsed) {
|
921
|
-
{
|
922
|
-
if (!responseToCache.status === 200) {
|
923
|
-
if (responseToCache.status === 0) {
|
924
|
-
logger.warn(`The response for '${request.url}' is an opaque ` + `response. The caching strategy that you're using will not ` + `cache opaque responses by default.`);
|
925
|
-
} else {
|
926
|
-
logger.debug(`The response for '${request.url}' returned ` + `a status code of '${response.status}' and won't be cached as a ` + `result.`);
|
927
|
-
}
|
928
|
-
}
|
929
|
-
}
|
930
|
-
|
931
|
-
responseToCache = responseToCache.status === 200 ? responseToCache : null;
|
932
|
-
}
|
933
|
-
|
934
|
-
return responseToCache ? responseToCache : null;
|
935
|
-
};
|
936
|
-
/**
|
937
|
-
* Checks the list of plugins for the cacheKeyWillBeUsed callback, and
|
938
|
-
* executes any of those callbacks found in sequence. The final `Request` object
|
939
|
-
* returned by the last plugin is treated as the cache key for cache reads
|
940
|
-
* and/or writes.
|
941
|
-
*
|
942
|
-
* @param {Object} options
|
943
|
-
* @param {Request} options.request
|
944
|
-
* @param {string} options.mode
|
945
|
-
* @param {Array<Object>} [options.plugins=[]]
|
946
|
-
* @return {Promise<Request>}
|
947
|
-
*
|
948
|
-
* @private
|
949
|
-
* @memberof module:workbox-core
|
950
|
-
*/
|
951
|
-
|
952
|
-
|
953
|
-
const _getEffectiveRequest = async ({
|
954
|
-
request,
|
955
|
-
mode,
|
956
|
-
plugins
|
957
|
-
}) => {
|
958
|
-
const cacheKeyWillBeUsedPlugins = pluginUtils.filter(plugins, pluginEvents.CACHE_KEY_WILL_BE_USED);
|
959
|
-
let effectiveRequest = request;
|
960
|
-
|
961
|
-
for (const plugin of cacheKeyWillBeUsedPlugins) {
|
962
|
-
effectiveRequest = await plugin[pluginEvents.CACHE_KEY_WILL_BE_USED].call(plugin, {
|
963
|
-
mode,
|
964
|
-
request: effectiveRequest
|
965
|
-
});
|
966
|
-
|
967
|
-
if (typeof effectiveRequest === 'string') {
|
968
|
-
effectiveRequest = new Request(effectiveRequest);
|
969
|
-
}
|
970
|
-
|
971
|
-
{
|
972
|
-
finalAssertExports.isInstance(effectiveRequest, Request, {
|
973
|
-
moduleName: 'Plugin',
|
974
|
-
funcName: pluginEvents.CACHE_KEY_WILL_BE_USED,
|
975
|
-
isReturnValueProblem: true
|
976
|
-
});
|
977
|
-
}
|
978
|
-
}
|
979
|
-
|
980
|
-
return effectiveRequest;
|
981
|
-
};
|
982
|
-
|
983
|
-
const cacheWrapper = {
|
984
|
-
put: putWrapper,
|
985
|
-
match: matchWrapper
|
986
|
-
};
|
987
|
-
|
988
|
-
/*
|
989
|
-
Copyright 2018 Google LLC
|
990
|
-
|
991
|
-
Use of this source code is governed by an MIT-style
|
992
|
-
license that can be found in the LICENSE file or at
|
993
|
-
https://opensource.org/licenses/MIT.
|
994
|
-
*/
|
995
|
-
/**
|
996
|
-
* A class that wraps common IndexedDB functionality in a promise-based API.
|
997
|
-
* It exposes all the underlying power and functionality of IndexedDB, but
|
998
|
-
* wraps the most commonly used features in a way that's much simpler to use.
|
999
|
-
*
|
1000
|
-
* @private
|
1001
|
-
*/
|
1002
|
-
|
1003
|
-
class DBWrapper {
|
1004
|
-
/**
|
1005
|
-
* @param {string} name
|
1006
|
-
* @param {number} version
|
1007
|
-
* @param {Object=} [callback]
|
1008
|
-
* @param {!Function} [callbacks.onupgradeneeded]
|
1009
|
-
* @param {!Function} [callbacks.onversionchange] Defaults to
|
1010
|
-
* DBWrapper.prototype._onversionchange when not specified.
|
1011
|
-
* @private
|
1012
|
-
*/
|
1013
|
-
constructor(name, version, {
|
1014
|
-
onupgradeneeded,
|
1015
|
-
onversionchange = this._onversionchange
|
1016
|
-
} = {}) {
|
1017
|
-
this._name = name;
|
1018
|
-
this._version = version;
|
1019
|
-
this._onupgradeneeded = onupgradeneeded;
|
1020
|
-
this._onversionchange = onversionchange; // If this is null, it means the database isn't open.
|
1021
|
-
|
1022
|
-
this._db = null;
|
1023
|
-
}
|
1024
|
-
/**
|
1025
|
-
* Returns the IDBDatabase instance (not normally needed).
|
1026
|
-
*
|
1027
|
-
* @private
|
1028
|
-
*/
|
1029
|
-
|
1030
|
-
|
1031
|
-
get db() {
|
1032
|
-
return this._db;
|
1033
|
-
}
|
1034
|
-
/**
|
1035
|
-
* Opens a connected to an IDBDatabase, invokes any onupgradedneeded
|
1036
|
-
* callback, and added an onversionchange callback to the database.
|
1037
|
-
*
|
1038
|
-
* @return {IDBDatabase}
|
1039
|
-
* @private
|
1040
|
-
*/
|
1041
|
-
|
1042
|
-
|
1043
|
-
async open() {
|
1044
|
-
if (this._db) return;
|
1045
|
-
this._db = await new Promise((resolve, reject) => {
|
1046
|
-
// This flag is flipped to true if the timeout callback runs prior
|
1047
|
-
// to the request failing or succeeding. Note: we use a timeout instead
|
1048
|
-
// of an onblocked handler since there are cases where onblocked will
|
1049
|
-
// never never run. A timeout better handles all possible scenarios:
|
1050
|
-
// https://github.com/w3c/IndexedDB/issues/223
|
1051
|
-
let openRequestTimedOut = false;
|
1052
|
-
setTimeout(() => {
|
1053
|
-
openRequestTimedOut = true;
|
1054
|
-
reject(new Error('The open request was blocked and timed out'));
|
1055
|
-
}, this.OPEN_TIMEOUT);
|
1056
|
-
const openRequest = indexedDB.open(this._name, this._version);
|
1057
|
-
|
1058
|
-
openRequest.onerror = () => reject(openRequest.error);
|
1059
|
-
|
1060
|
-
openRequest.onupgradeneeded = evt => {
|
1061
|
-
if (openRequestTimedOut) {
|
1062
|
-
openRequest.transaction.abort();
|
1063
|
-
evt.target.result.close();
|
1064
|
-
} else if (this._onupgradeneeded) {
|
1065
|
-
this._onupgradeneeded(evt);
|
1066
|
-
}
|
1067
|
-
};
|
1068
|
-
|
1069
|
-
openRequest.onsuccess = ({
|
1070
|
-
target
|
1071
|
-
}) => {
|
1072
|
-
const db = target.result;
|
1073
|
-
|
1074
|
-
if (openRequestTimedOut) {
|
1075
|
-
db.close();
|
1076
|
-
} else {
|
1077
|
-
db.onversionchange = this._onversionchange.bind(this);
|
1078
|
-
resolve(db);
|
1079
|
-
}
|
1080
|
-
};
|
1081
|
-
});
|
1082
|
-
return this;
|
1083
|
-
}
|
1084
|
-
/**
|
1085
|
-
* Polyfills the native `getKey()` method. Note, this is overridden at
|
1086
|
-
* runtime if the browser supports the native method.
|
1087
|
-
*
|
1088
|
-
* @param {string} storeName
|
1089
|
-
* @param {*} query
|
1090
|
-
* @return {Array}
|
1091
|
-
* @private
|
1092
|
-
*/
|
1093
|
-
|
1094
|
-
|
1095
|
-
async getKey(storeName, query) {
|
1096
|
-
return (await this.getAllKeys(storeName, query, 1))[0];
|
1097
|
-
}
|
1098
|
-
/**
|
1099
|
-
* Polyfills the native `getAll()` method. Note, this is overridden at
|
1100
|
-
* runtime if the browser supports the native method.
|
1101
|
-
*
|
1102
|
-
* @param {string} storeName
|
1103
|
-
* @param {*} query
|
1104
|
-
* @param {number} count
|
1105
|
-
* @return {Array}
|
1106
|
-
* @private
|
1107
|
-
*/
|
1108
|
-
|
1109
|
-
|
1110
|
-
async getAll(storeName, query, count) {
|
1111
|
-
return await this.getAllMatching(storeName, {
|
1112
|
-
query,
|
1113
|
-
count
|
1114
|
-
});
|
1115
|
-
}
|
1116
|
-
/**
|
1117
|
-
* Polyfills the native `getAllKeys()` method. Note, this is overridden at
|
1118
|
-
* runtime if the browser supports the native method.
|
1119
|
-
*
|
1120
|
-
* @param {string} storeName
|
1121
|
-
* @param {*} query
|
1122
|
-
* @param {number} count
|
1123
|
-
* @return {Array}
|
1124
|
-
* @private
|
1125
|
-
*/
|
1126
|
-
|
1127
|
-
|
1128
|
-
async getAllKeys(storeName, query, count) {
|
1129
|
-
return (await this.getAllMatching(storeName, {
|
1130
|
-
query,
|
1131
|
-
count,
|
1132
|
-
includeKeys: true
|
1133
|
-
})).map(({
|
1134
|
-
key
|
1135
|
-
}) => key);
|
1136
|
-
}
|
1137
|
-
/**
|
1138
|
-
* Supports flexible lookup in an object store by specifying an index,
|
1139
|
-
* query, direction, and count. This method returns an array of objects
|
1140
|
-
* with the signature .
|
1141
|
-
*
|
1142
|
-
* @param {string} storeName
|
1143
|
-
* @param {Object} [opts]
|
1144
|
-
* @param {string} [opts.index] The index to use (if specified).
|
1145
|
-
* @param {*} [opts.query]
|
1146
|
-
* @param {IDBCursorDirection} [opts.direction]
|
1147
|
-
* @param {number} [opts.count] The max number of results to return.
|
1148
|
-
* @param {boolean} [opts.includeKeys] When true, the structure of the
|
1149
|
-
* returned objects is changed from an array of values to an array of
|
1150
|
-
* objects in the form {key, primaryKey, value}.
|
1151
|
-
* @return {Array}
|
1152
|
-
* @private
|
1153
|
-
*/
|
1154
|
-
|
1155
|
-
|
1156
|
-
async getAllMatching(storeName, {
|
1157
|
-
index,
|
1158
|
-
query = null,
|
1159
|
-
// IE errors if query === `undefined`.
|
1160
|
-
direction = 'next',
|
1161
|
-
count,
|
1162
|
-
includeKeys
|
1163
|
-
} = {}) {
|
1164
|
-
return await this.transaction([storeName], 'readonly', (txn, done) => {
|
1165
|
-
const store = txn.objectStore(storeName);
|
1166
|
-
const target = index ? store.index(index) : store;
|
1167
|
-
const results = [];
|
1168
|
-
|
1169
|
-
target.openCursor(query, direction).onsuccess = ({
|
1170
|
-
target
|
1171
|
-
}) => {
|
1172
|
-
const cursor = target.result;
|
1173
|
-
|
1174
|
-
if (cursor) {
|
1175
|
-
const {
|
1176
|
-
primaryKey,
|
1177
|
-
key,
|
1178
|
-
value
|
1179
|
-
} = cursor;
|
1180
|
-
results.push(includeKeys ? {
|
1181
|
-
primaryKey,
|
1182
|
-
key,
|
1183
|
-
value
|
1184
|
-
} : value);
|
1185
|
-
|
1186
|
-
if (count && results.length >= count) {
|
1187
|
-
done(results);
|
1188
|
-
} else {
|
1189
|
-
cursor.continue();
|
1190
|
-
}
|
1191
|
-
} else {
|
1192
|
-
done(results);
|
1193
|
-
}
|
1194
|
-
};
|
1195
|
-
});
|
1196
|
-
}
|
1197
|
-
/**
|
1198
|
-
* Accepts a list of stores, a transaction type, and a callback and
|
1199
|
-
* performs a transaction. A promise is returned that resolves to whatever
|
1200
|
-
* value the callback chooses. The callback holds all the transaction logic
|
1201
|
-
* and is invoked with two arguments:
|
1202
|
-
* 1. The IDBTransaction object
|
1203
|
-
* 2. A `done` function, that's used to resolve the promise when
|
1204
|
-
* when the transaction is done, if passed a value, the promise is
|
1205
|
-
* resolved to that value.
|
1206
|
-
*
|
1207
|
-
* @param {Array<string>} storeNames An array of object store names
|
1208
|
-
* involved in the transaction.
|
1209
|
-
* @param {string} type Can be `readonly` or `readwrite`.
|
1210
|
-
* @param {!Function} callback
|
1211
|
-
* @return {*} The result of the transaction ran by the callback.
|
1212
|
-
* @private
|
1213
|
-
*/
|
1214
|
-
|
1215
|
-
|
1216
|
-
async transaction(storeNames, type, callback) {
|
1217
|
-
await this.open();
|
1218
|
-
return await new Promise((resolve, reject) => {
|
1219
|
-
const txn = this._db.transaction(storeNames, type);
|
1220
|
-
|
1221
|
-
txn.onabort = ({
|
1222
|
-
target
|
1223
|
-
}) => reject(target.error);
|
1224
|
-
|
1225
|
-
txn.oncomplete = () => resolve();
|
1226
|
-
|
1227
|
-
callback(txn, value => resolve(value));
|
1228
|
-
});
|
1229
|
-
}
|
1230
|
-
/**
|
1231
|
-
* Delegates async to a native IDBObjectStore method.
|
1232
|
-
*
|
1233
|
-
* @param {string} method The method name.
|
1234
|
-
* @param {string} storeName The object store name.
|
1235
|
-
* @param {string} type Can be `readonly` or `readwrite`.
|
1236
|
-
* @param {...*} args The list of args to pass to the native method.
|
1237
|
-
* @return {*} The result of the transaction.
|
1238
|
-
* @private
|
1239
|
-
*/
|
1240
|
-
|
1241
|
-
|
1242
|
-
async _call(method, storeName, type, ...args) {
|
1243
|
-
const callback = (txn, done) => {
|
1244
|
-
txn.objectStore(storeName)[method](...args).onsuccess = ({
|
1245
|
-
target
|
1246
|
-
}) => {
|
1247
|
-
done(target.result);
|
1248
|
-
};
|
1249
|
-
};
|
1250
|
-
|
1251
|
-
return await this.transaction([storeName], type, callback);
|
1252
|
-
}
|
1253
|
-
/**
|
1254
|
-
* The default onversionchange handler, which closes the database so other
|
1255
|
-
* connections can open without being blocked.
|
1256
|
-
*
|
1257
|
-
* @private
|
1258
|
-
*/
|
1259
|
-
|
1260
|
-
|
1261
|
-
_onversionchange() {
|
1262
|
-
this.close();
|
1263
|
-
}
|
1264
|
-
/**
|
1265
|
-
* Closes the connection opened by `DBWrapper.open()`. Generally this method
|
1266
|
-
* doesn't need to be called since:
|
1267
|
-
* 1. It's usually better to keep a connection open since opening
|
1268
|
-
* a new connection is somewhat slow.
|
1269
|
-
* 2. Connections are automatically closed when the reference is
|
1270
|
-
* garbage collected.
|
1271
|
-
* The primary use case for needing to close a connection is when another
|
1272
|
-
* reference (typically in another tab) needs to upgrade it and would be
|
1273
|
-
* blocked by the current, open connection.
|
1274
|
-
*
|
1275
|
-
* @private
|
1276
|
-
*/
|
1277
|
-
|
1278
|
-
|
1279
|
-
close() {
|
1280
|
-
if (this._db) {
|
1281
|
-
this._db.close();
|
1282
|
-
|
1283
|
-
this._db = null;
|
1284
|
-
}
|
1285
|
-
}
|
1286
|
-
|
1287
|
-
} // Exposed to let users modify the default timeout on a per-instance
|
1288
|
-
// or global basis.
|
1289
|
-
|
1290
|
-
DBWrapper.prototype.OPEN_TIMEOUT = 2000; // Wrap native IDBObjectStore methods according to their mode.
|
1291
|
-
|
1292
|
-
const methodsToWrap = {
|
1293
|
-
'readonly': ['get', 'count', 'getKey', 'getAll', 'getAllKeys'],
|
1294
|
-
'readwrite': ['add', 'put', 'clear', 'delete']
|
1295
|
-
};
|
1296
|
-
|
1297
|
-
for (const [mode, methods] of Object.entries(methodsToWrap)) {
|
1298
|
-
for (const method of methods) {
|
1299
|
-
if (method in IDBObjectStore.prototype) {
|
1300
|
-
// Don't use arrow functions here since we're outside of the class.
|
1301
|
-
DBWrapper.prototype[method] = async function (storeName, ...args) {
|
1302
|
-
return await this._call(method, storeName, mode, ...args);
|
1303
|
-
};
|
1304
|
-
}
|
1305
|
-
}
|
1306
|
-
}
|
1307
|
-
|
1308
|
-
/*
|
1309
|
-
Copyright 2018 Google LLC
|
1310
|
-
|
1311
|
-
Use of this source code is governed by an MIT-style
|
1312
|
-
license that can be found in the LICENSE file or at
|
1313
|
-
https://opensource.org/licenses/MIT.
|
1314
|
-
*/
|
1315
|
-
/**
|
1316
|
-
* The Deferred class composes Promises in a way that allows for them to be
|
1317
|
-
* resolved or rejected from outside the constructor. In most cases promises
|
1318
|
-
* should be used directly, but Deferreds can be necessary when the logic to
|
1319
|
-
* resolve a promise must be separate.
|
1320
|
-
*
|
1321
|
-
* @private
|
1322
|
-
*/
|
1323
|
-
|
1324
|
-
class Deferred {
|
1325
|
-
/**
|
1326
|
-
* Creates a promise and exposes its resolve and reject functions as methods.
|
1327
|
-
*/
|
1328
|
-
constructor() {
|
1329
|
-
this.promise = new Promise((resolve, reject) => {
|
1330
|
-
this.resolve = resolve;
|
1331
|
-
this.reject = reject;
|
1332
|
-
});
|
1333
|
-
}
|
1334
|
-
|
1335
|
-
}
|
1336
|
-
|
1337
|
-
/*
|
1338
|
-
Copyright 2018 Google LLC
|
1339
|
-
|
1340
|
-
Use of this source code is governed by an MIT-style
|
1341
|
-
license that can be found in the LICENSE file or at
|
1342
|
-
https://opensource.org/licenses/MIT.
|
1343
|
-
*/
|
1344
|
-
/**
|
1345
|
-
* Deletes the database.
|
1346
|
-
* Note: this is exported separately from the DBWrapper module because most
|
1347
|
-
* usages of IndexedDB in workbox dont need deleting, and this way it can be
|
1348
|
-
* reused in tests to delete databases without creating DBWrapper instances.
|
1349
|
-
*
|
1350
|
-
* @param {string} name The database name.
|
1351
|
-
* @private
|
1352
|
-
*/
|
1353
|
-
|
1354
|
-
const deleteDatabase = async name => {
|
1355
|
-
await new Promise((resolve, reject) => {
|
1356
|
-
const request = indexedDB.deleteDatabase(name);
|
1357
|
-
|
1358
|
-
request.onerror = ({
|
1359
|
-
target
|
1360
|
-
}) => {
|
1361
|
-
reject(target.error);
|
1362
|
-
};
|
1363
|
-
|
1364
|
-
request.onblocked = () => {
|
1365
|
-
reject(new Error('Delete blocked'));
|
1366
|
-
};
|
1367
|
-
|
1368
|
-
request.onsuccess = () => {
|
1369
|
-
resolve();
|
1370
|
-
};
|
1371
|
-
});
|
1372
|
-
};
|
1373
|
-
|
1374
|
-
/*
|
1375
|
-
Copyright 2018 Google LLC
|
1376
|
-
|
1377
|
-
Use of this source code is governed by an MIT-style
|
1378
|
-
license that can be found in the LICENSE file or at
|
1379
|
-
https://opensource.org/licenses/MIT.
|
1380
|
-
*/
|
1381
|
-
/**
|
1382
|
-
* Wrapper around the fetch API.
|
1383
|
-
*
|
1384
|
-
* Will call requestWillFetch on available plugins.
|
1385
|
-
*
|
1386
|
-
* @param {Object} options
|
1387
|
-
* @param {Request|string} options.request
|
1388
|
-
* @param {Object} [options.fetchOptions]
|
1389
|
-
* @param {Event} [options.event]
|
1390
|
-
* @param {Array<Object>} [options.plugins=[]]
|
1391
|
-
* @return {Promise<Response>}
|
1392
|
-
*
|
1393
|
-
* @private
|
1394
|
-
* @memberof module:workbox-core
|
1395
|
-
*/
|
1396
|
-
|
1397
|
-
const wrappedFetch = async ({
|
1398
|
-
request,
|
1399
|
-
fetchOptions,
|
1400
|
-
event,
|
1401
|
-
plugins = []
|
1402
|
-
}) => {
|
1403
|
-
// We *should* be able to call `await event.preloadResponse` even if it's
|
1404
|
-
// undefined, but for some reason, doing so leads to errors in our Node unit
|
1405
|
-
// tests. To work around that, explicitly check preloadResponse's value first.
|
1406
|
-
if (event && event.preloadResponse) {
|
1407
|
-
const possiblePreloadResponse = await event.preloadResponse;
|
1408
|
-
|
1409
|
-
if (possiblePreloadResponse) {
|
1410
|
-
{
|
1411
|
-
logger.log(`Using a preloaded navigation response for ` + `'${getFriendlyURL(request.url)}'`);
|
1412
|
-
}
|
1413
|
-
|
1414
|
-
return possiblePreloadResponse;
|
1415
|
-
}
|
1416
|
-
}
|
1417
|
-
|
1418
|
-
if (typeof request === 'string') {
|
1419
|
-
request = new Request(request);
|
1420
|
-
}
|
1421
|
-
|
1422
|
-
{
|
1423
|
-
finalAssertExports.isInstance(request, Request, {
|
1424
|
-
paramName: request,
|
1425
|
-
expectedClass: 'Request',
|
1426
|
-
moduleName: 'workbox-core',
|
1427
|
-
className: 'fetchWrapper',
|
1428
|
-
funcName: 'wrappedFetch'
|
1429
|
-
});
|
1430
|
-
}
|
1431
|
-
|
1432
|
-
const failedFetchPlugins = pluginUtils.filter(plugins, pluginEvents.FETCH_DID_FAIL); // If there is a fetchDidFail plugin, we need to save a clone of the
|
1433
|
-
// original request before it's either modified by a requestWillFetch
|
1434
|
-
// plugin or before the original request's body is consumed via fetch().
|
1435
|
-
|
1436
|
-
const originalRequest = failedFetchPlugins.length > 0 ? request.clone() : null;
|
1437
|
-
|
1438
|
-
try {
|
1439
|
-
for (let plugin of plugins) {
|
1440
|
-
if (pluginEvents.REQUEST_WILL_FETCH in plugin) {
|
1441
|
-
request = await plugin[pluginEvents.REQUEST_WILL_FETCH].call(plugin, {
|
1442
|
-
request: request.clone(),
|
1443
|
-
event
|
1444
|
-
});
|
1445
|
-
|
1446
|
-
{
|
1447
|
-
if (request) {
|
1448
|
-
finalAssertExports.isInstance(request, Request, {
|
1449
|
-
moduleName: 'Plugin',
|
1450
|
-
funcName: pluginEvents.CACHED_RESPONSE_WILL_BE_USED,
|
1451
|
-
isReturnValueProblem: true
|
1452
|
-
});
|
1453
|
-
}
|
1454
|
-
}
|
1455
|
-
}
|
1456
|
-
}
|
1457
|
-
} catch (err) {
|
1458
|
-
throw new WorkboxError('plugin-error-request-will-fetch', {
|
1459
|
-
thrownError: err
|
1460
|
-
});
|
1461
|
-
} // The request can be altered by plugins with `requestWillFetch` making
|
1462
|
-
// the original request (Most likely from a `fetch` event) to be different
|
1463
|
-
// to the Request we make. Pass both to `fetchDidFail` to aid debugging.
|
1464
|
-
|
1465
|
-
|
1466
|
-
let pluginFilteredRequest = request.clone();
|
1467
|
-
|
1468
|
-
try {
|
1469
|
-
let fetchResponse; // See https://github.com/GoogleChrome/workbox/issues/1796
|
1470
|
-
|
1471
|
-
if (request.mode === 'navigate') {
|
1472
|
-
fetchResponse = await fetch(request);
|
1473
|
-
} else {
|
1474
|
-
fetchResponse = await fetch(request, fetchOptions);
|
1475
|
-
}
|
1476
|
-
|
1477
|
-
{
|
1478
|
-
logger.debug(`Network request for ` + `'${getFriendlyURL(request.url)}' returned a response with ` + `status '${fetchResponse.status}'.`);
|
1479
|
-
}
|
1480
|
-
|
1481
|
-
for (const plugin of plugins) {
|
1482
|
-
if (pluginEvents.FETCH_DID_SUCCEED in plugin) {
|
1483
|
-
fetchResponse = await plugin[pluginEvents.FETCH_DID_SUCCEED].call(plugin, {
|
1484
|
-
event,
|
1485
|
-
request: pluginFilteredRequest,
|
1486
|
-
response: fetchResponse
|
1487
|
-
});
|
1488
|
-
|
1489
|
-
{
|
1490
|
-
if (fetchResponse) {
|
1491
|
-
finalAssertExports.isInstance(fetchResponse, Response, {
|
1492
|
-
moduleName: 'Plugin',
|
1493
|
-
funcName: pluginEvents.FETCH_DID_SUCCEED,
|
1494
|
-
isReturnValueProblem: true
|
1495
|
-
});
|
1496
|
-
}
|
1497
|
-
}
|
1498
|
-
}
|
1499
|
-
}
|
1500
|
-
|
1501
|
-
return fetchResponse;
|
1502
|
-
} catch (error) {
|
1503
|
-
{
|
1504
|
-
logger.error(`Network request for ` + `'${getFriendlyURL(request.url)}' threw an error.`, error);
|
1505
|
-
}
|
1506
|
-
|
1507
|
-
for (const plugin of failedFetchPlugins) {
|
1508
|
-
await plugin[pluginEvents.FETCH_DID_FAIL].call(plugin, {
|
1509
|
-
error,
|
1510
|
-
event,
|
1511
|
-
originalRequest: originalRequest.clone(),
|
1512
|
-
request: pluginFilteredRequest.clone()
|
1513
|
-
});
|
1514
|
-
}
|
1515
|
-
|
1516
|
-
throw error;
|
1517
|
-
}
|
1518
|
-
};
|
1519
|
-
|
1520
|
-
const fetchWrapper = {
|
1521
|
-
fetch: wrappedFetch
|
1522
|
-
};
|
1523
|
-
|
1524
|
-
/*
|
1525
|
-
Copyright 2018 Google LLC
|
1526
|
-
|
1527
|
-
Use of this source code is governed by an MIT-style
|
1528
|
-
license that can be found in the LICENSE file or at
|
1529
|
-
https://opensource.org/licenses/MIT.
|
1530
|
-
*/
|
1531
|
-
|
1532
|
-
var _private = /*#__PURE__*/Object.freeze({
|
1533
|
-
assert: finalAssertExports,
|
1534
|
-
cacheNames: cacheNames,
|
1535
|
-
cacheWrapper: cacheWrapper,
|
1536
|
-
DBWrapper: DBWrapper,
|
1537
|
-
Deferred: Deferred,
|
1538
|
-
deleteDatabase: deleteDatabase,
|
1539
|
-
executeQuotaErrorCallbacks: executeQuotaErrorCallbacks,
|
1540
|
-
fetchWrapper: fetchWrapper,
|
1541
|
-
getFriendlyURL: getFriendlyURL,
|
1542
|
-
logger: logger,
|
1543
|
-
WorkboxError: WorkboxError
|
1544
|
-
});
|
1545
|
-
|
1546
|
-
/*
|
1547
|
-
Copyright 2019 Google LLC
|
1548
|
-
|
1549
|
-
Use of this source code is governed by an MIT-style
|
1550
|
-
license that can be found in the LICENSE file or at
|
1551
|
-
https://opensource.org/licenses/MIT.
|
1552
|
-
*/
|
1553
|
-
/**
|
1554
|
-
* Claim any currently available clients once the service worker
|
1555
|
-
* becomes active. This is normally used in conjunction with `skipWaiting()`.
|
1556
|
-
*
|
1557
|
-
* @alias workbox.core.clientsClaim
|
1558
|
-
*/
|
1559
|
-
|
1560
|
-
const clientsClaim = () => {
|
1561
|
-
addEventListener('activate', () => clients.claim());
|
1562
|
-
};
|
1563
|
-
|
1564
|
-
/*
|
1565
|
-
Copyright 2019 Google LLC
|
1566
|
-
|
1567
|
-
Use of this source code is governed by an MIT-style
|
1568
|
-
license that can be found in the LICENSE file or at
|
1569
|
-
https://opensource.org/licenses/MIT.
|
1570
|
-
*/
|
1571
|
-
/**
|
1572
|
-
* Get the current cache names and prefix/suffix used by Workbox.
|
1573
|
-
*
|
1574
|
-
* `cacheNames.precache` is used for precached assets,
|
1575
|
-
* `cacheNames.googleAnalytics` is used by `workbox-google-analytics` to
|
1576
|
-
* store `analytics.js`, and `cacheNames.runtime` is used for everything else.
|
1577
|
-
*
|
1578
|
-
* `cacheNames.prefix` can be used to retrieve just the current prefix value.
|
1579
|
-
* `cacheNames.suffix` can be used to retrieve just the current suffix value.
|
1580
|
-
*
|
1581
|
-
* @return {Object} An object with `precache`, `runtime`, `prefix`, and
|
1582
|
-
* `googleAnalytics` properties.
|
1583
|
-
*
|
1584
|
-
* @alias workbox.core.cacheNames
|
1585
|
-
*/
|
1586
|
-
|
1587
|
-
const cacheNames$1 = {
|
1588
|
-
get googleAnalytics() {
|
1589
|
-
return cacheNames.getGoogleAnalyticsName();
|
1590
|
-
},
|
1591
|
-
|
1592
|
-
get precache() {
|
1593
|
-
return cacheNames.getPrecacheName();
|
1594
|
-
},
|
1595
|
-
|
1596
|
-
get prefix() {
|
1597
|
-
return cacheNames.getPrefix();
|
1598
|
-
},
|
1599
|
-
|
1600
|
-
get runtime() {
|
1601
|
-
return cacheNames.getRuntimeName();
|
1602
|
-
},
|
1603
|
-
|
1604
|
-
get suffix() {
|
1605
|
-
return cacheNames.getSuffix();
|
1606
|
-
}
|
1607
|
-
|
1608
|
-
};
|
1609
|
-
|
1610
|
-
/*
|
1611
|
-
Copyright 2019 Google LLC
|
1612
|
-
|
1613
|
-
Use of this source code is governed by an MIT-style
|
1614
|
-
license that can be found in the LICENSE file or at
|
1615
|
-
https://opensource.org/licenses/MIT.
|
1616
|
-
*/
|
1617
|
-
/**
|
1618
|
-
* Modifies the default cache names used by the Workbox packages.
|
1619
|
-
* Cache names are generated as `<prefix>-<Cache Name>-<suffix>`.
|
1620
|
-
*
|
1621
|
-
* @param {Object} details
|
1622
|
-
* @param {Object} [details.prefix] The string to add to the beginning of
|
1623
|
-
* the precache and runtime cache names.
|
1624
|
-
* @param {Object} [details.suffix] The string to add to the end of
|
1625
|
-
* the precache and runtime cache names.
|
1626
|
-
* @param {Object} [details.precache] The cache name to use for precache
|
1627
|
-
* caching.
|
1628
|
-
* @param {Object} [details.runtime] The cache name to use for runtime caching.
|
1629
|
-
* @param {Object} [details.googleAnalytics] The cache name to use for
|
1630
|
-
* `workbox-google-analytics` caching.
|
1631
|
-
*
|
1632
|
-
* @alias workbox.core.setCacheNameDetails
|
1633
|
-
*/
|
1634
|
-
|
1635
|
-
const setCacheNameDetails = details => {
|
1636
|
-
{
|
1637
|
-
Object.keys(details).forEach(key => {
|
1638
|
-
finalAssertExports.isType(details[key], 'string', {
|
1639
|
-
moduleName: 'workbox-core',
|
1640
|
-
funcName: 'setCacheNameDetails',
|
1641
|
-
paramName: `details.${key}`
|
1642
|
-
});
|
1643
|
-
});
|
1644
|
-
|
1645
|
-
if ('precache' in details && details.precache.length === 0) {
|
1646
|
-
throw new WorkboxError('invalid-cache-name', {
|
1647
|
-
cacheNameId: 'precache',
|
1648
|
-
value: details.precache
|
1649
|
-
});
|
1650
|
-
}
|
1651
|
-
|
1652
|
-
if ('runtime' in details && details.runtime.length === 0) {
|
1653
|
-
throw new WorkboxError('invalid-cache-name', {
|
1654
|
-
cacheNameId: 'runtime',
|
1655
|
-
value: details.runtime
|
1656
|
-
});
|
1657
|
-
}
|
1658
|
-
|
1659
|
-
if ('googleAnalytics' in details && details.googleAnalytics.length === 0) {
|
1660
|
-
throw new WorkboxError('invalid-cache-name', {
|
1661
|
-
cacheNameId: 'googleAnalytics',
|
1662
|
-
value: details.googleAnalytics
|
1663
|
-
});
|
1664
|
-
}
|
1665
|
-
}
|
1666
|
-
|
1667
|
-
cacheNames.updateDetails(details);
|
1668
|
-
};
|
1669
|
-
|
1670
|
-
/*
|
1671
|
-
Copyright 2019 Google LLC
|
1672
|
-
|
1673
|
-
Use of this source code is governed by an MIT-style
|
1674
|
-
license that can be found in the LICENSE file or at
|
1675
|
-
https://opensource.org/licenses/MIT.
|
1676
|
-
*/
|
1677
|
-
/**
|
1678
|
-
* Force a service worker to become active, instead of waiting. This is
|
1679
|
-
* normally used in conjunction with `clientsClaim()`.
|
1680
|
-
*
|
1681
|
-
* @alias workbox.core.skipWaiting
|
1682
|
-
*/
|
1683
|
-
|
1684
|
-
const skipWaiting = () => {
|
1685
|
-
// We need to explicitly call `self.skipWaiting()` here because we're
|
1686
|
-
// shadowing `skipWaiting` with this local function.
|
1687
|
-
addEventListener('install', () => self.skipWaiting());
|
1688
|
-
};
|
1689
|
-
|
1690
|
-
/*
|
1691
|
-
Copyright 2018 Google LLC
|
1692
|
-
|
1693
|
-
Use of this source code is governed by an MIT-style
|
1694
|
-
license that can be found in the LICENSE file or at
|
1695
|
-
https://opensource.org/licenses/MIT.
|
1696
|
-
*/
|
1697
|
-
|
1698
|
-
try {
|
1699
|
-
self.workbox.v = self.workbox.v || {};
|
1700
|
-
} catch (errer) {} // NOOP
|
1701
|
-
|
1702
|
-
exports._private = _private;
|
1703
|
-
exports.clientsClaim = clientsClaim;
|
1704
|
-
exports.cacheNames = cacheNames$1;
|
1705
|
-
exports.registerQuotaErrorCallback = registerQuotaErrorCallback;
|
1706
|
-
exports.setCacheNameDetails = setCacheNameDetails;
|
1707
|
-
exports.skipWaiting = skipWaiting;
|
1708
|
-
|
1709
|
-
return exports;
|
1710
|
-
|
1711
|
-
}({}));
|
1712
|
-
//# sourceMappingURL=workbox-core.dev.js.map
|