diff options
Diffstat (limited to 'public/workbox-v4.3.1/workbox-core.dev.js')
| -rw-r--r-- | public/workbox-v4.3.1/workbox-core.dev.js | 1712 |
1 files changed, 0 insertions, 1712 deletions
diff --git a/public/workbox-v4.3.1/workbox-core.dev.js b/public/workbox-v4.3.1/workbox-core.dev.js deleted file mode 100644 index 18b8b85..0000000 --- a/public/workbox-v4.3.1/workbox-core.dev.js +++ /dev/null @@ -1,1712 +0,0 @@ -this.workbox = this.workbox || {}; -this.workbox.core = (function (exports) { - 'use strict'; - - try { - self['workbox:core:4.3.1'] && _(); - } catch (e) {} // eslint-disable-line - - /* - Copyright 2019 Google LLC - Use of this source code is governed by an MIT-style - license that can be found in the LICENSE file or at - https://opensource.org/licenses/MIT. - */ - const logger = (() => { - let inGroup = false; - const methodToColorMap = { - debug: `#7f8c8d`, - // Gray - log: `#2ecc71`, - // Green - warn: `#f39c12`, - // Yellow - error: `#c0392b`, - // Red - groupCollapsed: `#3498db`, - // Blue - groupEnd: null // No colored prefix on groupEnd - - }; - - const print = function (method, args) { - if (method === 'groupCollapsed') { - // Safari doesn't print all console.groupCollapsed() arguments: - // https://bugs.webkit.org/show_bug.cgi?id=182754 - if (/^((?!chrome|android).)*safari/i.test(navigator.userAgent)) { - console[method](...args); - return; - } - } - - 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. - - const logPrefix = inGroup ? [] : ['%cworkbox', styles.join(';')]; - console[method](...logPrefix, ...args); - - if (method === 'groupCollapsed') { - inGroup = true; - } - - if (method === 'groupEnd') { - inGroup = false; - } - }; - - const api = {}; - - for (const method of Object.keys(methodToColorMap)) { - api[method] = (...args) => { - print(method, args); - }; - } - - return api; - })(); - - /* - Copyright 2018 Google LLC - - Use of this source code is governed by an MIT-style - license that can be found in the LICENSE file or at - https://opensource.org/licenses/MIT. - */ - const messages = { - 'invalid-value': ({ - paramName, - validValueDescription, - value - }) => { - if (!paramName || !validValueDescription) { - throw new Error(`Unexpected input to 'invalid-value' error.`); - } - - return `The '${paramName}' parameter was given a value with an ` + `unexpected value. ${validValueDescription} Received a value of ` + `${JSON.stringify(value)}.`; - }, - 'not-in-sw': ({ - moduleName - }) => { - if (!moduleName) { - throw new Error(`Unexpected input to 'not-in-sw' error.`); - } - - return `The '${moduleName}' must be used in a service worker.`; - }, - 'not-an-array': ({ - moduleName, - className, - funcName, - paramName - }) => { - if (!moduleName || !className || !funcName || !paramName) { - throw new Error(`Unexpected input to 'not-an-array' error.`); - } - - return `The parameter '${paramName}' passed into ` + `'${moduleName}.${className}.${funcName}()' must be an array.`; - }, - 'incorrect-type': ({ - expectedType, - paramName, - moduleName, - className, - funcName - }) => { - if (!expectedType || !paramName || !moduleName || !funcName) { - throw new Error(`Unexpected input to 'incorrect-type' error.`); - } - - return `The parameter '${paramName}' passed into ` + `'${moduleName}.${className ? className + '.' : ''}` + `${funcName}()' must be of type ${expectedType}.`; - }, - 'incorrect-class': ({ - expectedClass, - paramName, - moduleName, - className, - funcName, - isReturnValueProblem - }) => { - if (!expectedClass || !moduleName || !funcName) { - throw new Error(`Unexpected input to 'incorrect-class' error.`); - } - - if (isReturnValueProblem) { - return `The return value from ` + `'${moduleName}.${className ? className + '.' : ''}${funcName}()' ` + `must be an instance of class ${expectedClass.name}.`; - } - - return `The parameter '${paramName}' passed into ` + `'${moduleName}.${className ? className + '.' : ''}${funcName}()' ` + `must be an instance of class ${expectedClass.name}.`; - }, - 'missing-a-method': ({ - expectedMethod, - paramName, - moduleName, - className, - funcName - }) => { - if (!expectedMethod || !paramName || !moduleName || !className || !funcName) { - throw new Error(`Unexpected input to 'missing-a-method' error.`); - } - - return `${moduleName}.${className}.${funcName}() expected the ` + `'${paramName}' parameter to expose a '${expectedMethod}' method.`; - }, - 'add-to-cache-list-unexpected-type': ({ - entry - }) => { - 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.`; - }, - 'add-to-cache-list-conflicting-entries': ({ - firstEntry, - secondEntry - }) => { - if (!firstEntry || !secondEntry) { - throw new Error(`Unexpected input to ` + `'add-to-cache-list-duplicate-entries' error.`); - } - - 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.`; - }, - 'plugin-error-request-will-fetch': ({ - thrownError - }) => { - if (!thrownError) { - throw new Error(`Unexpected input to ` + `'plugin-error-request-will-fetch', error.`); - } - - return `An error was thrown by a plugins 'requestWillFetch()' method. ` + `The thrown error message was: '${thrownError.message}'.`; - }, - 'invalid-cache-name': ({ - cacheNameId, - value - }) => { - if (!cacheNameId) { - throw new Error(`Expected a 'cacheNameId' for error 'invalid-cache-name'`); - } - - return `You must provide a name containing at least one character for ` + `setCacheDeatils({${cacheNameId}: '...'}). Received a value of ` + `'${JSON.stringify(value)}'`; - }, - 'unregister-route-but-not-found-with-method': ({ - method - }) => { - if (!method) { - throw new Error(`Unexpected input to ` + `'unregister-route-but-not-found-with-method' error.`); - } - - return `The route you're trying to unregister was not previously ` + `registered for the method type '${method}'.`; - }, - 'unregister-route-route-not-registered': () => { - return `The route you're trying to unregister was not previously ` + `registered.`; - }, - 'queue-replay-failed': ({ - name - }) => { - return `Replaying the background sync queue '${name}' failed.`; - }, - 'duplicate-queue-name': ({ - name - }) => { - return `The Queue name '${name}' is already being used. ` + `All instances of backgroundSync.Queue must be given unique names.`; - }, - 'expired-test-without-max-age': ({ - methodName, - paramName - }) => { - return `The '${methodName}()' method can only be used when the ` + `'${paramName}' is used in the constructor.`; - }, - 'unsupported-route-type': ({ - moduleName, - className, - funcName, - paramName - }) => { - return `The supplied '${paramName}' parameter was an unsupported type. ` + `Please check the docs for ${moduleName}.${className}.${funcName} for ` + `valid input types.`; - }, - 'not-array-of-class': ({ - value, - expectedClass, - moduleName, - className, - funcName, - paramName - }) => { - 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.`; - }, - 'max-entries-or-age-required': ({ - moduleName, - className, - funcName - }) => { - return `You must define either config.maxEntries or config.maxAgeSeconds` + `in ${moduleName}.${className}.${funcName}`; - }, - 'statuses-or-headers-required': ({ - moduleName, - className, - funcName - }) => { - return `You must define either config.statuses or config.headers` + `in ${moduleName}.${className}.${funcName}`; - }, - 'invalid-string': ({ - moduleName, - className, - funcName, - paramName - }) => { - if (!paramName || !moduleName || !funcName) { - throw new Error(`Unexpected input to 'invalid-string' error.`); - } - - 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.`; - }, - 'channel-name-required': () => { - return `You must provide a channelName to construct a ` + `BroadcastCacheUpdate instance.`; - }, - 'invalid-responses-are-same-args': () => { - return `The arguments passed into responsesAreSame() appear to be ` + `invalid. Please ensure valid Responses are used.`; - }, - 'expire-custom-caches-only': () => { - return `You must provide a 'cacheName' property when using the ` + `expiration plugin with a runtime caching strategy.`; - }, - 'unit-must-be-bytes': ({ - normalizedRangeHeader - }) => { - if (!normalizedRangeHeader) { - throw new Error(`Unexpected input to 'unit-must-be-bytes' error.`); - } - - return `The 'unit' portion of the Range header must be set to 'bytes'. ` + `The Range header provided was "${normalizedRangeHeader}"`; - }, - 'single-range-only': ({ - normalizedRangeHeader - }) => { - if (!normalizedRangeHeader) { - throw new Error(`Unexpected input to 'single-range-only' error.`); - } - - return `Multiple ranges are not supported. Please use a single start ` + `value, and optional end value. The Range header provided was ` + `"${normalizedRangeHeader}"`; - }, - 'invalid-range-values': ({ - normalizedRangeHeader - }) => { - if (!normalizedRangeHeader) { - throw new Error(`Unexpected input to 'invalid-range-values' error.`); - } - - 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}"`; - }, - 'no-range-header': () => { - return `No Range header was found in the Request provided.`; - }, - 'range-not-satisfiable': ({ - size, - start, - end - }) => { - return `The start (${start}) and end (${end}) values in the Range are ` + `not satisfiable by the cached response, which is ${size} bytes.`; - }, - 'attempt-to-cache-non-get-request': ({ - url, - method - }) => { - return `Unable to cache '${url}' because it is a '${method}' request and ` + `only 'GET' requests can be cached.`; - }, - 'cache-put-with-no-response': ({ - url - }) => { - return `There was an attempt to cache '${url}' but the response was not ` + `defined.`; - }, - 'no-response': ({ - url, - error - }) => { - let message = `The strategy could not generate a response for '${url}'.`; - - if (error) { - message += ` The underlying error is ${error}.`; - } - - return message; - }, - 'bad-precaching-response': ({ - url, - status - }) => { - return `The precaching request for '${url}' failed with an HTTP ` + `status of ${status}.`; - } - }; - - /* - Copyright 2018 Google LLC - - Use of this source code is governed by an MIT-style - license that can be found in the LICENSE file or at - https://opensource.org/licenses/MIT. - */ - - const generatorFunction = (code, ...args) => { - const message = messages[code]; - - if (!message) { - throw new Error(`Unable to find message for code '${code}'.`); - } - - return message(...args); - }; - - const messageGenerator = generatorFunction; - - /* - Copyright 2018 Google LLC - - Use of this source code is governed by an MIT-style - license that can be found in the LICENSE file or at - https://opensource.org/licenses/MIT. - */ - /** - * Workbox errors should be thrown with this class. - * This allows use to ensure the type easily in tests, - * helps developers identify errors from workbox - * easily and allows use to optimise error - * messages correctly. - * - * @private - */ - - class WorkboxError extends Error { - /** - * - * @param {string} errorCode The error code that - * identifies this particular error. - * @param {Object=} details Any relevant arguments - * that will help developers identify issues should - * be added as a key on the context object. - */ - constructor(errorCode, details) { - let message = messageGenerator(errorCode, details); - super(message); - this.name = errorCode; - this.details = details; - } - - } - - /* - Copyright 2018 Google LLC - - Use of this source code is governed by an MIT-style - license that can be found in the LICENSE file or at - https://opensource.org/licenses/MIT. - */ - /* - * This method returns true if the current context is a service worker. - */ - - const isSWEnv = moduleName => { - if (!('ServiceWorkerGlobalScope' in self)) { - throw new WorkboxError('not-in-sw', { - moduleName - }); - } - }; - /* - * This method throws if the supplied value is not an array. - * The destructed values are required to produce a meaningful error for users. - * The destructed and restructured object is so it's clear what is - * needed. - */ - - - const isArray = (value, { - moduleName, - className, - funcName, - paramName - }) => { - if (!Array.isArray(value)) { - throw new WorkboxError('not-an-array', { - moduleName, - className, - funcName, - paramName - }); - } - }; - - const hasMethod = (object, expectedMethod, { - moduleName, - className, - funcName, - paramName - }) => { - const type = typeof object[expectedMethod]; - - if (type !== 'function') { - throw new WorkboxError('missing-a-method', { - paramName, - expectedMethod, - moduleName, - className, - funcName - }); - } - }; - - const isType = (object, expectedType, { - moduleName, - className, - funcName, - paramName - }) => { - if (typeof object !== expectedType) { - throw new WorkboxError('incorrect-type', { - paramName, - expectedType, - moduleName, - className, - funcName - }); - } - }; - - const isInstance = (object, expectedClass, { - moduleName, - className, - funcName, - paramName, - isReturnValueProblem - }) => { - if (!(object instanceof expectedClass)) { - throw new WorkboxError('incorrect-class', { - paramName, - expectedClass, - moduleName, - className, - funcName, - isReturnValueProblem - }); - } - }; - - const isOneOf = (value, validValues, { - paramName - }) => { - if (!validValues.includes(value)) { - throw new WorkboxError('invalid-value', { - paramName, - value, - validValueDescription: `Valid values are ${JSON.stringify(validValues)}.` - }); - } - }; - - const isArrayOfClass = (value, expectedClass, { - moduleName, - className, - funcName, - paramName - }) => { - const error = new WorkboxError('not-array-of-class', { - value, - expectedClass, - moduleName, - className, - funcName, - paramName - }); - - if (!Array.isArray(value)) { - throw error; - } - - for (let item of value) { - if (!(item instanceof expectedClass)) { - throw error; - } - } - }; - - const finalAssertExports = { - hasMethod, - isArray, - isInstance, - isOneOf, - isSWEnv, - isType, - isArrayOfClass - }; - - /* - Copyright 2018 Google LLC - - Use of this source code is governed by an MIT-style - license that can be found in the LICENSE file or at - https://opensource.org/licenses/MIT. - */ - - const quotaErrorCallbacks = new Set(); - - /* - Copyright 2019 Google LLC - - Use of this source code is governed by an MIT-style - license that can be found in the LICENSE file or at - https://opensource.org/licenses/MIT. - */ - /** - * Adds a function to the set of quotaErrorCallbacks that will be executed if - * there's a quota error. - * - * @param {Function} callback - * @memberof workbox.core - */ - - function registerQuotaErrorCallback(callback) { - { - finalAssertExports.isType(callback, 'function', { - moduleName: 'workbox-core', - funcName: 'register', - paramName: 'callback' - }); - } - - quotaErrorCallbacks.add(callback); - - { - logger.log('Registered a callback to respond to quota errors.', callback); - } - } - - /* - Copyright 2018 Google LLC - - Use of this source code is governed by an MIT-style - license that can be found in the LICENSE file or at - https://opensource.org/licenses/MIT. - */ - const _cacheNameDetails = { - googleAnalytics: 'googleAnalytics', - precache: 'precache-v2', - prefix: 'workbox', - runtime: 'runtime', - suffix: self.registration.scope - }; - - const _createCacheName = cacheName => { - return [_cacheNameDetails.prefix, cacheName, _cacheNameDetails.suffix].filter(value => value.length > 0).join('-'); - }; - - const cacheNames = { - updateDetails: details => { - Object.keys(_cacheNameDetails).forEach(key => { - if (typeof details[key] !== 'undefined') { - _cacheNameDetails[key] = details[key]; - } - }); - }, - getGoogleAnalyticsName: userCacheName => { - return userCacheName || _createCacheName(_cacheNameDetails.googleAnalytics); - }, - getPrecacheName: userCacheName => { - return userCacheName || _createCacheName(_cacheNameDetails.precache); - }, - getPrefix: () => { - return _cacheNameDetails.prefix; - }, - getRuntimeName: userCacheName => { - return userCacheName || _createCacheName(_cacheNameDetails.runtime); - }, - getSuffix: () => { - return _cacheNameDetails.suffix; - } - }; - - /* - Copyright 2018 Google LLC - - Use of this source code is governed by an MIT-style - license that can be found in the LICENSE file or at - https://opensource.org/licenses/MIT. - */ - - const getFriendlyURL = url => { - const urlObj = new URL(url, location); - - if (urlObj.origin === location.origin) { - return urlObj.pathname; - } - - return urlObj.href; - }; - - /* - Copyright 2018 Google LLC - - Use of this source code is governed by an MIT-style - license that can be found in the LICENSE file or at - https://opensource.org/licenses/MIT. - */ - /** - * Runs all of the callback functions, one at a time sequentially, in the order - * in which they were registered. - * - * @memberof workbox.core - * @private - */ - - async function executeQuotaErrorCallbacks() { - { - logger.log(`About to run ${quotaErrorCallbacks.size} ` + `callbacks to clean up caches.`); - } - - for (const callback of quotaErrorCallbacks) { - await callback(); - - { - logger.log(callback, 'is complete.'); - } - } - - { - logger.log('Finished running callbacks.'); - } - } - - /* - Copyright 2018 Google LLC - - Use of this source code is governed by an MIT-style - license that can be found in the LICENSE file or at - https://opensource.org/licenses/MIT. - */ - const pluginEvents = { - CACHE_DID_UPDATE: 'cacheDidUpdate', - CACHE_KEY_WILL_BE_USED: 'cacheKeyWillBeUsed', - CACHE_WILL_UPDATE: 'cacheWillUpdate', - CACHED_RESPONSE_WILL_BE_USED: 'cachedResponseWillBeUsed', - FETCH_DID_FAIL: 'fetchDidFail', - FETCH_DID_SUCCEED: 'fetchDidSucceed', - REQUEST_WILL_FETCH: 'requestWillFetch' - }; - - /* - Copyright 2018 Google LLC - - Use of this source code is governed by an MIT-style - license that can be found in the LICENSE file or at - https://opensource.org/licenses/MIT. - */ - const pluginUtils = { - filter: (plugins, callbackName) => { - return plugins.filter(plugin => callbackName in plugin); - } - }; - - /* - Copyright 2018 Google LLC - - Use of this source code is governed by an MIT-style - license that can be found in the LICENSE file or at - https://opensource.org/licenses/MIT. - */ - /** - * Wrapper around cache.put(). - * - * Will call `cacheDidUpdate` on plugins if the cache was updated, using - * `matchOptions` when determining what the old entry is. - * - * @param {Object} options - * @param {string} options.cacheName - * @param {Request} options.request - * @param {Response} options.response - * @param {Event} [options.event] - * @param {Array<Object>} [options.plugins=[]] - * @param {Object} [options.matchOptions] - * - * @private - * @memberof module:workbox-core - */ - - const putWrapper = async ({ - cacheName, - request, - response, - event, - plugins = [], - matchOptions - } = {}) => { - { - if (request.method && request.method !== 'GET') { - throw new WorkboxError('attempt-to-cache-non-get-request', { - url: getFriendlyURL(request.url), - method: request.method - }); - } - } - - const effectiveRequest = await _getEffectiveRequest({ - plugins, - request, - mode: 'write' - }); - - if (!response) { - { - logger.error(`Cannot cache non-existent response for ` + `'${getFriendlyURL(effectiveRequest.url)}'.`); - } - - throw new WorkboxError('cache-put-with-no-response', { - url: getFriendlyURL(effectiveRequest.url) - }); - } - - let responseToCache = await _isResponseSafeToCache({ - event, - plugins, - response, - request: effectiveRequest - }); - - if (!responseToCache) { - { - logger.debug(`Response '${getFriendlyURL(effectiveRequest.url)}' will ` + `not be cached.`, responseToCache); - } - - return; - } - - const cache = await caches.open(cacheName); - const updatePlugins = pluginUtils.filter(plugins, pluginEvents.CACHE_DID_UPDATE); - let oldResponse = updatePlugins.length > 0 ? await matchWrapper({ - cacheName, - matchOptions, - request: effectiveRequest - }) : null; - - { - logger.debug(`Updating the '${cacheName}' cache with a new Response for ` + `${getFriendlyURL(effectiveRequest.url)}.`); - } - - try { - await cache.put(effectiveRequest, responseToCache); - } catch (error) { - // See https://developer.mozilla.org/en-US/docs/Web/API/DOMException#exception-QuotaExceededError - if (error.name === 'QuotaExceededError') { - await executeQuotaErrorCallbacks(); - } - - throw error; - } - - for (let plugin of updatePlugins) { - await plugin[pluginEvents.CACHE_DID_UPDATE].call(plugin, { - cacheName, - event, - oldResponse, - newResponse: responseToCache, - request: effectiveRequest - }); - } - }; - /** - * This is a wrapper around cache.match(). - * - * @param {Object} options - * @param {string} options.cacheName Name of the cache to match against. - * @param {Request} options.request The Request that will be used to look up - * cache entries. - * @param {Event} [options.event] The event that propted the action. - * @param {Object} [options.matchOptions] Options passed to cache.match(). - * @param {Array<Object>} [options.plugins=[]] Array of plugins. - * @return {Response} A cached response if available. - * - * @private - * @memberof module:workbox-core - */ - - - const matchWrapper = async ({ - cacheName, - request, - event, - matchOptions, - plugins = [] - }) => { - const cache = await caches.open(cacheName); - const effectiveRequest = await _getEffectiveRequest({ - plugins, - request, - mode: 'read' - }); - let cachedResponse = await cache.match(effectiveRequest, matchOptions); - - { - if (cachedResponse) { - logger.debug(`Found a cached response in '${cacheName}'.`); - } else { - logger.debug(`No cached response found in '${cacheName}'.`); - } - } - - for (const plugin of plugins) { - if (pluginEvents.CACHED_RESPONSE_WILL_BE_USED in plugin) { - cachedResponse = await plugin[pluginEvents.CACHED_RESPONSE_WILL_BE_USED].call(plugin, { - cacheName, - event, - matchOptions, - cachedResponse, - request: effectiveRequest - }); - - { - if (cachedResponse) { - finalAssertExports.isInstance(cachedResponse, Response, { - moduleName: 'Plugin', - funcName: pluginEvents.CACHED_RESPONSE_WILL_BE_USED, - isReturnValueProblem: true - }); - } - } - } - } - - return cachedResponse; - }; - /** - * This method will call cacheWillUpdate on the available plugins (or use - * status === 200) to determine if the Response is safe and valid to cache. - * - * @param {Object} options - * @param {Request} options.request - * @param {Response} options.response - * @param {Event} [options.event] - * @param {Array<Object>} [options.plugins=[]] - * @return {Promise<Response>} - * - * @private - * @memberof module:workbox-core - */ - - - const _isResponseSafeToCache = async ({ - request, - response, - event, - plugins - }) => { - let responseToCache = response; - let pluginsUsed = false; - - for (let plugin of plugins) { - if (pluginEvents.CACHE_WILL_UPDATE in plugin) { - pluginsUsed = true; - responseToCache = await plugin[pluginEvents.CACHE_WILL_UPDATE].call(plugin, { - request, - response: responseToCache, - event - }); - - { - if (responseToCache) { - finalAssertExports.isInstance(responseToCache, Response, { - moduleName: 'Plugin', - funcName: pluginEvents.CACHE_WILL_UPDATE, - isReturnValueProblem: true - }); - } - } - - if (!responseToCache) { - break; - } - } - } - - if (!pluginsUsed) { - { - if (!responseToCache.status === 200) { - if (responseToCache.status === 0) { - 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.`); - } else { - logger.debug(`The response for '${request.url}' returned ` + `a status code of '${response.status}' and won't be cached as a ` + `result.`); - } - } - } - - responseToCache = responseToCache.status === 200 ? responseToCache : null; - } - - return responseToCache ? responseToCache : null; - }; - /** - * Checks the list of plugins for the cacheKeyWillBeUsed callback, and - * executes any of those callbacks found in sequence. The final `Request` object - * returned by the last plugin is treated as the cache key for cache reads - * and/or writes. - * - * @param {Object} options - * @param {Request} options.request - * @param {string} options.mode - * @param {Array<Object>} [options.plugins=[]] - * @return {Promise<Request>} - * - * @private - * @memberof module:workbox-core - */ - - - const _getEffectiveRequest = async ({ - request, - mode, - plugins - }) => { - const cacheKeyWillBeUsedPlugins = pluginUtils.filter(plugins, pluginEvents.CACHE_KEY_WILL_BE_USED); - let effectiveRequest = request; - - for (const plugin of cacheKeyWillBeUsedPlugins) { - effectiveRequest = await plugin[pluginEvents.CACHE_KEY_WILL_BE_USED].call(plugin, { - mode, - request: effectiveRequest - }); - - if (typeof effectiveRequest === 'string') { - effectiveRequest = new Request(effectiveRequest); - } - - { - finalAssertExports.isInstance(effectiveRequest, Request, { - moduleName: 'Plugin', - funcName: pluginEvents.CACHE_KEY_WILL_BE_USED, - isReturnValueProblem: true - }); - } - } - - return effectiveRequest; - }; - - const cacheWrapper = { - put: putWrapper, - match: matchWrapper - }; - - /* - Copyright 2018 Google LLC - - Use of this source code is governed by an MIT-style - license that can be found in the LICENSE file or at - https://opensource.org/licenses/MIT. - */ - /** - * A class that wraps common IndexedDB functionality in a promise-based API. - * It exposes all the underlying power and functionality of IndexedDB, but - * wraps the most commonly used features in a way that's much simpler to use. - * - * @private - */ - - class DBWrapper { - /** - * @param {string} name - * @param {number} version - * @param {Object=} [callback] - * @param {!Function} [callbacks.onupgradeneeded] - * @param {!Function} [callbacks.onversionchange] Defaults to - * DBWrapper.prototype._onversionchange when not specified. - * @private - */ - constructor(name, version, { - onupgradeneeded, - onversionchange = this._onversionchange - } = {}) { - this._name = name; - this._version = version; - this._onupgradeneeded = onupgradeneeded; - this._onversionchange = onversionchange; // If this is null, it means the database isn't open. - - this._db = null; - } - /** - * Returns the IDBDatabase instance (not normally needed). - * - * @private - */ - - - get db() { - return this._db; - } - /** - * Opens a connected to an IDBDatabase, invokes any onupgradedneeded - * callback, and added an onversionchange callback to the database. - * - * @return {IDBDatabase} - * @private - */ - - - async open() { - if (this._db) return; - this._db = await new Promise((resolve, reject) => { - // This flag is flipped to true if the timeout callback runs prior - // to the request failing or succeeding. Note: we use a timeout instead - // of an onblocked handler since there are cases where onblocked will - // never never run. A timeout better handles all possible scenarios: - // https://github.com/w3c/IndexedDB/issues/223 - let openRequestTimedOut = false; - setTimeout(() => { - openRequestTimedOut = true; - reject(new Error('The open request was blocked and timed out')); - }, this.OPEN_TIMEOUT); - const openRequest = indexedDB.open(this._name, this._version); - - openRequest.onerror = () => reject(openRequest.error); - - openRequest.onupgradeneeded = evt => { - if (openRequestTimedOut) { - openRequest.transaction.abort(); - evt.target.result.close(); - } else if (this._onupgradeneeded) { - this._onupgradeneeded(evt); - } - }; - - openRequest.onsuccess = ({ - target - }) => { - const db = target.result; - - if (openRequestTimedOut) { - db.close(); - } else { - db.onversionchange = this._onversionchange.bind(this); - resolve(db); - } - }; - }); - return this; - } - /** - * Polyfills the native `getKey()` method. Note, this is overridden at - * runtime if the browser supports the native method. - * - * @param {string} storeName - * @param {*} query - * @return {Array} - * @private - */ - - - async getKey(storeName, query) { - return (await this.getAllKeys(storeName, query, 1))[0]; - } - /** - * Polyfills the native `getAll()` method. Note, this is overridden at - * runtime if the browser supports the native method. - * - * @param {string} storeName - * @param {*} query - * @param {number} count - * @return {Array} - * @private - */ - - - async getAll(storeName, query, count) { - return await this.getAllMatching(storeName, { - query, - count - }); - } - /** - * Polyfills the native `getAllKeys()` method. Note, this is overridden at - * runtime if the browser supports the native method. - * - * @param {string} storeName - * @param {*} query - * @param {number} count - * @return {Array} - * @private - */ - - - async getAllKeys(storeName, query, count) { - return (await this.getAllMatching(storeName, { - query, - count, - includeKeys: true - })).map(({ - key - }) => key); - } - /** - * Supports flexible lookup in an object store by specifying an index, - |
