jekyll-pwa-plugin 2.2.3 → 5.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/jekyll-pwa-plugin.rb +11 -3
- data/lib/vendor/workbox-v5.1.4/workbox-background-sync.dev.js +818 -0
- data/lib/vendor/workbox-v5.1.4/workbox-background-sync.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-background-sync.prod.js +2 -0
- data/lib/vendor/workbox-v5.1.4/workbox-background-sync.prod.js.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-broadcast-update.dev.js +288 -0
- data/lib/vendor/workbox-v5.1.4/workbox-broadcast-update.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-broadcast-update.prod.js +2 -0
- data/lib/vendor/workbox-v5.1.4/workbox-broadcast-update.prod.js.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-cacheable-response.dev.js +191 -0
- data/lib/vendor/workbox-v5.1.4/workbox-cacheable-response.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-cacheable-response.prod.js +2 -0
- data/lib/vendor/workbox-v5.1.4/workbox-cacheable-response.prod.js.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-core.dev.js +1858 -0
- data/lib/vendor/workbox-v5.1.4/workbox-core.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-core.prod.js +2 -0
- data/lib/vendor/workbox-v5.1.4/workbox-core.prod.js.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-expiration.dev.js +649 -0
- data/lib/vendor/workbox-v5.1.4/workbox-expiration.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-expiration.prod.js +2 -0
- data/lib/vendor/workbox-v5.1.4/workbox-expiration.prod.js.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-navigation-preload.dev.js +102 -0
- data/lib/vendor/workbox-v5.1.4/workbox-navigation-preload.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-navigation-preload.prod.js +2 -0
- data/lib/vendor/workbox-v5.1.4/workbox-navigation-preload.prod.js.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-offline-ga.dev.js +235 -0
- data/lib/vendor/workbox-v5.1.4/workbox-offline-ga.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-offline-ga.prod.js +2 -0
- data/lib/vendor/workbox-v5.1.4/workbox-offline-ga.prod.js.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-precaching.dev.js +1210 -0
- data/lib/vendor/workbox-v5.1.4/workbox-precaching.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-precaching.prod.js +2 -0
- data/lib/vendor/workbox-v5.1.4/workbox-precaching.prod.js.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-range-requests.dev.js +262 -0
- data/lib/vendor/workbox-v5.1.4/workbox-range-requests.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-range-requests.prod.js +2 -0
- data/lib/vendor/workbox-v5.1.4/workbox-range-requests.prod.js.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-routing.dev.js +923 -0
- data/lib/vendor/workbox-v5.1.4/workbox-routing.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-routing.prod.js +2 -0
- data/lib/vendor/workbox-v5.1.4/workbox-routing.prod.js.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-strategies.dev.js +923 -0
- data/lib/vendor/workbox-v5.1.4/workbox-strategies.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-strategies.prod.js +2 -0
- data/lib/vendor/workbox-v5.1.4/workbox-strategies.prod.js.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-streams.dev.js +318 -0
- data/lib/vendor/workbox-v5.1.4/workbox-streams.dev.js.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-streams.prod.js +2 -0
- data/lib/vendor/workbox-v5.1.4/workbox-streams.prod.js.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-sw.js +2 -0
- data/lib/vendor/workbox-v5.1.4/workbox-sw.js.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-window.dev.es5.mjs +1125 -0
- data/lib/vendor/workbox-v5.1.4/workbox-window.dev.es5.mjs.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-window.dev.mjs +943 -0
- data/lib/vendor/workbox-v5.1.4/workbox-window.dev.mjs.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-window.dev.umd.js +1136 -0
- data/lib/vendor/workbox-v5.1.4/workbox-window.dev.umd.js.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-window.prod.es5.mjs +2 -0
- data/lib/vendor/workbox-v5.1.4/workbox-window.prod.es5.mjs.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-window.prod.mjs +2 -0
- data/lib/vendor/workbox-v5.1.4/workbox-window.prod.mjs.map +1 -0
- data/lib/vendor/workbox-v5.1.4/workbox-window.prod.umd.js +2 -0
- data/lib/vendor/workbox-v5.1.4/workbox-window.prod.umd.js.map +1 -0
- metadata +65 -55
- data/lib/vendor/workbox-v3.6.3/workbox-background-sync.dev.js +0 -593
- data/lib/vendor/workbox-v3.6.3/workbox-background-sync.dev.js.map +0 -1
- data/lib/vendor/workbox-v3.6.3/workbox-background-sync.prod.js +0 -3
- data/lib/vendor/workbox-v3.6.3/workbox-background-sync.prod.js.map +0 -1
- data/lib/vendor/workbox-v3.6.3/workbox-broadcast-cache-update.dev.js +0 -395
- data/lib/vendor/workbox-v3.6.3/workbox-broadcast-cache-update.dev.js.map +0 -1
- data/lib/vendor/workbox-v3.6.3/workbox-broadcast-cache-update.prod.js +0 -3
- data/lib/vendor/workbox-v3.6.3/workbox-broadcast-cache-update.prod.js.map +0 -1
- data/lib/vendor/workbox-v3.6.3/workbox-cache-expiration.dev.js +0 -740
- data/lib/vendor/workbox-v3.6.3/workbox-cache-expiration.dev.js.map +0 -1
- data/lib/vendor/workbox-v3.6.3/workbox-cache-expiration.prod.js +0 -3
- data/lib/vendor/workbox-v3.6.3/workbox-cache-expiration.prod.js.map +0 -1
- data/lib/vendor/workbox-v3.6.3/workbox-cacheable-response.dev.js +0 -236
- data/lib/vendor/workbox-v3.6.3/workbox-cacheable-response.dev.js.map +0 -1
- data/lib/vendor/workbox-v3.6.3/workbox-cacheable-response.prod.js +0 -3
- data/lib/vendor/workbox-v3.6.3/workbox-cacheable-response.prod.js.map +0 -1
- data/lib/vendor/workbox-v3.6.3/workbox-core.dev.js +0 -1736
- data/lib/vendor/workbox-v3.6.3/workbox-core.dev.js.map +0 -1
- data/lib/vendor/workbox-v3.6.3/workbox-core.prod.js +0 -3
- data/lib/vendor/workbox-v3.6.3/workbox-core.prod.js.map +0 -1
- data/lib/vendor/workbox-v3.6.3/workbox-google-analytics.dev.js +0 -255
- data/lib/vendor/workbox-v3.6.3/workbox-google-analytics.dev.js.map +0 -1
- data/lib/vendor/workbox-v3.6.3/workbox-google-analytics.prod.js +0 -3
- data/lib/vendor/workbox-v3.6.3/workbox-google-analytics.prod.js.map +0 -1
- data/lib/vendor/workbox-v3.6.3/workbox-navigation-preload.dev.js +0 -159
- data/lib/vendor/workbox-v3.6.3/workbox-navigation-preload.dev.js.map +0 -1
- data/lib/vendor/workbox-v3.6.3/workbox-navigation-preload.prod.js +0 -3
- data/lib/vendor/workbox-v3.6.3/workbox-navigation-preload.prod.js.map +0 -1
- data/lib/vendor/workbox-v3.6.3/workbox-precaching.dev.js +0 -1171
- data/lib/vendor/workbox-v3.6.3/workbox-precaching.dev.js.map +0 -1
- data/lib/vendor/workbox-v3.6.3/workbox-precaching.prod.js +0 -3
- data/lib/vendor/workbox-v3.6.3/workbox-precaching.prod.js.map +0 -1
- data/lib/vendor/workbox-v3.6.3/workbox-range-requests.dev.js +0 -299
- data/lib/vendor/workbox-v3.6.3/workbox-range-requests.dev.js.map +0 -1
- data/lib/vendor/workbox-v3.6.3/workbox-range-requests.prod.js +0 -3
- data/lib/vendor/workbox-v3.6.3/workbox-range-requests.prod.js.map +0 -1
- data/lib/vendor/workbox-v3.6.3/workbox-routing.dev.js +0 -863
- data/lib/vendor/workbox-v3.6.3/workbox-routing.dev.js.map +0 -1
- data/lib/vendor/workbox-v3.6.3/workbox-routing.prod.js +0 -3
- data/lib/vendor/workbox-v3.6.3/workbox-routing.prod.js.map +0 -1
- data/lib/vendor/workbox-v3.6.3/workbox-strategies.dev.js +0 -1172
- data/lib/vendor/workbox-v3.6.3/workbox-strategies.dev.js.map +0 -1
- data/lib/vendor/workbox-v3.6.3/workbox-strategies.prod.js +0 -3
- data/lib/vendor/workbox-v3.6.3/workbox-strategies.prod.js.map +0 -1
- data/lib/vendor/workbox-v3.6.3/workbox-streams.dev.js +0 -380
- data/lib/vendor/workbox-v3.6.3/workbox-streams.dev.js.map +0 -1
- data/lib/vendor/workbox-v3.6.3/workbox-streams.prod.js +0 -3
- data/lib/vendor/workbox-v3.6.3/workbox-streams.prod.js.map +0 -1
- data/lib/vendor/workbox-v3.6.3/workbox-sw.js +0 -3
- data/lib/vendor/workbox-v3.6.3/workbox-sw.js.map +0 -1
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"workbox-routing.dev.js","sources":["../_version.js","../utils/constants.js","../utils/normalizeHandler.js","../Route.js","../NavigationRoute.js","../RegExpRoute.js","../Router.js","../utils/getOrCreateDefaultRouter.js","../registerRoute.js","../setCatchHandler.js","../setDefaultHandler.js"],"sourcesContent":["\"use strict\";\n// @ts-ignore\ntry {\n self['workbox:routing:5.1.4'] && _();\n}\ncatch (e) { }\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport '../_version.js';\n/**\n * The default HTTP method, 'GET', used when there's no specific method\n * configured for a route.\n *\n * @type {string}\n *\n * @private\n */\nexport const defaultMethod = 'GET';\n/**\n * The list of valid HTTP methods associated with requests that could be routed.\n *\n * @type {Array<string>}\n *\n * @private\n */\nexport const validMethods = [\n 'DELETE',\n 'GET',\n 'HEAD',\n 'PATCH',\n 'POST',\n 'PUT',\n];\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { assert } from 'workbox-core/_private/assert.js';\nimport '../_version.js';\n/**\n * @param {function()|Object} handler Either a function, or an object with a\n * 'handle' method.\n * @return {Object} An object with a handle method.\n *\n * @private\n */\nexport const normalizeHandler = (handler) => {\n if (handler && typeof handler === 'object') {\n if (process.env.NODE_ENV !== 'production') {\n assert.hasMethod(handler, 'handle', {\n moduleName: 'workbox-routing',\n className: 'Route',\n funcName: 'constructor',\n paramName: 'handler',\n });\n }\n return handler;\n }\n else {\n if (process.env.NODE_ENV !== 'production') {\n assert.isType(handler, 'function', {\n moduleName: 'workbox-routing',\n className: 'Route',\n funcName: 'constructor',\n paramName: 'handler',\n });\n }\n return { handle: handler };\n }\n};\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { assert } from 'workbox-core/_private/assert.js';\nimport { defaultMethod, validMethods } from './utils/constants.js';\nimport { normalizeHandler } from './utils/normalizeHandler.js';\nimport './_version.js';\n/**\n * A `Route` consists of a pair of callback functions, \"match\" and \"handler\".\n * The \"match\" callback determine if a route should be used to \"handle\" a\n * request by returning a non-falsy value if it can. The \"handler\" callback\n * is called when there is a match and should return a Promise that resolves\n * to a `Response`.\n *\n * @memberof module:workbox-routing\n */\nclass Route {\n /**\n * Constructor for Route class.\n *\n * @param {module:workbox-routing~matchCallback} match\n * A callback function that determines whether the route matches a given\n * `fetch` event by returning a non-falsy value.\n * @param {module:workbox-routing~handlerCallback} handler A callback\n * function that returns a Promise resolving to a Response.\n * @param {string} [method='GET'] The HTTP method to match the Route\n * against.\n */\n constructor(match, handler, method = defaultMethod) {\n if (process.env.NODE_ENV !== 'production') {\n assert.isType(match, 'function', {\n moduleName: 'workbox-routing',\n className: 'Route',\n funcName: 'constructor',\n paramName: 'match',\n });\n if (method) {\n assert.isOneOf(method, validMethods, { paramName: 'method' });\n }\n }\n // These values are referenced directly by Router so cannot be\n // altered by minificaton.\n this.handler = normalizeHandler(handler);\n this.match = match;\n this.method = method;\n }\n}\nexport { Route };\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { assert } from 'workbox-core/_private/assert.js';\nimport { logger } from 'workbox-core/_private/logger.js';\nimport { Route } from './Route.js';\nimport './_version.js';\n/**\n * NavigationRoute makes it easy to create a\n * [Route]{@link module:workbox-routing.Route} that matches for browser\n * [navigation requests]{@link https://developers.google.com/web/fundamentals/primers/service-workers/high-performance-loading#first_what_are_navigation_requests}.\n *\n * It will only match incoming Requests whose\n * [`mode`]{@link https://fetch.spec.whatwg.org/#concept-request-mode}\n * is set to `navigate`.\n *\n * You can optionally only apply this route to a subset of navigation requests\n * by using one or both of the `denylist` and `allowlist` parameters.\n *\n * @memberof module:workbox-routing\n * @extends module:workbox-routing.Route\n */\nclass NavigationRoute extends Route {\n /**\n * If both `denylist` and `allowlist` are provided, the `denylist` will\n * take precedence and the request will not match this route.\n *\n * The regular expressions in `allowlist` and `denylist`\n * are matched against the concatenated\n * [`pathname`]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLHyperlinkElementUtils/pathname}\n * and [`search`]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLHyperlinkElementUtils/search}\n * portions of the requested URL.\n *\n * @param {module:workbox-routing~handlerCallback} handler A callback\n * function that returns a Promise resulting in a Response.\n * @param {Object} options\n * @param {Array<RegExp>} [options.denylist] If any of these patterns match,\n * the route will not handle the request (even if a allowlist RegExp matches).\n * @param {Array<RegExp>} [options.allowlist=[/./]] If any of these patterns\n * match the URL's pathname and search parameter, the route will handle the\n * request (assuming the denylist doesn't match).\n */\n constructor(handler, { allowlist = [/./], denylist = [] } = {}) {\n if (process.env.NODE_ENV !== 'production') {\n assert.isArrayOfClass(allowlist, RegExp, {\n moduleName: 'workbox-routing',\n className: 'NavigationRoute',\n funcName: 'constructor',\n paramName: 'options.allowlist',\n });\n assert.isArrayOfClass(denylist, RegExp, {\n moduleName: 'workbox-routing',\n className: 'NavigationRoute',\n funcName: 'constructor',\n paramName: 'options.denylist',\n });\n }\n super((options) => this._match(options), handler);\n this._allowlist = allowlist;\n this._denylist = denylist;\n }\n /**\n * Routes match handler.\n *\n * @param {Object} options\n * @param {URL} options.url\n * @param {Request} options.request\n * @return {boolean}\n *\n * @private\n */\n _match({ url, request }) {\n if (request && request.mode !== 'navigate') {\n return false;\n }\n const pathnameAndSearch = url.pathname + url.search;\n for (const regExp of this._denylist) {\n if (regExp.test(pathnameAndSearch)) {\n if (process.env.NODE_ENV !== 'production') {\n logger.log(`The navigation route ${pathnameAndSearch} is not ` +\n `being used, since the URL matches this denylist pattern: ` +\n `${regExp}`);\n }\n return false;\n }\n }\n if (this._allowlist.some((regExp) => regExp.test(pathnameAndSearch))) {\n if (process.env.NODE_ENV !== 'production') {\n logger.debug(`The navigation route ${pathnameAndSearch} ` +\n `is being used.`);\n }\n return true;\n }\n if (process.env.NODE_ENV !== 'production') {\n logger.log(`The navigation route ${pathnameAndSearch} is not ` +\n `being used, since the URL being navigated to doesn't ` +\n `match the allowlist.`);\n }\n return false;\n }\n}\nexport { NavigationRoute };\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { assert } from 'workbox-core/_private/assert.js';\nimport { logger } from 'workbox-core/_private/logger.js';\nimport { Route } from './Route.js';\nimport './_version.js';\n/**\n * RegExpRoute makes it easy to create a regular expression based\n * [Route]{@link module:workbox-routing.Route}.\n *\n * For same-origin requests the RegExp only needs to match part of the URL. For\n * requests against third-party servers, you must define a RegExp that matches\n * the start of the URL.\n *\n * [See the module docs for info.]{@link https://developers.google.com/web/tools/workbox/modules/workbox-routing}\n *\n * @memberof module:workbox-routing\n * @extends module:workbox-routing.Route\n */\nclass RegExpRoute extends Route {\n /**\n * If the regular expression contains\n * [capture groups]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#grouping-back-references},\n * the captured values will be passed to the\n * [handler's]{@link module:workbox-routing~handlerCallback} `params`\n * argument.\n *\n * @param {RegExp} regExp The regular expression to match against URLs.\n * @param {module:workbox-routing~handlerCallback} handler A callback\n * function that returns a Promise resulting in a Response.\n * @param {string} [method='GET'] The HTTP method to match the Route\n * against.\n */\n constructor(regExp, handler, method) {\n if (process.env.NODE_ENV !== 'production') {\n assert.isInstance(regExp, RegExp, {\n moduleName: 'workbox-routing',\n className: 'RegExpRoute',\n funcName: 'constructor',\n paramName: 'pattern',\n });\n }\n const match = ({ url }) => {\n const result = regExp.exec(url.href);\n // Return immediately if there's no match.\n if (!result) {\n return;\n }\n // Require that the match start at the first character in the URL string\n // if it's a cross-origin request.\n // See https://github.com/GoogleChrome/workbox/issues/281 for the context\n // behind this behavior.\n if ((url.origin !== location.origin) && (result.index !== 0)) {\n if (process.env.NODE_ENV !== 'production') {\n logger.debug(`The regular expression '${regExp}' only partially matched ` +\n `against the cross-origin URL '${url}'. RegExpRoute's will only ` +\n `handle cross-origin requests if they match the entire URL.`);\n }\n return;\n }\n // If the route matches, but there aren't any capture groups defined, then\n // this will return [], which is truthy and therefore sufficient to\n // indicate a match.\n // If there are capture groups, then it will return their values.\n return result.slice(1);\n };\n super(match, handler, method);\n }\n}\nexport { RegExpRoute };\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { assert } from 'workbox-core/_private/assert.js';\nimport { logger } from 'workbox-core/_private/logger.js';\nimport { WorkboxError } from 'workbox-core/_private/WorkboxError.js';\nimport { getFriendlyURL } from 'workbox-core/_private/getFriendlyURL.js';\nimport { normalizeHandler } from './utils/normalizeHandler.js';\nimport './_version.js';\n/**\n * The Router can be used to process a FetchEvent through one or more\n * [Routes]{@link module:workbox-routing.Route} responding with a Request if\n * a matching route exists.\n *\n * If no route matches a given a request, the Router will use a \"default\"\n * handler if one is defined.\n *\n * Should the matching Route throw an error, the Router will use a \"catch\"\n * handler if one is defined to gracefully deal with issues and respond with a\n * Request.\n *\n * If a request matches multiple routes, the **earliest** registered route will\n * be used to respond to the request.\n *\n * @memberof module:workbox-routing\n */\nclass Router {\n /**\n * Initializes a new Router.\n */\n constructor() {\n this._routes = new Map();\n }\n /**\n * @return {Map<string, Array<module:workbox-routing.Route>>} routes A `Map` of HTTP\n * method name ('GET', etc.) to an array of all the corresponding `Route`\n * instances that are registered.\n */\n get routes() {\n return this._routes;\n }\n /**\n * Adds a fetch event listener to respond to events when a route matches\n * the event's request.\n */\n addFetchListener() {\n // See https://github.com/Microsoft/TypeScript/issues/28357#issuecomment-436484705\n self.addEventListener('fetch', ((event) => {\n const { request } = event;\n const responsePromise = this.handleRequest({ request, event });\n if (responsePromise) {\n event.respondWith(responsePromise);\n }\n }));\n }\n /**\n * Adds a message event listener for URLs to cache from the window.\n * This is useful to cache resources loaded on the page prior to when the\n * service worker started controlling it.\n *\n * The format of the message data sent from the window should be as follows.\n * Where the `urlsToCache` array may consist of URL strings or an array of\n * URL string + `requestInit` object (the same as you'd pass to `fetch()`).\n *\n * ```\n * {\n * type: 'CACHE_URLS',\n * payload: {\n * urlsToCache: [\n * './script1.js',\n * './script2.js',\n * ['./script3.js', {mode: 'no-cors'}],\n * ],\n * },\n * }\n * ```\n */\n addCacheListener() {\n // See https://github.com/Microsoft/TypeScript/issues/28357#issuecomment-436484705\n self.addEventListener('message', ((event) => {\n if (event.data && event.data.type === 'CACHE_URLS') {\n const { payload } = event.data;\n if (process.env.NODE_ENV !== 'production') {\n logger.debug(`Caching URLs from the window`, payload.urlsToCache);\n }\n const requestPromises = Promise.all(payload.urlsToCache.map((entry) => {\n if (typeof entry === 'string') {\n entry = [entry];\n }\n const request = new Request(...entry);\n return this.handleRequest({ request });\n // TODO(philipwalton): TypeScript errors without this typecast for\n // some reason (probably a bug). The real type here should work but\n // doesn't: `Array<Promise<Response> | undefined>`.\n })); // TypeScript\n event.waitUntil(requestPromises);\n // If a MessageChannel was used, reply to the message on success.\n if (event.ports && event.ports[0]) {\n requestPromises.then(() => event.ports[0].postMessage(true));\n }\n }\n }));\n }\n /**\n * Apply the routing rules to a FetchEvent object to get a Response from an\n * appropriate Route's handler.\n *\n * @param {Object} options\n * @param {Request} options.request The request to handle (this is usually\n * from a fetch event, but it does not have to be).\n * @param {FetchEvent} [options.event] The event that triggered the request,\n * if applicable.\n * @return {Promise<Response>|undefined} A promise is returned if a\n * registered route can handle the request. If there is no matching\n * route and there's no `defaultHandler`, `undefined` is returned.\n */\n handleRequest({ request, event }) {\n if (process.env.NODE_ENV !== 'production') {\n assert.isInstance(request, Request, {\n moduleName: 'workbox-routing',\n className: 'Router',\n funcName: 'handleRequest',\n paramName: 'options.request',\n });\n }\n const url = new URL(request.url, location.href);\n if (!url.protocol.startsWith('http')) {\n if (process.env.NODE_ENV !== 'production') {\n logger.debug(`Workbox Router only supports URLs that start with 'http'.`);\n }\n return;\n }\n const { params, route } = this.findMatchingRoute({ url, request, event });\n let handler = route && route.handler;\n const debugMessages = [];\n if (process.env.NODE_ENV !== 'production') {\n if (handler) {\n debugMessages.push([\n `Found a route to handle this request:`, route,\n ]);\n if (params) {\n debugMessages.push([\n `Passing the following params to the route's handler:`, params,\n ]);\n }\n }\n }\n // If we don't have a handler because there was no matching route, then\n // fall back to defaultHandler if that's defined.\n if (!handler && this._defaultHandler) {\n if (process.env.NODE_ENV !== 'production') {\n debugMessages.push(`Failed to find a matching route. Falling ` +\n `back to the default handler.`);\n }\n handler = this._defaultHandler;\n }\n if (!handler) {\n if (process.env.NODE_ENV !== 'production') {\n // No handler so Workbox will do nothing. If logs is set of debug\n // i.e. verbose, we should print out this information.\n logger.debug(`No route found for: ${getFriendlyURL(url)}`);\n }\n return;\n }\n if (process.env.NODE_ENV !== 'production') {\n // We have a handler, meaning Workbox is going to handle the route.\n // print the routing details to the console.\n logger.groupCollapsed(`Router is responding to: ${getFriendlyURL(url)}`);\n debugMessages.forEach((msg) => {\n if (Array.isArray(msg)) {\n logger.log(...msg);\n }\n else {\n logger.log(msg);\n }\n });\n logger.groupEnd();\n }\n // Wrap in try and catch in case the handle method throws a synchronous\n // error. It should still callback to the catch handler.\n let responsePromise;\n try {\n responsePromise = handler.handle({ url, request, event, params });\n }\n catch (err) {\n responsePromise = Promise.reject(err);\n }\n if (responsePromise instanceof Promise && this._catchHandler) {\n responsePromise = responsePromise.catch((err) => {\n if (process.env.NODE_ENV !== 'production') {\n // Still include URL here as it will be async from the console group\n // and may not make sense without the URL\n logger.groupCollapsed(`Error thrown when responding to: ` +\n ` ${getFriendlyURL(url)}. Falling back to Catch Handler.`);\n logger.error(`Error thrown by:`, route);\n logger.error(err);\n logger.groupEnd();\n }\n return this._catchHandler.handle({ url, request, event });\n });\n }\n return responsePromise;\n }\n /**\n * Checks a request and URL (and optionally an event) against the list of\n * registered routes, and if there's a match, returns the corresponding\n * route along with any params generated by the match.\n *\n * @param {Object} options\n * @param {URL} options.url\n * @param {Request} options.request The request to match.\n * @param {Event} [options.event] The corresponding event (unless N/A).\n * @return {Object} An object with `route` and `params` properties.\n * They are populated if a matching route was found or `undefined`\n * otherwise.\n */\n findMatchingRoute({ url, request, event }) {\n if (process.env.NODE_ENV !== 'production') {\n assert.isInstance(url, URL, {\n moduleName: 'workbox-routing',\n className: 'Router',\n funcName: 'findMatchingRoute',\n paramName: 'options.url',\n });\n assert.isInstance(request, Request, {\n moduleName: 'workbox-routing',\n className: 'Router',\n funcName: 'findMatchingRoute',\n paramName: 'options.request',\n });\n }\n const routes = this._routes.get(request.method) || [];\n for (const route of routes) {\n let params;\n const matchResult = route.match({ url, request, event });\n if (matchResult) {\n // See https://github.com/GoogleChrome/workbox/issues/2079\n params = matchResult;\n if (Array.isArray(matchResult) && matchResult.length === 0) {\n // Instead of passing an empty array in as params, use undefined.\n params = undefined;\n }\n else if ((matchResult.constructor === Object &&\n Object.keys(matchResult).length === 0)) {\n // Instead of passing an empty object in as params, use undefined.\n params = undefined;\n }\n else if (typeof matchResult === 'boolean') {\n // For the boolean value true (rather than just something truth-y),\n // don't set params.\n // See https://github.com/GoogleChrome/workbox/pull/2134#issuecomment-513924353\n params = undefined;\n }\n // Return early if have a match.\n return { route, params };\n }\n }\n // If no match was found above, return and empty object.\n return {};\n }\n /**\n * Define a default `handler` that's called when no routes explicitly\n * match the incoming request.\n *\n * Without a default handler, unmatched requests will go against the\n * network as if there were no service worker present.\n *\n * @param {module:workbox-routing~handlerCallback} handler A callback\n * function that returns a Promise resulting in a Response.\n */\n setDefaultHandler(handler) {\n this._defaultHandler = normalizeHandler(handler);\n }\n /**\n * If a Route throws an error while handling a request, this `handler`\n * will be called and given a chance to provide a response.\n *\n * @param {module:workbox-routing~handlerCallback} handler A callback\n * function that returns a Promise resulting in a Response.\n */\n setCatchHandler(handler) {\n this._catchHandler = normalizeHandler(handler);\n }\n /**\n * Registers a route with the router.\n *\n * @param {module:workbox-routing.Route} route The route to register.\n */\n registerRoute(route) {\n if (process.env.NODE_ENV !== 'production') {\n assert.isType(route, 'object', {\n moduleName: 'workbox-routing',\n className: 'Router',\n funcName: 'registerRoute',\n paramName: 'route',\n });\n assert.hasMethod(route, 'match', {\n moduleName: 'workbox-routing',\n className: 'Router',\n funcName: 'registerRoute',\n paramName: 'route',\n });\n assert.isType(route.handler, 'object', {\n moduleName: 'workbox-routing',\n className: 'Router',\n funcName: 'registerRoute',\n paramName: 'route',\n });\n assert.hasMethod(route.handler, 'handle', {\n moduleName: 'workbox-routing',\n className: 'Router',\n funcName: 'registerRoute',\n paramName: 'route.handler',\n });\n assert.isType(route.method, 'string', {\n moduleName: 'workbox-routing',\n className: 'Router',\n funcName: 'registerRoute',\n paramName: 'route.method',\n });\n }\n if (!this._routes.has(route.method)) {\n this._routes.set(route.method, []);\n }\n // Give precedence to all of the earlier routes by adding this additional\n // route to the end of the array.\n this._routes.get(route.method).push(route);\n }\n /**\n * Unregisters a route with the router.\n *\n * @param {module:workbox-routing.Route} route The route to unregister.\n */\n unregisterRoute(route) {\n if (!this._routes.has(route.method)) {\n throw new WorkboxError('unregister-route-but-not-found-with-method', {\n method: route.method,\n });\n }\n const routeIndex = this._routes.get(route.method).indexOf(route);\n if (routeIndex > -1) {\n this._routes.get(route.method).splice(routeIndex, 1);\n }\n else {\n throw new WorkboxError('unregister-route-route-not-registered');\n }\n }\n}\nexport { Router };\n","/*\n Copyright 2019 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { Router } from '../Router.js';\nimport '../_version.js';\nlet defaultRouter;\n/**\n * Creates a new, singleton Router instance if one does not exist. If one\n * does already exist, that instance is returned.\n *\n * @private\n * @return {Router}\n */\nexport const getOrCreateDefaultRouter = () => {\n if (!defaultRouter) {\n defaultRouter = new Router();\n // The helpers that use the default Router assume these listeners exist.\n defaultRouter.addFetchListener();\n defaultRouter.addCacheListener();\n }\n return defaultRouter;\n};\n","/*\n Copyright 2019 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { logger } from 'workbox-core/_private/logger.js';\nimport { WorkboxError } from 'workbox-core/_private/WorkboxError.js';\nimport { Route } from './Route.js';\nimport { RegExpRoute } from './RegExpRoute.js';\nimport { getOrCreateDefaultRouter } from './utils/getOrCreateDefaultRouter.js';\nimport './_version.js';\n/**\n * Easily register a RegExp, string, or function with a caching\n * strategy to a singleton Router instance.\n *\n * This method will generate a Route for you if needed and\n * call [registerRoute()]{@link module:workbox-routing.Router#registerRoute}.\n *\n * @param {RegExp|string|module:workbox-routing.Route~matchCallback|module:workbox-routing.Route} capture\n * If the capture param is a `Route`, all other arguments will be ignored.\n * @param {module:workbox-routing~handlerCallback} [handler] A callback\n * function that returns a Promise resulting in a Response. This parameter\n * is required if `capture` is not a `Route` object.\n * @param {string} [method='GET'] The HTTP method to match the Route\n * against.\n * @return {module:workbox-routing.Route} The generated `Route`(Useful for\n * unregistering).\n *\n * @memberof module:workbox-routing\n */\nfunction registerRoute(capture, handler, method) {\n let route;\n if (typeof capture === 'string') {\n const captureUrl = new URL(capture, location.href);\n if (process.env.NODE_ENV !== 'production') {\n if (!(capture.startsWith('/') || capture.startsWith('http'))) {\n throw new WorkboxError('invalid-string', {\n moduleName: 'workbox-routing',\n funcName: 'registerRoute',\n paramName: 'capture',\n });\n }\n // We want to check if Express-style wildcards are in the pathname only.\n // TODO: Remove this log message in v4.\n const valueToCheck = capture.startsWith('http') ?\n captureUrl.pathname : capture;\n // See https://github.com/pillarjs/path-to-regexp#parameters\n const wildcards = '[*:?+]';\n if ((new RegExp(`${wildcards}`)).exec(valueToCheck)) {\n logger.debug(`The '$capture' parameter contains an Express-style wildcard ` +\n `character (${wildcards}). Strings are now always interpreted as ` +\n `exact matches; use a RegExp for partial or wildcard matches.`);\n }\n }\n const matchCallback = ({ url }) => {\n if (process.env.NODE_ENV !== 'production') {\n if ((url.pathname === captureUrl.pathname) &&\n (url.origin !== captureUrl.origin)) {\n logger.debug(`${capture} only partially matches the cross-origin URL ` +\n `${url}. This route will only handle cross-origin requests ` +\n `if they match the entire URL.`);\n }\n }\n return url.href === captureUrl.href;\n };\n // If `capture` is a string then `handler` and `method` must be present.\n route = new Route(matchCallback, handler, method);\n }\n else if (capture instanceof RegExp) {\n // If `capture` is a `RegExp` then `handler` and `method` must be present.\n route = new RegExpRoute(capture, handler, method);\n }\n else if (typeof capture === 'function') {\n // If `capture` is a function then `handler` and `method` must be present.\n route = new Route(capture, handler, method);\n }\n else if (capture instanceof Route) {\n route = capture;\n }\n else {\n throw new WorkboxError('unsupported-route-type', {\n moduleName: 'workbox-routing',\n funcName: 'registerRoute',\n paramName: 'capture',\n });\n }\n const defaultRouter = getOrCreateDefaultRouter();\n defaultRouter.registerRoute(route);\n return route;\n}\nexport { registerRoute };\n","/*\n Copyright 2019 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { getOrCreateDefaultRouter } from './utils/getOrCreateDefaultRouter.js';\nimport './_version.js';\n/**\n * If a Route throws an error while handling a request, this `handler`\n * will be called and given a chance to provide a response.\n *\n * @param {module:workbox-routing~handlerCallback} handler A callback\n * function that returns a Promise resulting in a Response.\n *\n * @memberof module:workbox-routing\n */\nfunction setCatchHandler(handler) {\n const defaultRouter = getOrCreateDefaultRouter();\n defaultRouter.setCatchHandler(handler);\n}\nexport { setCatchHandler };\n","/*\n Copyright 2019 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { getOrCreateDefaultRouter } from './utils/getOrCreateDefaultRouter.js';\nimport './_version.js';\n/**\n * Define a default `handler` that's called when no routes explicitly\n * match the incoming request.\n *\n * Without a default handler, unmatched requests will go against the\n * network as if there were no service worker present.\n *\n * @param {module:workbox-routing~handlerCallback} handler A callback\n * function that returns a Promise resulting in a Response.\n *\n * @memberof module:workbox-routing\n */\nfunction setDefaultHandler(handler) {\n const defaultRouter = getOrCreateDefaultRouter();\n defaultRouter.setDefaultHandler(handler);\n}\nexport { setDefaultHandler };\n"],"names":["self","_","e","defaultMethod","validMethods","normalizeHandler","handler","assert","hasMethod","moduleName","className","funcName","paramName","isType","handle","Route","constructor","match","method","isOneOf","NavigationRoute","allowlist","denylist","isArrayOfClass","RegExp","options","_match","_allowlist","_denylist","url","request","mode","pathnameAndSearch","pathname","search","regExp","test","logger","log","some","debug","RegExpRoute","isInstance","result","exec","href","origin","location","index","slice","Router","_routes","Map","routes","addFetchListener","addEventListener","event","responsePromise","handleRequest","respondWith","addCacheListener","data","type","payload","urlsToCache","requestPromises","Promise","all","map","entry","Request","waitUntil","ports","then","postMessage","URL","protocol","startsWith","params","route","findMatchingRoute","debugMessages","push","_defaultHandler","getFriendlyURL","groupCollapsed","forEach","msg","Array","isArray","groupEnd","err","reject","_catchHandler","catch","error","get","matchResult","length","undefined","Object","keys","setDefaultHandler","setCatchHandler","registerRoute","has","set","unregisterRoute","WorkboxError","routeIndex","indexOf","splice","defaultRouter","getOrCreateDefaultRouter","capture","captureUrl","valueToCheck","wildcards","matchCallback"],"mappings":";;;;IAEA,IAAI;IACAA,EAAAA,IAAI,CAAC,uBAAD,CAAJ,IAAiCC,CAAC,EAAlC;IACH,CAFD,CAGA,OAAOC,CAAP,EAAU;;ICLV;;;;;;;AAOA,IACA;;;;;;;;;AAQA,IAAO,MAAMC,aAAa,GAAG,KAAtB;IACP;;;;;;;;AAOA,IAAO,MAAMC,YAAY,GAAG,CACxB,QADwB,EAExB,KAFwB,EAGxB,MAHwB,EAIxB,OAJwB,EAKxB,MALwB,EAMxB,KANwB,CAArB;;ICxBP;;;;;;;AAOA,IAEA;;;;;;;;AAOA,IAAO,MAAMC,gBAAgB,GAAIC,OAAD,IAAa;IACzC,MAAIA,OAAO,IAAI,OAAOA,OAAP,KAAmB,QAAlC,EAA4C;IACxC,IAA2C;IACvCC,MAAAA,gBAAM,CAACC,SAAP,CAAiBF,OAAjB,EAA0B,QAA1B,EAAoC;IAChCG,QAAAA,UAAU,EAAE,iBADoB;IAEhCC,QAAAA,SAAS,EAAE,OAFqB;IAGhCC,QAAAA,QAAQ,EAAE,aAHsB;IAIhCC,QAAAA,SAAS,EAAE;IAJqB,OAApC;IAMH;;IACD,WAAON,OAAP;IACH,GAVD,MAWK;IACD,IAA2C;IACvCC,MAAAA,gBAAM,CAACM,MAAP,CAAcP,OAAd,EAAuB,UAAvB,EAAmC;IAC/BG,QAAAA,UAAU,EAAE,iBADmB;IAE/BC,QAAAA,SAAS,EAAE,OAFoB;IAG/BC,QAAA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;;;"}
|
@@ -0,0 +1,2 @@
|
|
1
|
+
this.workbox=this.workbox||{},this.workbox.routing=function(t,e){"use strict";try{self["workbox:routing:5.1.4"]&&_()}catch(t){}const s=t=>t&&"object"==typeof t?t:{handle:t};class r{constructor(t,e,r="GET"){this.handler=s(e),this.match=t,this.method=r}}class n extends r{constructor(t,e,s){super(({url:e})=>{const s=t.exec(e.href);if(s&&(e.origin===location.origin||0===s.index))return s.slice(1)},e,s)}}class o{constructor(){this.t=new Map}get routes(){return this.t}addFetchListener(){self.addEventListener("fetch",t=>{const{request:e}=t,s=this.handleRequest({request:e,event:t});s&&t.respondWith(s)})}addCacheListener(){self.addEventListener("message",t=>{if(t.data&&"CACHE_URLS"===t.data.type){const{payload:e}=t.data,s=Promise.all(e.urlsToCache.map(t=>{"string"==typeof t&&(t=[t]);const e=new Request(...t);return this.handleRequest({request:e})}));t.waitUntil(s),t.ports&&t.ports[0]&&s.then(()=>t.ports[0].postMessage(!0))}})}handleRequest({request:t,event:e}){const s=new URL(t.url,location.href);if(!s.protocol.startsWith("http"))return;const{params:r,route:n}=this.findMatchingRoute({url:s,request:t,event:e});let o,i=n&&n.handler;if(!i&&this.s&&(i=this.s),i){try{o=i.handle({url:s,request:t,event:e,params:r})}catch(t){o=Promise.reject(t)}return o instanceof Promise&&this.o&&(o=o.catch(r=>this.o.handle({url:s,request:t,event:e}))),o}}findMatchingRoute({url:t,request:e,event:s}){const r=this.t.get(e.method)||[];for(const n of r){let r;const o=n.match({url:t,request:e,event:s});if(o)return r=o,(Array.isArray(o)&&0===o.length||o.constructor===Object&&0===Object.keys(o).length||"boolean"==typeof o)&&(r=void 0),{route:n,params:r}}return{}}setDefaultHandler(t){this.s=s(t)}setCatchHandler(t){this.o=s(t)}registerRoute(t){this.t.has(t.method)||this.t.set(t.method,[]),this.t.get(t.method).push(t)}unregisterRoute(t){if(!this.t.has(t.method))throw new e.WorkboxError("unregister-route-but-not-found-with-method",{method:t.method});const s=this.t.get(t.method).indexOf(t);if(!(s>-1))throw new e.WorkboxError("unregister-route-route-not-registered");this.t.get(t.method).splice(s,1)}}let i;const u=()=>(i||(i=new o,i.addFetchListener(),i.addCacheListener()),i);return t.NavigationRoute=class extends r{constructor(t,{allowlist:e=[/./],denylist:s=[]}={}){super(t=>this.i(t),t),this.u=e,this.h=s}i({url:t,request:e}){if(e&&"navigate"!==e.mode)return!1;const s=t.pathname+t.search;for(const t of this.h)if(t.test(s))return!1;return!!this.u.some(t=>t.test(s))}},t.RegExpRoute=n,t.Route=r,t.Router=o,t.registerRoute=function(t,s,o){let i;if("string"==typeof t){const e=new URL(t,location.href);i=new r(({url:t})=>t.href===e.href,s,o)}else if(t instanceof RegExp)i=new n(t,s,o);else if("function"==typeof t)i=new r(t,s,o);else{if(!(t instanceof r))throw new e.WorkboxError("unsupported-route-type",{moduleName:"workbox-routing",funcName:"registerRoute",paramName:"capture"});i=t}return u().registerRoute(i),i},t.setCatchHandler=function(t){u().setCatchHandler(t)},t.setDefaultHandler=function(t){u().setDefaultHandler(t)},t}({},workbox.core._private);
|
2
|
+
//# sourceMappingURL=workbox-routing.prod.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"workbox-routing.prod.js","sources":["../_version.js","../utils/constants.js","../utils/normalizeHandler.js","../Route.js","../RegExpRoute.js","../Router.js","../utils/getOrCreateDefaultRouter.js","../NavigationRoute.js","../registerRoute.js","../setCatchHandler.js","../setDefaultHandler.js"],"sourcesContent":["\"use strict\";\n// @ts-ignore\ntry {\n self['workbox:routing:5.1.4'] && _();\n}\ncatch (e) { }\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport '../_version.js';\n/**\n * The default HTTP method, 'GET', used when there's no specific method\n * configured for a route.\n *\n * @type {string}\n *\n * @private\n */\nexport const defaultMethod = 'GET';\n/**\n * The list of valid HTTP methods associated with requests that could be routed.\n *\n * @type {Array<string>}\n *\n * @private\n */\nexport const validMethods = [\n 'DELETE',\n 'GET',\n 'HEAD',\n 'PATCH',\n 'POST',\n 'PUT',\n];\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { assert } from 'workbox-core/_private/assert.js';\nimport '../_version.js';\n/**\n * @param {function()|Object} handler Either a function, or an object with a\n * 'handle' method.\n * @return {Object} An object with a handle method.\n *\n * @private\n */\nexport const normalizeHandler = (handler) => {\n if (handler && typeof handler === 'object') {\n if (process.env.NODE_ENV !== 'production') {\n assert.hasMethod(handler, 'handle', {\n moduleName: 'workbox-routing',\n className: 'Route',\n funcName: 'constructor',\n paramName: 'handler',\n });\n }\n return handler;\n }\n else {\n if (process.env.NODE_ENV !== 'production') {\n assert.isType(handler, 'function', {\n moduleName: 'workbox-routing',\n className: 'Route',\n funcName: 'constructor',\n paramName: 'handler',\n });\n }\n return { handle: handler };\n }\n};\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { assert } from 'workbox-core/_private/assert.js';\nimport { defaultMethod, validMethods } from './utils/constants.js';\nimport { normalizeHandler } from './utils/normalizeHandler.js';\nimport './_version.js';\n/**\n * A `Route` consists of a pair of callback functions, \"match\" and \"handler\".\n * The \"match\" callback determine if a route should be used to \"handle\" a\n * request by returning a non-falsy value if it can. The \"handler\" callback\n * is called when there is a match and should return a Promise that resolves\n * to a `Response`.\n *\n * @memberof module:workbox-routing\n */\nclass Route {\n /**\n * Constructor for Route class.\n *\n * @param {module:workbox-routing~matchCallback} match\n * A callback function that determines whether the route matches a given\n * `fetch` event by returning a non-falsy value.\n * @param {module:workbox-routing~handlerCallback} handler A callback\n * function that returns a Promise resolving to a Response.\n * @param {string} [method='GET'] The HTTP method to match the Route\n * against.\n */\n constructor(match, handler, method = defaultMethod) {\n if (process.env.NODE_ENV !== 'production') {\n assert.isType(match, 'function', {\n moduleName: 'workbox-routing',\n className: 'Route',\n funcName: 'constructor',\n paramName: 'match',\n });\n if (method) {\n assert.isOneOf(method, validMethods, { paramName: 'method' });\n }\n }\n // These values are referenced directly by Router so cannot be\n // altered by minificaton.\n this.handler = normalizeHandler(handler);\n this.match = match;\n this.method = method;\n }\n}\nexport { Route };\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { assert } from 'workbox-core/_private/assert.js';\nimport { logger } from 'workbox-core/_private/logger.js';\nimport { Route } from './Route.js';\nimport './_version.js';\n/**\n * RegExpRoute makes it easy to create a regular expression based\n * [Route]{@link module:workbox-routing.Route}.\n *\n * For same-origin requests the RegExp only needs to match part of the URL. For\n * requests against third-party servers, you must define a RegExp that matches\n * the start of the URL.\n *\n * [See the module docs for info.]{@link https://developers.google.com/web/tools/workbox/modules/workbox-routing}\n *\n * @memberof module:workbox-routing\n * @extends module:workbox-routing.Route\n */\nclass RegExpRoute extends Route {\n /**\n * If the regular expression contains\n * [capture groups]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#grouping-back-references},\n * the captured values will be passed to the\n * [handler's]{@link module:workbox-routing~handlerCallback} `params`\n * argument.\n *\n * @param {RegExp} regExp The regular expression to match against URLs.\n * @param {module:workbox-routing~handlerCallback} handler A callback\n * function that returns a Promise resulting in a Response.\n * @param {string} [method='GET'] The HTTP method to match the Route\n * against.\n */\n constructor(regExp, handler, method) {\n if (process.env.NODE_ENV !== 'production') {\n assert.isInstance(regExp, RegExp, {\n moduleName: 'workbox-routing',\n className: 'RegExpRoute',\n funcName: 'constructor',\n paramName: 'pattern',\n });\n }\n const match = ({ url }) => {\n const result = regExp.exec(url.href);\n // Return immediately if there's no match.\n if (!result) {\n return;\n }\n // Require that the match start at the first character in the URL string\n // if it's a cross-origin request.\n // See https://github.com/GoogleChrome/workbox/issues/281 for the context\n // behind this behavior.\n if ((url.origin !== location.origin) && (result.index !== 0)) {\n if (process.env.NODE_ENV !== 'production') {\n logger.debug(`The regular expression '${regExp}' only partially matched ` +\n `against the cross-origin URL '${url}'. RegExpRoute's will only ` +\n `handle cross-origin requests if they match the entire URL.`);\n }\n return;\n }\n // If the route matches, but there aren't any capture groups defined, then\n // this will return [], which is truthy and therefore sufficient to\n // indicate a match.\n // If there are capture groups, then it will return their values.\n return result.slice(1);\n };\n super(match, handler, method);\n }\n}\nexport { RegExpRoute };\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { assert } from 'workbox-core/_private/assert.js';\nimport { logger } from 'workbox-core/_private/logger.js';\nimport { WorkboxError } from 'workbox-core/_private/WorkboxError.js';\nimport { getFriendlyURL } from 'workbox-core/_private/getFriendlyURL.js';\nimport { normalizeHandler } from './utils/normalizeHandler.js';\nimport './_version.js';\n/**\n * The Router can be used to process a FetchEvent through one or more\n * [Routes]{@link module:workbox-routing.Route} responding with a Request if\n * a matching route exists.\n *\n * If no route matches a given a request, the Router will use a \"default\"\n * handler if one is defined.\n *\n * Should the matching Route throw an error, the Router will use a \"catch\"\n * handler if one is defined to gracefully deal with issues and respond with a\n * Request.\n *\n * If a request matches multiple routes, the **earliest** registered route will\n * be used to respond to the request.\n *\n * @memberof module:workbox-routing\n */\nclass Router {\n /**\n * Initializes a new Router.\n */\n constructor() {\n this._routes = new Map();\n }\n /**\n * @return {Map<string, Array<module:workbox-routing.Route>>} routes A `Map` of HTTP\n * method name ('GET', etc.) to an array of all the corresponding `Route`\n * instances that are registered.\n */\n get routes() {\n return this._routes;\n }\n /**\n * Adds a fetch event listener to respond to events when a route matches\n * the event's request.\n */\n addFetchListener() {\n // See https://github.com/Microsoft/TypeScript/issues/28357#issuecomment-436484705\n self.addEventListener('fetch', ((event) => {\n const { request } = event;\n const responsePromise = this.handleRequest({ request, event });\n if (responsePromise) {\n event.respondWith(responsePromise);\n }\n }));\n }\n /**\n * Adds a message event listener for URLs to cache from the window.\n * This is useful to cache resources loaded on the page prior to when the\n * service worker started controlling it.\n *\n * The format of the message data sent from the window should be as follows.\n * Where the `urlsToCache` array may consist of URL strings or an array of\n * URL string + `requestInit` object (the same as you'd pass to `fetch()`).\n *\n * ```\n * {\n * type: 'CACHE_URLS',\n * payload: {\n * urlsToCache: [\n * './script1.js',\n * './script2.js',\n * ['./script3.js', {mode: 'no-cors'}],\n * ],\n * },\n * }\n * ```\n */\n addCacheListener() {\n // See https://github.com/Microsoft/TypeScript/issues/28357#issuecomment-436484705\n self.addEventListener('message', ((event) => {\n if (event.data && event.data.type === 'CACHE_URLS') {\n const { payload } = event.data;\n if (process.env.NODE_ENV !== 'production') {\n logger.debug(`Caching URLs from the window`, payload.urlsToCache);\n }\n const requestPromises = Promise.all(payload.urlsToCache.map((entry) => {\n if (typeof entry === 'string') {\n entry = [entry];\n }\n const request = new Request(...entry);\n return this.handleRequest({ request });\n // TODO(philipwalton): TypeScript errors without this typecast for\n // some reason (probably a bug). The real type here should work but\n // doesn't: `Array<Promise<Response> | undefined>`.\n })); // TypeScript\n event.waitUntil(requestPromises);\n // If a MessageChannel was used, reply to the message on success.\n if (event.ports && event.ports[0]) {\n requestPromises.then(() => event.ports[0].postMessage(true));\n }\n }\n }));\n }\n /**\n * Apply the routing rules to a FetchEvent object to get a Response from an\n * appropriate Route's handler.\n *\n * @param {Object} options\n * @param {Request} options.request The request to handle (this is usually\n * from a fetch event, but it does not have to be).\n * @param {FetchEvent} [options.event] The event that triggered the request,\n * if applicable.\n * @return {Promise<Response>|undefined} A promise is returned if a\n * registered route can handle the request. If there is no matching\n * route and there's no `defaultHandler`, `undefined` is returned.\n */\n handleRequest({ request, event }) {\n if (process.env.NODE_ENV !== 'production') {\n assert.isInstance(request, Request, {\n moduleName: 'workbox-routing',\n className: 'Router',\n funcName: 'handleRequest',\n paramName: 'options.request',\n });\n }\n const url = new URL(request.url, location.href);\n if (!url.protocol.startsWith('http')) {\n if (process.env.NODE_ENV !== 'production') {\n logger.debug(`Workbox Router only supports URLs that start with 'http'.`);\n }\n return;\n }\n const { params, route } = this.findMatchingRoute({ url, request, event });\n let handler = route && route.handler;\n const debugMessages = [];\n if (process.env.NODE_ENV !== 'production') {\n if (handler) {\n debugMessages.push([\n `Found a route to handle this request:`, route,\n ]);\n if (params) {\n debugMessages.push([\n `Passing the following params to the route's handler:`, params,\n ]);\n }\n }\n }\n // If we don't have a handler because there was no matching route, then\n // fall back to defaultHandler if that's defined.\n if (!handler && this._defaultHandler) {\n if (process.env.NODE_ENV !== 'production') {\n debugMessages.push(`Failed to find a matching route. Falling ` +\n `back to the default handler.`);\n }\n handler = this._defaultHandler;\n }\n if (!handler) {\n if (process.env.NODE_ENV !== 'production') {\n // No handler so Workbox will do nothing. If logs is set of debug\n // i.e. verbose, we should print out this information.\n logger.debug(`No route found for: ${getFriendlyURL(url)}`);\n }\n return;\n }\n if (process.env.NODE_ENV !== 'production') {\n // We have a handler, meaning Workbox is going to handle the route.\n // print the routing details to the console.\n logger.groupCollapsed(`Router is responding to: ${getFriendlyURL(url)}`);\n debugMessages.forEach((msg) => {\n if (Array.isArray(msg)) {\n logger.log(...msg);\n }\n else {\n logger.log(msg);\n }\n });\n logger.groupEnd();\n }\n // Wrap in try and catch in case the handle method throws a synchronous\n // error. It should still callback to the catch handler.\n let responsePromise;\n try {\n responsePromise = handler.handle({ url, request, event, params });\n }\n catch (err) {\n responsePromise = Promise.reject(err);\n }\n if (responsePromise instanceof Promise && this._catchHandler) {\n responsePromise = responsePromise.catch((err) => {\n if (process.env.NODE_ENV !== 'production') {\n // Still include URL here as it will be async from the console group\n // and may not make sense without the URL\n logger.groupCollapsed(`Error thrown when responding to: ` +\n ` ${getFriendlyURL(url)}. Falling back to Catch Handler.`);\n logger.error(`Error thrown by:`, route);\n logger.error(err);\n logger.groupEnd();\n }\n return this._catchHandler.handle({ url, request, event });\n });\n }\n return responsePromise;\n }\n /**\n * Checks a request and URL (and optionally an event) against the list of\n * registered routes, and if there's a match, returns the corresponding\n * route along with any params generated by the match.\n *\n * @param {Object} options\n * @param {URL} options.url\n * @param {Request} options.request The request to match.\n * @param {Event} [options.event] The corresponding event (unless N/A).\n * @return {Object} An object with `route` and `params` properties.\n * They are populated if a matching route was found or `undefined`\n * otherwise.\n */\n findMatchingRoute({ url, request, event }) {\n if (process.env.NODE_ENV !== 'production') {\n assert.isInstance(url, URL, {\n moduleName: 'workbox-routing',\n className: 'Router',\n funcName: 'findMatchingRoute',\n paramName: 'options.url',\n });\n assert.isInstance(request, Request, {\n moduleName: 'workbox-routing',\n className: 'Router',\n funcName: 'findMatchingRoute',\n paramName: 'options.request',\n });\n }\n const routes = this._routes.get(request.method) || [];\n for (const route of routes) {\n let params;\n const matchResult = route.match({ url, request, event });\n if (matchResult) {\n // See https://github.com/GoogleChrome/workbox/issues/2079\n params = matchResult;\n if (Array.isArray(matchResult) && matchResult.length === 0) {\n // Instead of passing an empty array in as params, use undefined.\n params = undefined;\n }\n else if ((matchResult.constructor === Object &&\n Object.keys(matchResult).length === 0)) {\n // Instead of passing an empty object in as params, use undefined.\n params = undefined;\n }\n else if (typeof matchResult === 'boolean') {\n // For the boolean value true (rather than just something truth-y),\n // don't set params.\n // See https://github.com/GoogleChrome/workbox/pull/2134#issuecomment-513924353\n params = undefined;\n }\n // Return early if have a match.\n return { route, params };\n }\n }\n // If no match was found above, return and empty object.\n return {};\n }\n /**\n * Define a default `handler` that's called when no routes explicitly\n * match the incoming request.\n *\n * Without a default handler, unmatched requests will go against the\n * network as if there were no service worker present.\n *\n * @param {module:workbox-routing~handlerCallback} handler A callback\n * function that returns a Promise resulting in a Response.\n */\n setDefaultHandler(handler) {\n this._defaultHandler = normalizeHandler(handler);\n }\n /**\n * If a Route throws an error while handling a request, this `handler`\n * will be called and given a chance to provide a response.\n *\n * @param {module:workbox-routing~handlerCallback} handler A callback\n * function that returns a Promise resulting in a Response.\n */\n setCatchHandler(handler) {\n this._catchHandler = normalizeHandler(handler);\n }\n /**\n * Registers a route with the router.\n *\n * @param {module:workbox-routing.Route} route The route to register.\n */\n registerRoute(route) {\n if (process.env.NODE_ENV !== 'production') {\n assert.isType(route, 'object', {\n moduleName: 'workbox-routing',\n className: 'Router',\n funcName: 'registerRoute',\n paramName: 'route',\n });\n assert.hasMethod(route, 'match', {\n moduleName: 'workbox-routing',\n className: 'Router',\n funcName: 'registerRoute',\n paramName: 'route',\n });\n assert.isType(route.handler, 'object', {\n moduleName: 'workbox-routing',\n className: 'Router',\n funcName: 'registerRoute',\n paramName: 'route',\n });\n assert.hasMethod(route.handler, 'handle', {\n moduleName: 'workbox-routing',\n className: 'Router',\n funcName: 'registerRoute',\n paramName: 'route.handler',\n });\n assert.isType(route.method, 'string', {\n moduleName: 'workbox-routing',\n className: 'Router',\n funcName: 'registerRoute',\n paramName: 'route.method',\n });\n }\n if (!this._routes.has(route.method)) {\n this._routes.set(route.method, []);\n }\n // Give precedence to all of the earlier routes by adding this additional\n // route to the end of the array.\n this._routes.get(route.method).push(route);\n }\n /**\n * Unregisters a route with the router.\n *\n * @param {module:workbox-routing.Route} route The route to unregister.\n */\n unregisterRoute(route) {\n if (!this._routes.has(route.method)) {\n throw new WorkboxError('unregister-route-but-not-found-with-method', {\n method: route.method,\n });\n }\n const routeIndex = this._routes.get(route.method).indexOf(route);\n if (routeIndex > -1) {\n this._routes.get(route.method).splice(routeIndex, 1);\n }\n else {\n throw new WorkboxError('unregister-route-route-not-registered');\n }\n }\n}\nexport { Router };\n","/*\n Copyright 2019 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { Router } from '../Router.js';\nimport '../_version.js';\nlet defaultRouter;\n/**\n * Creates a new, singleton Router instance if one does not exist. If one\n * does already exist, that instance is returned.\n *\n * @private\n * @return {Router}\n */\nexport const getOrCreateDefaultRouter = () => {\n if (!defaultRouter) {\n defaultRouter = new Router();\n // The helpers that use the default Router assume these listeners exist.\n defaultRouter.addFetchListener();\n defaultRouter.addCacheListener();\n }\n return defaultRouter;\n};\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { assert } from 'workbox-core/_private/assert.js';\nimport { logger } from 'workbox-core/_private/logger.js';\nimport { Route } from './Route.js';\nimport './_version.js';\n/**\n * NavigationRoute makes it easy to create a\n * [Route]{@link module:workbox-routing.Route} that matches for browser\n * [navigation requests]{@link https://developers.google.com/web/fundamentals/primers/service-workers/high-performance-loading#first_what_are_navigation_requests}.\n *\n * It will only match incoming Requests whose\n * [`mode`]{@link https://fetch.spec.whatwg.org/#concept-request-mode}\n * is set to `navigate`.\n *\n * You can optionally only apply this route to a subset of navigation requests\n * by using one or both of the `denylist` and `allowlist` parameters.\n *\n * @memberof module:workbox-routing\n * @extends module:workbox-routing.Route\n */\nclass NavigationRoute extends Route {\n /**\n * If both `denylist` and `allowlist` are provided, the `denylist` will\n * take precedence and the request will not match this route.\n *\n * The regular expressions in `allowlist` and `denylist`\n * are matched against the concatenated\n * [`pathname`]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLHyperlinkElementUtils/pathname}\n * and [`search`]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLHyperlinkElementUtils/search}\n * portions of the requested URL.\n *\n * @param {module:workbox-routing~handlerCallback} handler A callback\n * function that returns a Promise resulting in a Response.\n * @param {Object} options\n * @param {Array<RegExp>} [options.denylist] If any of these patterns match,\n * the route will not handle the request (even if a allowlist RegExp matches).\n * @param {Array<RegExp>} [options.allowlist=[/./]] If any of these patterns\n * match the URL's pathname and search parameter, the route will handle the\n * request (assuming the denylist doesn't match).\n */\n constructor(handler, { allowlist = [/./], denylist = [] } = {}) {\n if (process.env.NODE_ENV !== 'production') {\n assert.isArrayOfClass(allowlist, RegExp, {\n moduleName: 'workbox-routing',\n className: 'NavigationRoute',\n funcName: 'constructor',\n paramName: 'options.allowlist',\n });\n assert.isArrayOfClass(denylist, RegExp, {\n moduleName: 'workbox-routing',\n className: 'NavigationRoute',\n funcName: 'constructor',\n paramName: 'options.denylist',\n });\n }\n super((options) => this._match(options), handler);\n this._allowlist = allowlist;\n this._denylist = denylist;\n }\n /**\n * Routes match handler.\n *\n * @param {Object} options\n * @param {URL} options.url\n * @param {Request} options.request\n * @return {boolean}\n *\n * @private\n */\n _match({ url, request }) {\n if (request && request.mode !== 'navigate') {\n return false;\n }\n const pathnameAndSearch = url.pathname + url.search;\n for (const regExp of this._denylist) {\n if (regExp.test(pathnameAndSearch)) {\n if (process.env.NODE_ENV !== 'production') {\n logger.log(`The navigation route ${pathnameAndSearch} is not ` +\n `being used, since the URL matches this denylist pattern: ` +\n `${regExp}`);\n }\n return false;\n }\n }\n if (this._allowlist.some((regExp) => regExp.test(pathnameAndSearch))) {\n if (process.env.NODE_ENV !== 'production') {\n logger.debug(`The navigation route ${pathnameAndSearch} ` +\n `is being used.`);\n }\n return true;\n }\n if (process.env.NODE_ENV !== 'production') {\n logger.log(`The navigation route ${pathnameAndSearch} is not ` +\n `being used, since the URL being navigated to doesn't ` +\n `match the allowlist.`);\n }\n return false;\n }\n}\nexport { NavigationRoute };\n","/*\n Copyright 2019 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { logger } from 'workbox-core/_private/logger.js';\nimport { WorkboxError } from 'workbox-core/_private/WorkboxError.js';\nimport { Route } from './Route.js';\nimport { RegExpRoute } from './RegExpRoute.js';\nimport { getOrCreateDefaultRouter } from './utils/getOrCreateDefaultRouter.js';\nimport './_version.js';\n/**\n * Easily register a RegExp, string, or function with a caching\n * strategy to a singleton Router instance.\n *\n * This method will generate a Route for you if needed and\n * call [registerRoute()]{@link module:workbox-routing.Router#registerRoute}.\n *\n * @param {RegExp|string|module:workbox-routing.Route~matchCallback|module:workbox-routing.Route} capture\n * If the capture param is a `Route`, all other arguments will be ignored.\n * @param {module:workbox-routing~handlerCallback} [handler] A callback\n * function that returns a Promise resulting in a Response. This parameter\n * is required if `capture` is not a `Route` object.\n * @param {string} [method='GET'] The HTTP method to match the Route\n * against.\n * @return {module:workbox-routing.Route} The generated `Route`(Useful for\n * unregistering).\n *\n * @memberof module:workbox-routing\n */\nfunction registerRoute(capture, handler, method) {\n let route;\n if (typeof capture === 'string') {\n const captureUrl = new URL(capture, location.href);\n if (process.env.NODE_ENV !== 'production') {\n if (!(capture.startsWith('/') || capture.startsWith('http'))) {\n throw new WorkboxError('invalid-string', {\n moduleName: 'workbox-routing',\n funcName: 'registerRoute',\n paramName: 'capture',\n });\n }\n // We want to check if Express-style wildcards are in the pathname only.\n // TODO: Remove this log message in v4.\n const valueToCheck = capture.startsWith('http') ?\n captureUrl.pathname : capture;\n // See https://github.com/pillarjs/path-to-regexp#parameters\n const wildcards = '[*:?+]';\n if ((new RegExp(`${wildcards}`)).exec(valueToCheck)) {\n logger.debug(`The '$capture' parameter contains an Express-style wildcard ` +\n `character (${wildcards}). Strings are now always interpreted as ` +\n `exact matches; use a RegExp for partial or wildcard matches.`);\n }\n }\n const matchCallback = ({ url }) => {\n if (process.env.NODE_ENV !== 'production') {\n if ((url.pathname === captureUrl.pathname) &&\n (url.origin !== captureUrl.origin)) {\n logger.debug(`${capture} only partially matches the cross-origin URL ` +\n `${url}. This route will only handle cross-origin requests ` +\n `if they match the entire URL.`);\n }\n }\n return url.href === captureUrl.href;\n };\n // If `capture` is a string then `handler` and `method` must be present.\n route = new Route(matchCallback, handler, method);\n }\n else if (capture instanceof RegExp) {\n // If `capture` is a `RegExp` then `handler` and `method` must be present.\n route = new RegExpRoute(capture, handler, method);\n }\n else if (typeof capture === 'function') {\n // If `capture` is a function then `handler` and `method` must be present.\n route = new Route(capture, handler, method);\n }\n else if (capture instanceof Route) {\n route = capture;\n }\n else {\n throw new WorkboxError('unsupported-route-type', {\n moduleName: 'workbox-routing',\n funcName: 'registerRoute',\n paramName: 'capture',\n });\n }\n const defaultRouter = getOrCreateDefaultRouter();\n defaultRouter.registerRoute(route);\n return route;\n}\nexport { registerRoute };\n","/*\n Copyright 2019 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { getOrCreateDefaultRouter } from './utils/getOrCreateDefaultRouter.js';\nimport './_version.js';\n/**\n * If a Route throws an error while handling a request, this `handler`\n * will be called and given a chance to provide a response.\n *\n * @param {module:workbox-routing~handlerCallback} handler A callback\n * function that returns a Promise resulting in a Response.\n *\n * @memberof module:workbox-routing\n */\nfunction setCatchHandler(handler) {\n const defaultRouter = getOrCreateDefaultRouter();\n defaultRouter.setCatchHandler(handler);\n}\nexport { setCatchHandler };\n","/*\n Copyright 2019 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport { getOrCreateDefaultRouter } from './utils/getOrCreateDefaultRouter.js';\nimport './_version.js';\n/**\n * Define a default `handler` that's called when no routes explicitly\n * match the incoming request.\n *\n * Without a default handler, unmatched requests will go against the\n * network as if there were no service worker present.\n *\n * @param {module:workbox-routing~handlerCallback} handler A callback\n * function that returns a Promise resulting in a Response.\n *\n * @memberof module:workbox-routing\n */\nfunction setDefaultHandler(handler) {\n const defaultRouter = getOrCreateDefaultRouter();\n defaultRouter.setDefaultHandler(handler);\n}\nexport { setDefaultHandler };\n"],"names":["self","_","e","normalizeHandler","handler","handle","Route","constructor","match","method","RegExpRoute","regExp","url","result","exec","href","origin","location","index","slice","Router","_routes","Map","this","addFetchListener","addEventListener","event","request","responsePromise","handleRequest","respondWith","addCacheListener","data","type","payload","requestPromises","Promise","all","urlsToCache","map","entry","Request","waitUntil","ports","then","postMessage","URL","protocol","startsWith","params","route","findMatchingRoute","_defaultHandler","err","reject","_catchHandler","catch","routes","get","matchResult","Array","isArray","length","Object","keys","undefined","setDefaultHandler","setCatchHandler","registerRoute","has","set","push","unregisterRoute","WorkboxError","routeIndex","indexOf","splice","defaultRouter","getOrCreateDefaultRouter","allowlist","denylist","options","_match","_allowlist","_denylist","mode","pathnameAndSearch","pathname","search","test","some","capture","captureUrl","RegExp","moduleName","funcName","paramName"],"mappings":"8EAEA,IACIA,KAAK,0BAA4BC,IAErC,MAAOC,ICWA,MCAMC,EAAoBC,GACzBA,GAA8B,iBAAZA,EASXA,EAWA,CAAEC,OAAQD,GCjBzB,MAAME,EAYFC,YAAYC,EAAOJ,EAASK,EFhBH,YE8BhBL,QAAUD,EAAiBC,QAC3BI,MAAQA,OACRC,OAASA,GCxBtB,MAAMC,UAAoBJ,EActBC,YAAYI,EAAQP,EAASK,SASX,EAAGG,IAAAA,YACPC,EAASF,EAAOG,KAAKF,EAAIG,SAE1BF,IAOAD,EAAII,SAAWC,SAASD,QAA6B,IAAjBH,EAAOK,cAYzCL,EAAOM,MAAM,IAEXf,EAASK,ICzC9B,MAAMW,EAIFb,mBACSc,EAAU,IAAIC,wBAQZC,KAAKF,EAMhBG,mBAEIxB,KAAKyB,iBAAiB,QAAWC,UACvBC,QAAEA,GAAYD,EACdE,EAAkBL,KAAKM,cAAc,CAAEF,QAAAA,EAASD,MAAAA,IAClDE,GACAF,EAAMI,YAAYF,KA0B9BG,mBAEI/B,KAAKyB,iBAAiB,UAAaC,OAC3BA,EAAMM,MAA4B,eAApBN,EAAMM,KAAKC,KAAuB,OAC1CC,QAAEA,GAAYR,EAAMM,KAIpBG,EAAkBC,QAAQC,IAAIH,EAAQI,YAAYC,IAAKC,IACpC,iBAAVA,IACPA,EAAQ,CAACA,UAEPb,EAAU,IAAIc,WAAWD,UACxBjB,KAAKM,cAAc,CAAEF,QAAAA,OAKhCD,EAAMgB,UAAUP,GAEZT,EAAMiB,OAASjB,EAAMiB,MAAM,IAC3BR,EAAgBS,KAAK,IAAMlB,EAAMiB,MAAM,GAAGE,aAAY,OAkBtEhB,eAAcF,QAAEA,EAAF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AAclB,GACrBA,qBCxEX,SAAyB9C,GACC0E,IACRX,gBAAgB/D,wBCClC,SAA2BA,GACD0E,IACRZ,kBAAkB9D"}
|
@@ -0,0 +1,923 @@
|
|
1
|
+
this.workbox = this.workbox || {};
|
2
|
+
this.workbox.strategies = (function (exports, assert_js, cacheNames_js, cacheWrapper_js, fetchWrapper_js, getFriendlyURL_js, logger_js, WorkboxError_js) {
|
3
|
+
'use strict';
|
4
|
+
|
5
|
+
try {
|
6
|
+
self['workbox:strategies:5.1.4'] && _();
|
7
|
+
} catch (e) {}
|
8
|
+
|
9
|
+
/*
|
10
|
+
Copyright 2018 Google LLC
|
11
|
+
|
12
|
+
Use of this source code is governed by an MIT-style
|
13
|
+
license that can be found in the LICENSE file or at
|
14
|
+
https://opensource.org/licenses/MIT.
|
15
|
+
*/
|
16
|
+
const messages = {
|
17
|
+
strategyStart: (strategyName, request) => `Using ${strategyName} to respond to '${getFriendlyURL_js.getFriendlyURL(request.url)}'`,
|
18
|
+
printFinalResponse: response => {
|
19
|
+
if (response) {
|
20
|
+
logger_js.logger.groupCollapsed(`View the final response here.`);
|
21
|
+
logger_js.logger.log(response || '[No response returned]');
|
22
|
+
logger_js.logger.groupEnd();
|
23
|
+
}
|
24
|
+
}
|
25
|
+
};
|
26
|
+
|
27
|
+
/*
|
28
|
+
Copyright 2018 Google LLC
|
29
|
+
|
30
|
+
Use of this source code is governed by an MIT-style
|
31
|
+
license that can be found in the LICENSE file or at
|
32
|
+
https://opensource.org/licenses/MIT.
|
33
|
+
*/
|
34
|
+
/**
|
35
|
+
* An implementation of a [cache-first]{@link https://developers.google.com/web/fundamentals/instant-and-offline/offline-cookbook/#cache-falling-back-to-network}
|
36
|
+
* request strategy.
|
37
|
+
*
|
38
|
+
* A cache first strategy is useful for assets that have been revisioned,
|
39
|
+
* such as URLs like `/styles/example.a8f5f1.css`, since they
|
40
|
+
* can be cached for long periods of time.
|
41
|
+
*
|
42
|
+
* If the network request fails, and there is no cache match, this will throw
|
43
|
+
* a `WorkboxError` exception.
|
44
|
+
*
|
45
|
+
* @memberof module:workbox-strategies
|
46
|
+
*/
|
47
|
+
|
48
|
+
class CacheFirst {
|
49
|
+
/**
|
50
|
+
* @param {Object} options
|
51
|
+
* @param {string} options.cacheName Cache name to store and retrieve
|
52
|
+
* requests. Defaults to cache names provided by
|
53
|
+
* [workbox-core]{@link module:workbox-core.cacheNames}.
|
54
|
+
* @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}
|
55
|
+
* to use in conjunction with this caching strategy.
|
56
|
+
* @param {Object} options.fetchOptions Values passed along to the
|
57
|
+
* [`init`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)
|
58
|
+
* of all fetch() requests made by this strategy.
|
59
|
+
* @param {Object} options.matchOptions [`CacheQueryOptions`](https://w3c.github.io/ServiceWorker/#dictdef-cachequeryoptions)
|
60
|
+
*/
|
61
|
+
constructor(options = {}) {
|
62
|
+
this._cacheName = cacheNames_js.cacheNames.getRuntimeName(options.cacheName);
|
63
|
+
this._plugins = options.plugins || [];
|
64
|
+
this._fetchOptions = options.fetchOptions;
|
65
|
+
this._matchOptions = options.matchOptions;
|
66
|
+
}
|
67
|
+
/**
|
68
|
+
* This method will perform a request strategy and follows an API that
|
69
|
+
* will work with the
|
70
|
+
* [Workbox Router]{@link module:workbox-routing.Router}.
|
71
|
+
*
|
72
|
+
* @param {Object} options
|
73
|
+
* @param {Request|string} options.request A request to run this strategy for.
|
74
|
+
* @param {Event} [options.event] The event that triggered the request.
|
75
|
+
* @return {Promise<Response>}
|
76
|
+
*/
|
77
|
+
|
78
|
+
|
79
|
+
async handle({
|
80
|
+
event,
|
81
|
+
request
|
82
|
+
}) {
|
83
|
+
const logs = [];
|
84
|
+
|
85
|
+
if (typeof request === 'string') {
|
86
|
+
request = new Request(request);
|
87
|
+
}
|
88
|
+
|
89
|
+
{
|
90
|
+
assert_js.assert.isInstance(request, Request, {
|
91
|
+
moduleName: 'workbox-strategies',
|
92
|
+
className: 'CacheFirst',
|
93
|
+
funcName: 'makeRequest',
|
94
|
+
paramName: 'request'
|
95
|
+
});
|
96
|
+
}
|
97
|
+
|
98
|
+
let response = await cacheWrapper_js.cacheWrapper.match({
|
99
|
+
cacheName: this._cacheName,
|
100
|
+
request,
|
101
|
+
event,
|
102
|
+
matchOptions: this._matchOptions,
|
103
|
+
plugins: this._plugins
|
104
|
+
});
|
105
|
+
let error;
|
106
|
+
|
107
|
+
if (!response) {
|
108
|
+
{
|
109
|
+
logs.push(`No response found in the '${this._cacheName}' cache. ` + `Will respond with a network request.`);
|
110
|
+
}
|
111
|
+
|
112
|
+
try {
|
113
|
+
response = await this._getFromNetwork(request, event);
|
114
|
+
} catch (err) {
|
115
|
+
error = err;
|
116
|
+
}
|
117
|
+
|
118
|
+
{
|
119
|
+
if (response) {
|
120
|
+
logs.push(`Got response from network.`);
|
121
|
+
} else {
|
122
|
+
logs.push(`Unable to get a response from the network.`);
|
123
|
+
}
|
124
|
+
}
|
125
|
+
} else {
|
126
|
+
{
|
127
|
+
logs.push(`Found a cached response in the '${this._cacheName}' cache.`);
|
128
|
+
}
|
129
|
+
}
|
130
|
+
|
131
|
+
{
|
132
|
+
logger_js.logger.groupCollapsed(messages.strategyStart('CacheFirst', request));
|
133
|
+
|
134
|
+
for (const log of logs) {
|
135
|
+
logger_js.logger.log(log);
|
136
|
+
}
|
137
|
+
|
138
|
+
messages.printFinalResponse(response);
|
139
|
+
logger_js.logger.groupEnd();
|
140
|
+
}
|
141
|
+
|
142
|
+
if (!response) {
|
143
|
+
throw new WorkboxError_js.WorkboxError('no-response', {
|
144
|
+
url: request.url,
|
145
|
+
error
|
146
|
+
});
|
147
|
+
}
|
148
|
+
|
149
|
+
return response;
|
150
|
+
}
|
151
|
+
/**
|
152
|
+
* Handles the network and cache part of CacheFirst.
|
153
|
+
*
|
154
|
+
* @param {Request} request
|
155
|
+
* @param {Event} [event]
|
156
|
+
* @return {Promise<Response>}
|
157
|
+
*
|
158
|
+
* @private
|
159
|
+
*/
|
160
|
+
|
161
|
+
|
162
|
+
async _getFromNetwork(request, event) {
|
163
|
+
const response = await fetchWrapper_js.fetchWrapper.fetch({
|
164
|
+
request,
|
165
|
+
event,
|
166
|
+
fetchOptions: this._fetchOptions,
|
167
|
+
plugins: this._plugins
|
168
|
+
}); // Keep the service worker while we put the request to the cache
|
169
|
+
|
170
|
+
const responseClone = response.clone();
|
171
|
+
const cachePutPromise = cacheWrapper_js.cacheWrapper.put({
|
172
|
+
cacheName: this._cacheName,
|
173
|
+
request,
|
174
|
+
response: responseClone,
|
175
|
+
event,
|
176
|
+
plugins: this._plugins
|
177
|
+
});
|
178
|
+
|
179
|
+
if (event) {
|
180
|
+
try {
|
181
|
+
event.waitUntil(cachePutPromise);
|
182
|
+
} catch (error) {
|
183
|
+
{
|
184
|
+
logger_js.logger.warn(`Unable to ensure service worker stays alive when ` + `updating cache for '${getFriendlyURL_js.getFriendlyURL(request.url)}'.`);
|
185
|
+
}
|
186
|
+
}
|
187
|
+
}
|
188
|
+
|
189
|
+
return response;
|
190
|
+
}
|
191
|
+
|
192
|
+
}
|
193
|
+
|
194
|
+
/*
|
195
|
+
Copyright 2018 Google LLC
|
196
|
+
|
197
|
+
Use of this source code is governed by an MIT-style
|
198
|
+
license that can be found in the LICENSE file or at
|
199
|
+
https://opensource.org/licenses/MIT.
|
200
|
+
*/
|
201
|
+
/**
|
202
|
+
* An implementation of a
|
203
|
+
* [cache-only]{@link https://developers.google.com/web/fundamentals/instant-and-offline/offline-cookbook/#cache-only}
|
204
|
+
* request strategy.
|
205
|
+
*
|
206
|
+
* This class is useful if you want to take advantage of any
|
207
|
+
* [Workbox plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}.
|
208
|
+
*
|
209
|
+
* If there is no cache match, this will throw a `WorkboxError` exception.
|
210
|
+
*
|
211
|
+
* @memberof module:workbox-strategies
|
212
|
+
*/
|
213
|
+
|
214
|
+
class CacheOnly {
|
215
|
+
/**
|
216
|
+
* @param {Object} options
|
217
|
+
* @param {string} options.cacheName Cache name to store and retrieve
|
218
|
+
* requests. Defaults to cache names provided by
|
219
|
+
* [workbox-core]{@link module:workbox-core.cacheNames}.
|
220
|
+
* @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}
|
221
|
+
* to use in conjunction with this caching strategy.
|
222
|
+
* @param {Object} options.matchOptions [`CacheQueryOptions`](https://w3c.github.io/ServiceWorker/#dictdef-cachequeryoptions)
|
223
|
+
*/
|
224
|
+
constructor(options = {}) {
|
225
|
+
this._cacheName = cacheNames_js.cacheNames.getRuntimeName(options.cacheName);
|
226
|
+
this._plugins = options.plugins || [];
|
227
|
+
this._matchOptions = options.matchOptions;
|
228
|
+
}
|
229
|
+
/**
|
230
|
+
* This method will perform a request strategy and follows an API that
|
231
|
+
* will work with the
|
232
|
+
* [Workbox Router]{@link module:workbox-routing.Router}.
|
233
|
+
*
|
234
|
+
* @param {Object} options
|
235
|
+
* @param {Request|string} options.request A request to run this strategy for.
|
236
|
+
* @param {Event} [options.event] The event that triggered the request.
|
237
|
+
* @return {Promise<Response>}
|
238
|
+
*/
|
239
|
+
|
240
|
+
|
241
|
+
async handle({
|
242
|
+
event,
|
243
|
+
request
|
244
|
+
}) {
|
245
|
+
if (typeof request === 'string') {
|
246
|
+
request = new Request(request);
|
247
|
+
}
|
248
|
+
|
249
|
+
{
|
250
|
+
assert_js.assert.isInstance(request, Request, {
|
251
|
+
moduleName: 'workbox-strategies',
|
252
|
+
className: 'CacheOnly',
|
253
|
+
funcName: 'makeRequest',
|
254
|
+
paramName: 'request'
|
255
|
+
});
|
256
|
+
}
|
257
|
+
|
258
|
+
const response = await cacheWrapper_js.cacheWrapper.match({
|
259
|
+
cacheName: this._cacheName,
|
260
|
+
request,
|
261
|
+
event,
|
262
|
+
matchOptions: this._matchOptions,
|
263
|
+
plugins: this._plugins
|
264
|
+
});
|
265
|
+
|
266
|
+
{
|
267
|
+
logger_js.logger.groupCollapsed(messages.strategyStart('CacheOnly', request));
|
268
|
+
|
269
|
+
if (response) {
|
270
|
+
logger_js.logger.log(`Found a cached response in the '${this._cacheName}'` + ` cache.`);
|
271
|
+
messages.printFinalResponse(response);
|
272
|
+
} else {
|
273
|
+
logger_js.logger.log(`No response found in the '${this._cacheName}' cache.`);
|
274
|
+
}
|
275
|
+
|
276
|
+
logger_js.logger.groupEnd();
|
277
|
+
}
|
278
|
+
|
279
|
+
if (!response) {
|
280
|
+
throw new WorkboxError_js.WorkboxError('no-response', {
|
281
|
+
url: request.url
|
282
|
+
});
|
283
|
+
}
|
284
|
+
|
285
|
+
return response;
|
286
|
+
}
|
287
|
+
|
288
|
+
}
|
289
|
+
|
290
|
+
/*
|
291
|
+
Copyright 2018 Google LLC
|
292
|
+
|
293
|
+
Use of this source code is governed by an MIT-style
|
294
|
+
license that can be found in the LICENSE file or at
|
295
|
+
https://opensource.org/licenses/MIT.
|
296
|
+
*/
|
297
|
+
const cacheOkAndOpaquePlugin = {
|
298
|
+
/**
|
299
|
+
* Returns a valid response (to allow caching) if the status is 200 (OK) or
|
300
|
+
* 0 (opaque).
|
301
|
+
*
|
302
|
+
* @param {Object} options
|
303
|
+
* @param {Response} options.response
|
304
|
+
* @return {Response|null}
|
305
|
+
*
|
306
|
+
* @private
|
307
|
+
*/
|
308
|
+
cacheWillUpdate: async ({
|
309
|
+
response
|
310
|
+
}) => {
|
311
|
+
if (response.status === 200 || response.status === 0) {
|
312
|
+
return response;
|
313
|
+
}
|
314
|
+
|
315
|
+
return null;
|
316
|
+
}
|
317
|
+
};
|
318
|
+
|
319
|
+
/*
|
320
|
+
Copyright 2018 Google LLC
|
321
|
+
|
322
|
+
Use of this source code is governed by an MIT-style
|
323
|
+
license that can be found in the LICENSE file or at
|
324
|
+
https://opensource.org/licenses/MIT.
|
325
|
+
*/
|
326
|
+
/**
|
327
|
+
* An implementation of a
|
328
|
+
* [network first]{@link https://developers.google.com/web/fundamentals/instant-and-offline/offline-cookbook/#network-falling-back-to-cache}
|
329
|
+
* request strategy.
|
330
|
+
*
|
331
|
+
* By default, this strategy will cache responses with a 200 status code as
|
332
|
+
* well as [opaque responses]{@link https://developers.google.com/web/tools/workbox/guides/handle-third-party-requests}.
|
333
|
+
* Opaque responses are are cross-origin requests where the response doesn't
|
334
|
+
* support [CORS]{@link https://enable-cors.org/}.
|
335
|
+
*
|
336
|
+
* If the network request fails, and there is no cache match, this will throw
|
337
|
+
* a `WorkboxError` exception.
|
338
|
+
*
|
339
|
+
* @memberof module:workbox-strategies
|
340
|
+
*/
|
341
|
+
|
342
|
+
class NetworkFirst {
|
343
|
+
/**
|
344
|
+
* @param {Object} options
|
345
|
+
* @param {string} options.cacheName Cache name to store and retrieve
|
346
|
+
* requests. Defaults to cache names provided by
|
347
|
+
* [workbox-core]{@link module:workbox-core.cacheNames}.
|
348
|
+
* @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}
|
349
|
+
* to use in conjunction with this caching strategy.
|
350
|
+
* @param {Object} options.fetchOptions Values passed along to the
|
351
|
+
* [`init`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)
|
352
|
+
* of all fetch() requests made by this strategy.
|
353
|
+
* @param {Object} options.matchOptions [`CacheQueryOptions`](https://w3c.github.io/ServiceWorker/#dictdef-cachequeryoptions)
|
354
|
+
* @param {number} options.networkTimeoutSeconds If set, any network requests
|
355
|
+
* that fail to respond within the timeout will fallback to the cache.
|
356
|
+
*
|
357
|
+
* This option can be used to combat
|
358
|
+
* "[lie-fi]{@link https://developers.google.com/web/fundamentals/performance/poor-connectivity/#lie-fi}"
|
359
|
+
* scenarios.
|
360
|
+
*/
|
361
|
+
constructor(options = {}) {
|
362
|
+
this._cacheName = cacheNames_js.cacheNames.getRuntimeName(options.cacheName);
|
363
|
+
|
364
|
+
if (options.plugins) {
|
365
|
+
const isUsingCacheWillUpdate = options.plugins.some(plugin => !!plugin.cacheWillUpdate);
|
366
|
+
this._plugins = isUsingCacheWillUpdate ? options.plugins : [cacheOkAndOpaquePlugin, ...options.plugins];
|
367
|
+
} else {
|
368
|
+
// No plugins passed in, use the default plugin.
|
369
|
+
this._plugins = [cacheOkAndOpaquePlugin];
|
370
|
+
}
|
371
|
+
|
372
|
+
this._networkTimeoutSeconds = options.networkTimeoutSeconds || 0;
|
373
|
+
|
374
|
+
{
|
375
|
+
if (this._networkTimeoutSeconds) {
|
376
|
+
assert_js.assert.isType(this._networkTimeoutSeconds, 'number', {
|
377
|
+
moduleName: 'workbox-strategies',
|
378
|
+
className: 'NetworkFirst',
|
379
|
+
funcName: 'constructor',
|
380
|
+
paramName: 'networkTimeoutSeconds'
|
381
|
+
});
|
382
|
+
}
|
383
|
+
}
|
384
|
+
|
385
|
+
this._fetchOptions = options.fetchOptions;
|
386
|
+
this._matchOptions = options.matchOptions;
|
387
|
+
}
|
388
|
+
/**
|
389
|
+
* This method will perform a request strategy and follows an API that
|
390
|
+
* will work with the
|
391
|
+
* [Workbox Router]{@link module:workbox-routing.Router}.
|
392
|
+
*
|
393
|
+
* @param {Object} options
|
394
|
+
* @param {Request|string} options.request A request to run this strategy for.
|
395
|
+
* @param {Event} [options.event] The event that triggered the request.
|
396
|
+
* @return {Promise<Response>}
|
397
|
+
*/
|
398
|
+
|
399
|
+
|
400
|
+
async handle({
|
401
|
+
event,
|
402
|
+
request
|
403
|
+
}) {
|
404
|
+
const logs = [];
|
405
|
+
|
406
|
+
if (typeof request === 'string') {
|
407
|
+
request = new Request(request);
|
408
|
+
}
|
409
|
+
|
410
|
+
{
|
411
|
+
assert_js.assert.isInstance(request, Request, {
|
412
|
+
moduleName: 'workbox-strategies',
|
413
|
+
className: 'NetworkFirst',
|
414
|
+
funcName: 'handle',
|
415
|
+
paramName: 'makeRequest'
|
416
|
+
});
|
417
|
+
}
|
418
|
+
|
419
|
+
const promises = [];
|
420
|
+
let timeoutId;
|
421
|
+
|
422
|
+
if (this._networkTimeoutSeconds) {
|
423
|
+
const {
|
424
|
+
id,
|
425
|
+
promise
|
426
|
+
} = this._getTimeoutPromise({
|
427
|
+
request,
|
428
|
+
event,
|
429
|
+
logs
|
430
|
+
});
|
431
|
+
|
432
|
+
timeoutId = id;
|
433
|
+
promises.push(promise);
|
434
|
+
}
|
435
|
+
|
436
|
+
const networkPromise = this._getNetworkPromise({
|
437
|
+
timeoutId,
|
438
|
+
request,
|
439
|
+
event,
|
440
|
+
logs
|
441
|
+
});
|
442
|
+
|
443
|
+
promises.push(networkPromise); // Promise.race() will resolve as soon as the first promise resolves.
|
444
|
+
|
445
|
+
let response = await Promise.race(promises); // If Promise.race() resolved with null, it might be due to a network
|
446
|
+
// timeout + a cache miss. If that were to happen, we'd rather wait until
|
447
|
+
// the networkPromise resolves instead of returning null.
|
448
|
+
// Note that it's fine to await an already-resolved promise, so we don't
|
449
|
+
// have to check to see if it's still "in flight".
|
450
|
+
|
451
|
+
if (!response) {
|
452
|
+
response = await networkPromise;
|
453
|
+
}
|
454
|
+
|
455
|
+
{
|
456
|
+
logger_js.logger.groupCollapsed(messages.strategyStart('NetworkFirst', request));
|
457
|
+
|
458
|
+
for (const log of logs) {
|
459
|
+
logger_js.logger.log(log);
|
460
|
+
}
|
461
|
+
|
462
|
+
messages.printFinalResponse(response);
|
463
|
+
logger_js.logger.groupEnd();
|
464
|
+
}
|
465
|
+
|
466
|
+
if (!response) {
|
467
|
+
throw new WorkboxError_js.WorkboxError('no-response', {
|
468
|
+
url: request.url
|
469
|
+
});
|
470
|
+
}
|
471
|
+
|
472
|
+
return response;
|
473
|
+
}
|
474
|
+
/**
|
475
|
+
* @param {Object} options
|
476
|
+
* @param {Request} options.request
|
477
|
+
* @param {Array} options.logs A reference to the logs array
|
478
|
+
* @param {Event} [options.event]
|
479
|
+
* @return {Promise<Response>}
|
480
|
+
*
|
481
|
+
* @private
|
482
|
+
*/
|
483
|
+
|
484
|
+
|
485
|
+
_getTimeoutPromise({
|
486
|
+
request,
|
487
|
+
logs,
|
488
|
+
event
|
489
|
+
}) {
|
490
|
+
let timeoutId;
|
491
|
+
const timeoutPromise = new Promise(resolve => {
|
492
|
+
const onNetworkTimeout = async () => {
|
493
|
+
{
|
494
|
+
logs.push(`Timing out the network response at ` + `${this._networkTimeoutSeconds} seconds.`);
|
495
|
+
}
|
496
|
+
|
497
|
+
resolve(await this._respondFromCache({
|
498
|
+
request,
|
499
|
+
event
|
500
|
+
}));
|
501
|
+
};
|
502
|
+
|
503
|
+
timeoutId = setTimeout(onNetworkTimeout, this._networkTimeoutSeconds * 1000);
|
504
|
+
});
|
505
|
+
return {
|
506
|
+
promise: timeoutPromise,
|
507
|
+
id: timeoutId
|
508
|
+
};
|
509
|
+
}
|
510
|
+
/**
|
511
|
+
* @param {Object} options
|
512
|
+
* @param {number|undefined} options.timeoutId
|
513
|
+
* @param {Request} options.request
|
514
|
+
* @param {Array} options.logs A reference to the logs Array.
|
515
|
+
* @param {Event} [options.event]
|
516
|
+
* @return {Promise<Response>}
|
517
|
+
*
|
518
|
+
* @private
|
519
|
+
*/
|
520
|
+
|
521
|
+
|
522
|
+
async _getNetworkPromise({
|
523
|
+
timeoutId,
|
524
|
+
request,
|
525
|
+
logs,
|
526
|
+
event
|
527
|
+
}) {
|
528
|
+
let error;
|
529
|
+
let response;
|
530
|
+
|
531
|
+
try {
|
532
|
+
response = await fetchWrapper_js.fetchWrapper.fetch({
|
533
|
+
request,
|
534
|
+
event,
|
535
|
+
fetchOptions: this._fetchOptions,
|
536
|
+
plugins: this._plugins
|
537
|
+
});
|
538
|
+
} catch (err) {
|
539
|
+
error = err;
|
540
|
+
}
|
541
|
+
|
542
|
+
if (timeoutId) {
|
543
|
+
clearTimeout(timeoutId);
|
544
|
+
}
|
545
|
+
|
546
|
+
{
|
547
|
+
if (response) {
|
548
|
+
logs.push(`Got response from network.`);
|
549
|
+
} else {
|
550
|
+
logs.push(`Unable to get a response from the network. Will respond ` + `with a cached response.`);
|
551
|
+
}
|
552
|
+
}
|
553
|
+
|
554
|
+
if (error || !response) {
|
555
|
+
response = await this._respondFromCache({
|
556
|
+
request,
|
557
|
+
event
|
558
|
+
});
|
559
|
+
|
560
|
+
{
|
561
|
+
if (response) {
|
562
|
+
logs.push(`Found a cached response in the '${this._cacheName}'` + ` cache.`);
|
563
|
+
} else {
|
564
|
+
logs.push(`No response found in the '${this._cacheName}' cache.`);
|
565
|
+
}
|
566
|
+
}
|
567
|
+
} else {
|
568
|
+
// Keep the service worker alive while we put the request in the cache
|
569
|
+
const responseClone = response.clone();
|
570
|
+
const cachePut = cacheWrapper_js.cacheWrapper.put({
|
571
|
+
cacheName: this._cacheName,
|
572
|
+
request,
|
573
|
+
response: responseClone,
|
574
|
+
event,
|
575
|
+
plugins: this._plugins
|
576
|
+
});
|
577
|
+
|
578
|
+
if (event) {
|
579
|
+
try {
|
580
|
+
// The event has been responded to so we can keep the SW alive to
|
581
|
+
// respond to the request
|
582
|
+
event.waitUntil(cachePut);
|
583
|
+
} catch (err) {
|
584
|
+
{
|
585
|
+
logger_js.logger.warn(`Unable to ensure service worker stays alive when ` + `updating cache for '${getFriendlyURL_js.getFriendlyURL(request.url)}'.`);
|
586
|
+
}
|
587
|
+
}
|
588
|
+
}
|
589
|
+
}
|
590
|
+
|
591
|
+
return response;
|
592
|
+
}
|
593
|
+
/**
|
594
|
+
* Used if the network timeouts or fails to make the request.
|
595
|
+
*
|
596
|
+
* @param {Object} options
|
597
|
+
* @param {Request} request The request to match in the cache
|
598
|
+
* @param {Event} [options.event]
|
599
|
+
* @return {Promise<Object>}
|
600
|
+
*
|
601
|
+
* @private
|
602
|
+
*/
|
603
|
+
|
604
|
+
|
605
|
+
_respondFromCache({
|
606
|
+
event,
|
607
|
+
request
|
608
|
+
}) {
|
609
|
+
return cacheWrapper_js.cacheWrapper.match({
|
610
|
+
cacheName: this._cacheName,
|
611
|
+
request,
|
612
|
+
event,
|
613
|
+
matchOptions: this._matchOptions,
|
614
|
+
plugins: this._plugins
|
615
|
+
});
|
616
|
+
}
|
617
|
+
|
618
|
+
}
|
619
|
+
|
620
|
+
/*
|
621
|
+
Copyright 2018 Google LLC
|
622
|
+
|
623
|
+
Use of this source code is governed by an MIT-style
|
624
|
+
license that can be found in the LICENSE file or at
|
625
|
+
https://opensource.org/licenses/MIT.
|
626
|
+
*/
|
627
|
+
/**
|
628
|
+
* An implementation of a
|
629
|
+
* [network-only]{@link https://developers.google.com/web/fundamentals/instant-and-offline/offline-cookbook/#network-only}
|
630
|
+
* request strategy.
|
631
|
+
*
|
632
|
+
* This class is useful if you want to take advantage of any
|
633
|
+
* [Workbox plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}.
|
634
|
+
*
|
635
|
+
* If the network request fails, this will throw a `WorkboxError` exception.
|
636
|
+
*
|
637
|
+
* @memberof module:workbox-strategies
|
638
|
+
*/
|
639
|
+
|
640
|
+
class NetworkOnly {
|
641
|
+
/**
|
642
|
+
* @param {Object} options
|
643
|
+
* @param {string} options.cacheName Cache name to store and retrieve
|
644
|
+
* requests. Defaults to cache names provided by
|
645
|
+
* [workbox-core]{@link module:workbox-core.cacheNames}.
|
646
|
+
* @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}
|
647
|
+
* to use in conjunction with this caching strategy.
|
648
|
+
* @param {Object} options.fetchOptions Values passed along to the
|
649
|
+
* [`init`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)
|
650
|
+
* of all fetch() requests made by this strategy.
|
651
|
+
*/
|
652
|
+
constructor(options = {}) {
|
653
|
+
this._plugins = options.plugins || [];
|
654
|
+
this._fetchOptions = options.fetchOptions;
|
655
|
+
}
|
656
|
+
/**
|
657
|
+
* This method will perform a request strategy and follows an API that
|
658
|
+
* will work with the
|
659
|
+
* [Workbox Router]{@link module:workbox-routing.Router}.
|
660
|
+
*
|
661
|
+
* @param {Object} options
|
662
|
+
* @param {Request|string} options.request The request to run this strategy for.
|
663
|
+
* @param {Event} [options.event] The event that triggered the request.
|
664
|
+
* @return {Promise<Response>}
|
665
|
+
*/
|
666
|
+
|
667
|
+
|
668
|
+
async handle({
|
669
|
+
event,
|
670
|
+
request
|
671
|
+
}) {
|
672
|
+
if (typeof request === 'string') {
|
673
|
+
request = new Request(request);
|
674
|
+
}
|
675
|
+
|
676
|
+
{
|
677
|
+
assert_js.assert.isInstance(request, Request, {
|
678
|
+
moduleName: 'workbox-strategies',
|
679
|
+
className: 'NetworkOnly',
|
680
|
+
funcName: 'handle',
|
681
|
+
paramName: 'request'
|
682
|
+
});
|
683
|
+
}
|
684
|
+
|
685
|
+
let error;
|
686
|
+
let response;
|
687
|
+
|
688
|
+
try {
|
689
|
+
response = await fetchWrapper_js.fetchWrapper.fetch({
|
690
|
+
request,
|
691
|
+
event,
|
692
|
+
fetchOptions: this._fetchOptions,
|
693
|
+
plugins: this._plugins
|
694
|
+
});
|
695
|
+
} catch (err) {
|
696
|
+
error = err;
|
697
|
+
}
|
698
|
+
|
699
|
+
{
|
700
|
+
logger_js.logger.groupCollapsed(messages.strategyStart('NetworkOnly', request));
|
701
|
+
|
702
|
+
if (response) {
|
703
|
+
logger_js.logger.log(`Got response from network.`);
|
704
|
+
} else {
|
705
|
+
logger_js.logger.log(`Unable to get a response from the network.`);
|
706
|
+
}
|
707
|
+
|
708
|
+
messages.printFinalResponse(response);
|
709
|
+
logger_js.logger.groupEnd();
|
710
|
+
}
|
711
|
+
|
712
|
+
if (!response) {
|
713
|
+
throw new WorkboxError_js.WorkboxError('no-response', {
|
714
|
+
url: request.url,
|
715
|
+
error
|
716
|
+
});
|
717
|
+
}
|
718
|
+
|
719
|
+
return response;
|
720
|
+
}
|
721
|
+
|
722
|
+
}
|
723
|
+
|
724
|
+
/*
|
725
|
+
Copyright 2018 Google LLC
|
726
|
+
|
727
|
+
Use of this source code is governed by an MIT-style
|
728
|
+
license that can be found in the LICENSE file or at
|
729
|
+
https://opensource.org/licenses/MIT.
|
730
|
+
*/
|
731
|
+
/**
|
732
|
+
* An implementation of a
|
733
|
+
* [stale-while-revalidate]{@link https://developers.google.com/web/fundamentals/instant-and-offline/offline-cookbook/#stale-while-revalidate}
|
734
|
+
* request strategy.
|
735
|
+
*
|
736
|
+
* Resources are requested from both the cache and the network in parallel.
|
737
|
+
* The strategy will respond with the cached version if available, otherwise
|
738
|
+
* wait for the network response. The cache is updated with the network response
|
739
|
+
* with each successful request.
|
740
|
+
*
|
741
|
+
* By default, this strategy will cache responses with a 200 status code as
|
742
|
+
* well as [opaque responses]{@link https://developers.google.com/web/tools/workbox/guides/handle-third-party-requests}.
|
743
|
+
* Opaque responses are cross-origin requests where the response doesn't
|
744
|
+
* support [CORS]{@link https://enable-cors.org/}.
|
745
|
+
*
|
746
|
+
* If the network request fails, and there is no cache match, this will throw
|
747
|
+
* a `WorkboxError` exception.
|
748
|
+
*
|
749
|
+
* @memberof module:workbox-strategies
|
750
|
+
*/
|
751
|
+
|
752
|
+
class StaleWhileRevalidate {
|
753
|
+
/**
|
754
|
+
* @param {Object} options
|
755
|
+
* @param {string} options.cacheName Cache name to store and retrieve
|
756
|
+
* requests. Defaults to cache names provided by
|
757
|
+
* [workbox-core]{@link module:workbox-core.cacheNames}.
|
758
|
+
* @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}
|
759
|
+
* to use in conjunction with this caching strategy.
|
760
|
+
* @param {Object} options.fetchOptions Values passed along to the
|
761
|
+
* [`init`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)
|
762
|
+
* of all fetch() requests made by this strategy.
|
763
|
+
* @param {Object} options.matchOptions [`CacheQueryOptions`](https://w3c.github.io/ServiceWorker/#dictdef-cachequeryoptions)
|
764
|
+
*/
|
765
|
+
constructor(options = {}) {
|
766
|
+
this._cacheName = cacheNames_js.cacheNames.getRuntimeName(options.cacheName);
|
767
|
+
this._plugins = options.plugins || [];
|
768
|
+
|
769
|
+
if (options.plugins) {
|
770
|
+
const isUsingCacheWillUpdate = options.plugins.some(plugin => !!plugin.cacheWillUpdate);
|
771
|
+
this._plugins = isUsingCacheWillUpdate ? options.plugins : [cacheOkAndOpaquePlugin, ...options.plugins];
|
772
|
+
} else {
|
773
|
+
// No plugins passed in, use the default plugin.
|
774
|
+
this._plugins = [cacheOkAndOpaquePlugin];
|
775
|
+
}
|
776
|
+
|
777
|
+
this._fetchOptions = options.fetchOptions;
|
778
|
+
this._matchOptions = options.matchOptions;
|
779
|
+
}
|
780
|
+
/**
|
781
|
+
* This method will perform a request strategy and follows an API that
|
782
|
+
* will work with the
|
783
|
+
* [Workbox Router]{@link module:workbox-routing.Router}.
|
784
|
+
*
|
785
|
+
* @param {Object} options
|
786
|
+
* @param {Request|string} options.request A request to run this strategy for.
|
787
|
+
* @param {Event} [options.event] The event that triggered the request.
|
788
|
+
* @return {Promise<Response>}
|
789
|
+
*/
|
790
|
+
|
791
|
+
|
792
|
+
async handle({
|
793
|
+
event,
|
794
|
+
request
|
795
|
+
}) {
|
796
|
+
const logs = [];
|
797
|
+
|
798
|
+
if (typeof request === 'string') {
|
799
|
+
request = new Request(request);
|
800
|
+
}
|
801
|
+
|
802
|
+
{
|
803
|
+
assert_js.assert.isInstance(request, Request, {
|
804
|
+
moduleName: 'workbox-strategies',
|
805
|
+
className: 'StaleWhileRevalidate',
|
806
|
+
funcName: 'handle',
|
807
|
+
paramName: 'request'
|
808
|
+
});
|
809
|
+
}
|
810
|
+
|
811
|
+
const fetchAndCachePromise = this._getFromNetwork({
|
812
|
+
request,
|
813
|
+
event
|
814
|
+
});
|
815
|
+
|
816
|
+
let response = await cacheWrapper_js.cacheWrapper.match({
|
817
|
+
cacheName: this._cacheName,
|
818
|
+
request,
|
819
|
+
event,
|
820
|
+
matchOptions: this._matchOptions,
|
821
|
+
plugins: this._plugins
|
822
|
+
});
|
823
|
+
let error;
|
824
|
+
|
825
|
+
if (response) {
|
826
|
+
{
|
827
|
+
logs.push(`Found a cached response in the '${this._cacheName}'` + ` cache. Will update with the network response in the background.`);
|
828
|
+
}
|
829
|
+
|
830
|
+
if (event) {
|
831
|
+
try {
|
832
|
+
event.waitUntil(fetchAndCachePromise);
|
833
|
+
} catch (error) {
|
834
|
+
{
|
835
|
+
logger_js.logger.warn(`Unable to ensure service worker stays alive when ` + `updating cache for '${getFriendlyURL_js.getFriendlyURL(request.url)}'.`);
|
836
|
+
}
|
837
|
+
}
|
838
|
+
}
|
839
|
+
} else {
|
840
|
+
{
|
841
|
+
logs.push(`No response found in the '${this._cacheName}' cache. ` + `Will wait for the network response.`);
|
842
|
+
}
|
843
|
+
|
844
|
+
try {
|
845
|
+
response = await fetchAndCachePromise;
|
846
|
+
} catch (err) {
|
847
|
+
error = err;
|
848
|
+
}
|
849
|
+
}
|
850
|
+
|
851
|
+
{
|
852
|
+
logger_js.logger.groupCollapsed(messages.strategyStart('StaleWhileRevalidate', request));
|
853
|
+
|
854
|
+
for (const log of logs) {
|
855
|
+
logger_js.logger.log(log);
|
856
|
+
}
|
857
|
+
|
858
|
+
messages.printFinalResponse(response);
|
859
|
+
logger_js.logger.groupEnd();
|
860
|
+
}
|
861
|
+
|
862
|
+
if (!response) {
|
863
|
+
throw new WorkboxError_js.WorkboxError('no-response', {
|
864
|
+
url: request.url,
|
865
|
+
error
|
866
|
+
});
|
867
|
+
}
|
868
|
+
|
869
|
+
return response;
|
870
|
+
}
|
871
|
+
/**
|
872
|
+
* @param {Object} options
|
873
|
+
* @param {Request} options.request
|
874
|
+
* @param {Event} [options.event]
|
875
|
+
* @return {Promise<Response>}
|
876
|
+
*
|
877
|
+
* @private
|
878
|
+
*/
|
879
|
+
|
880
|
+
|
881
|
+
async _getFromNetwork({
|
882
|
+
request,
|
883
|
+
event
|
884
|
+
}) {
|
885
|
+
const response = await fetchWrapper_js.fetchWrapper.fetch({
|
886
|
+
request,
|
887
|
+
event,
|
888
|
+
fetchOptions: this._fetchOptions,
|
889
|
+
plugins: this._plugins
|
890
|
+
});
|
891
|
+
const cachePutPromise = cacheWrapper_js.cacheWrapper.put({
|
892
|
+
cacheName: this._cacheName,
|
893
|
+
request,
|
894
|
+
response: response.clone(),
|
895
|
+
event,
|
896
|
+
plugins: this._plugins
|
897
|
+
});
|
898
|
+
|
899
|
+
if (event) {
|
900
|
+
try {
|
901
|
+
event.waitUntil(cachePutPromise);
|
902
|
+
} catch (error) {
|
903
|
+
{
|
904
|
+
logger_js.logger.warn(`Unable to ensure service worker stays alive when ` + `updating cache for '${getFriendlyURL_js.getFriendlyURL(request.url)}'.`);
|
905
|
+
}
|
906
|
+
}
|
907
|
+
}
|
908
|
+
|
909
|
+
return response;
|
910
|
+
}
|
911
|
+
|
912
|
+
}
|
913
|
+
|
914
|
+
exports.CacheFirst = CacheFirst;
|
915
|
+
exports.CacheOnly = CacheOnly;
|
916
|
+
exports.NetworkFirst = NetworkFirst;
|
917
|
+
exports.NetworkOnly = NetworkOnly;
|
918
|
+
exports.StaleWhileRevalidate = StaleWhileRevalidate;
|
919
|
+
|
920
|
+
return exports;
|
921
|
+
|
922
|
+
}({}, workbox.core._private, workbox.core._private, workbox.core._private, workbox.core._private, workbox.core._private, workbox.core._private, workbox.core._private));
|
923
|
+
//# sourceMappingURL=workbox-strategies.dev.js.map
|