Socket
Socket
Sign inDemoInstall

workbox-core

Package Overview
Dependencies
Maintainers
4
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

workbox-core - npm Package Compare versions

Comparing version 5.1.3 to 6.0.0-alpha.0

4

_private.d.ts
import { assert } from './_private/assert.js';
import { cacheNames } from './_private/cacheNames.js';
import { cacheWrapper } from './_private/cacheWrapper.js';
import { canConstructReadableStream } from './_private/canConstructReadableStream.js';

@@ -11,3 +10,2 @@ import { canConstructResponseFromBodyStream } from './_private/canConstructResponseFromBodyStream.js';

import { executeQuotaErrorCallbacks } from './_private/executeQuotaErrorCallbacks.js';
import { fetchWrapper } from './_private/fetchWrapper.js';
import { getFriendlyURL } from './_private/getFriendlyURL.js';

@@ -19,2 +17,2 @@ import { logger } from './_private/logger.js';

import './_version.js';
export { assert, cacheNames, cacheWrapper, canConstructReadableStream, canConstructResponseFromBodyStream, dontWaitFor, DBWrapper, Deferred, deleteDatabase, executeQuotaErrorCallbacks, fetchWrapper, getFriendlyURL, logger, resultingClientExists, timeout, WorkboxError, };
export { assert, cacheNames, canConstructReadableStream, canConstructResponseFromBodyStream, dontWaitFor, DBWrapper, Deferred, deleteDatabase, executeQuotaErrorCallbacks, getFriendlyURL, logger, resultingClientExists, timeout, WorkboxError, };

@@ -11,3 +11,2 @@ /*

import { cacheNames } from './_private/cacheNames.js';
import { cacheWrapper } from './_private/cacheWrapper.js';
import { canConstructReadableStream } from './_private/canConstructReadableStream.js';

@@ -20,3 +19,2 @@ import { canConstructResponseFromBodyStream } from './_private/canConstructResponseFromBodyStream.js';

import { executeQuotaErrorCallbacks } from './_private/executeQuotaErrorCallbacks.js';
import { fetchWrapper } from './_private/fetchWrapper.js';
import { getFriendlyURL } from './_private/getFriendlyURL.js';

@@ -28,2 +26,2 @@ import { logger } from './_private/logger.js';

import './_version.js';
export { assert, cacheNames, cacheWrapper, canConstructReadableStream, canConstructResponseFromBodyStream, dontWaitFor, DBWrapper, Deferred, deleteDatabase, executeQuotaErrorCallbacks, fetchWrapper, getFriendlyURL, logger, resultingClientExists, timeout, WorkboxError, };
export { assert, cacheNames, canConstructReadableStream, canConstructResponseFromBodyStream, dontWaitFor, DBWrapper, Deferred, deleteDatabase, executeQuotaErrorCallbacks, getFriendlyURL, logger, resultingClientExists, timeout, WorkboxError, };

@@ -1,13 +0,11 @@

import { WorkboxErrorDetails } from '../_private/WorkboxError.js';
import { MapLikeObject } from '../types.js';
import '../_version.js';
declare const finalAssertExports: {
hasMethod: (object: {
[key: string]: any;
}, expectedMethod: string, details: WorkboxErrorDetails) => void;
isArray: (value: any[], details: WorkboxErrorDetails) => void;
isInstance: (object: {}, expectedClass: Function, details: WorkboxErrorDetails) => void;
isOneOf: (value: any, validValues: any[], details: WorkboxErrorDetails) => void;
isType: (object: {}, expectedType: string, details: WorkboxErrorDetails) => void;
isArrayOfClass: (value: any, expectedClass: Function, details: WorkboxErrorDetails) => void;
hasMethod: (object: MapLikeObject, expectedMethod: string, details: MapLikeObject) => void;
isArray: (value: any[], details: MapLikeObject) => void;
isInstance: (object: {}, expectedClass: Function, details: MapLikeObject) => void;
isOneOf: (value: any, validValues: any[], details: MapLikeObject) => void;
isType: (object: {}, expectedType: string, details: MapLikeObject) => void;
isArrayOfClass: (value: any, expectedClass: Function, details: MapLikeObject) => void;
} | null;
export { finalAssertExports as assert };

@@ -0,5 +1,3 @@

import { MapLikeObject } from '../types.js';
import '../_version.js';
export interface WorkboxErrorDetails {
[propName: string]: any;
}
/**

@@ -16,3 +14,3 @@ * Workbox errors should be thrown with this class.

name: string;
details?: WorkboxErrorDetails;
details?: MapLikeObject;
/**

@@ -26,4 +24,4 @@ *

*/
constructor(errorCode: string, details?: WorkboxErrorDetails);
constructor(errorCode: string, details?: MapLikeObject);
}
export { WorkboxError };

@@ -327,3 +327,3 @@ this.workbox = this.workbox || {};

}) => {
return `The precaching request for '${url}' failed with an HTTP ` + `status of ${status}.`;
return `The precaching request for '${url}' failed` + (status ? ` with an HTTP status of ${status}.` : `.`);
},

@@ -345,2 +345,7 @@ 'non-precached-url': ({

return `Unable to find a precached response in ${cacheName} for ${url}.`;
},
'cross-origin-copy-response': ({
origin
}) => {
return `workbox-core.copyResponse() can only be used with same-origin ` + `responses. It was passed a response with origin ${origin}.`;
}

@@ -569,377 +574,2 @@ };

/*
Copyright 2018 Google LLC
Use of this source code is governed by an MIT-style
license that can be found in the LICENSE file or at
https://opensource.org/licenses/MIT.
*/
/**
* Runs all of the callback functions, one at a time sequentially, in the order
* in which they were registered.
*
* @memberof module:workbox-core
* @private
*/
async function executeQuotaErrorCallbacks() {
{
logger.log(`About to run ${quotaErrorCallbacks.size} ` + `callbacks to clean up caches.`);
}
for (const callback of quotaErrorCallbacks) {
await callback();
{
logger.log(callback, 'is complete.');
}
}
{
logger.log('Finished running callbacks.');
}
}
/*
Copyright 2018 Google LLC
Use of this source code is governed by an MIT-style
license that can be found in the LICENSE file or at
https://opensource.org/licenses/MIT.
*/
const getFriendlyURL = url => {
const urlObj = new URL(String(url), location.href); // See https://github.com/GoogleChrome/workbox/issues/2323
// We want to include everything, except for the origin if it's same-origin.
return urlObj.href.replace(new RegExp(`^${location.origin}`), '');
};
/*
Copyright 2018 Google LLC
Use of this source code is governed by an MIT-style
license that can be found in the LICENSE file or at
https://opensource.org/licenses/MIT.
*/
const pluginUtils = {
filter: (plugins, callbackName) => {
return plugins.filter(plugin => callbackName in plugin);
}
};
/*
Copyright 2018 Google LLC
Use of this source code is governed by an MIT-style
license that can be found in the LICENSE file or at
https://opensource.org/licenses/MIT.
*/
/**
* Checks the list of plugins for the cacheKeyWillBeUsed callback, and
* executes any of those callbacks found in sequence. The final `Request` object
* returned by the last plugin is treated as the cache key for cache reads
* and/or writes.
*
* @param {Object} options
* @param {Request} options.request
* @param {string} options.mode
* @param {Array<Object>} [options.plugins=[]]
* @return {Promise<Request>}
*
* @private
* @memberof module:workbox-core
*/
const _getEffectiveRequest = async ({
request,
mode,
plugins = []
}) => {
const cacheKeyWillBeUsedPlugins = pluginUtils.filter(plugins, "cacheKeyWillBeUsed"
/* CACHE_KEY_WILL_BE_USED */
);
let effectiveRequest = request;
for (const plugin of cacheKeyWillBeUsedPlugins) {
effectiveRequest = await plugin["cacheKeyWillBeUsed"
/* CACHE_KEY_WILL_BE_USED */
].call(plugin, {
mode,
request: effectiveRequest
});
if (typeof effectiveRequest === 'string') {
effectiveRequest = new Request(effectiveRequest);
}
{
finalAssertExports.isInstance(effectiveRequest, Request, {
moduleName: 'Plugin',
funcName: "cacheKeyWillBeUsed"
/* CACHE_KEY_WILL_BE_USED */
,
isReturnValueProblem: true
});
}
}
return effectiveRequest;
};
/**
* This method will call cacheWillUpdate on the available plugins (or use
* status === 200) to determine if the Response is safe and valid to cache.
*
* @param {Object} options
* @param {Request} options.request
* @param {Response} options.response
* @param {Event} [options.event]
* @param {Array<Object>} [options.plugins=[]]
* @return {Promise<Response>}
*
* @private
* @memberof module:workbox-core
*/
const _isResponseSafeToCache = async ({
request,
response,
event,
plugins = []
}) => {
let responseToCache = response;
let pluginsUsed = false;
for (const plugin of plugins) {
if ("cacheWillUpdate"
/* CACHE_WILL_UPDATE */
in plugin) {
pluginsUsed = true;
const pluginMethod = plugin["cacheWillUpdate"
/* CACHE_WILL_UPDATE */
];
responseToCache = await pluginMethod.call(plugin, {
request,
response: responseToCache,
event
});
{
if (responseToCache) {
finalAssertExports.isInstance(responseToCache, Response, {
moduleName: 'Plugin',
funcName: "cacheWillUpdate"
/* CACHE_WILL_UPDATE */
,
isReturnValueProblem: true
});
}
}
if (!responseToCache) {
break;
}
}
}
if (!pluginsUsed) {
{
if (responseToCache) {
if (responseToCache.status !== 200) {
if (responseToCache.status === 0) {
logger.warn(`The response for '${request.url}' is an opaque ` + `response. The caching strategy that you're using will not ` + `cache opaque responses by default.`);
} else {
logger.debug(`The response for '${request.url}' returned ` + `a status code of '${response.status}' and won't be cached as a ` + `result.`);
}
}
}
}
responseToCache = responseToCache && responseToCache.status === 200 ? responseToCache : undefined;
}
return responseToCache ? responseToCache : null;
};
/**
* This is a wrapper around cache.match().
*
* @param {Object} options
* @param {string} options.cacheName Name of the cache to match against.
* @param {Request} options.request The Request that will be used to look up
* cache entries.
* @param {Event} [options.event] The event that prompted the action.
* @param {Object} [options.matchOptions] Options passed to cache.match().
* @param {Array<Object>} [options.plugins=[]] Array of plugins.
* @return {Response} A cached response if available.
*
* @private
* @memberof module:workbox-core
*/
const matchWrapper = async ({
cacheName,
request,
event,
matchOptions,
plugins = []
}) => {
const cache = await self.caches.open(cacheName);
const effectiveRequest = await _getEffectiveRequest({
plugins,
request,
mode: 'read'
});
let cachedResponse = await cache.match(effectiveRequest, matchOptions);
{
if (cachedResponse) {
logger.debug(`Found a cached response in '${cacheName}'.`);
} else {
logger.debug(`No cached response found in '${cacheName}'.`);
}
}
for (const plugin of plugins) {
if ("cachedResponseWillBeUsed"
/* CACHED_RESPONSE_WILL_BE_USED */
in plugin) {
const pluginMethod = plugin["cachedResponseWillBeUsed"
/* CACHED_RESPONSE_WILL_BE_USED */
];
cachedResponse = await pluginMethod.call(plugin, {
cacheName,
event,
matchOptions,
cachedResponse,
request: effectiveRequest
});
{
if (cachedResponse) {
finalAssertExports.isInstance(cachedResponse, Response, {
moduleName: 'Plugin',
funcName: "cachedResponseWillBeUsed"
/* CACHED_RESPONSE_WILL_BE_USED */
,
isReturnValueProblem: true
});
}
}
}
}
return cachedResponse;
};
/**
* Wrapper around cache.put().
*
* Will call `cacheDidUpdate` on plugins if the cache was updated, using
* `matchOptions` when determining what the old entry is.
*
* @param {Object} options
* @param {string} options.cacheName
* @param {Request} options.request
* @param {Response} options.response
* @param {Event} [options.event]
* @param {Array<Object>} [options.plugins=[]]
* @param {Object} [options.matchOptions]
*
* @private
* @memberof module:workbox-core
*/
const putWrapper = async ({
cacheName,
request,
response,
event,
plugins = [],
matchOptions
}) => {
{
if (request.method && request.method !== 'GET') {
throw new WorkboxError('attempt-to-cache-non-get-request', {
url: getFriendlyURL(request.url),
method: request.method
});
}
}
const effectiveRequest = await _getEffectiveRequest({
plugins,
request,
mode: 'write'
});
if (!response) {
{
logger.error(`Cannot cache non-existent response for ` + `'${getFriendlyURL(effectiveRequest.url)}'.`);
}
throw new WorkboxError('cache-put-with-no-response', {
url: getFriendlyURL(effectiveRequest.url)
});
}
const responseToCache = await _isResponseSafeToCache({
event,
plugins,
response,
request: effectiveRequest
});
if (!responseToCache) {
{
logger.debug(`Response '${getFriendlyURL(effectiveRequest.url)}' will ` + `not be cached.`, responseToCache);
}
return;
}
const cache = await self.caches.open(cacheName);
const updatePlugins = pluginUtils.filter(plugins, "cacheDidUpdate"
/* CACHE_DID_UPDATE */
);
const oldResponse = updatePlugins.length > 0 ? await matchWrapper({
cacheName,
matchOptions,
request: effectiveRequest
}) : null;
{
logger.debug(`Updating the '${cacheName}' cache with a new Response for ` + `${getFriendlyURL(effectiveRequest.url)}.`);
}
try {
await cache.put(effectiveRequest, responseToCache);
} catch (error) {
// See https://developer.mozilla.org/en-US/docs/Web/API/DOMException#exception-QuotaExceededError
if (error.name === 'QuotaExceededError') {
await executeQuotaErrorCallbacks();
}
throw error;
}
for (const plugin of updatePlugins) {
await plugin["cacheDidUpdate"
/* CACHE_DID_UPDATE */
].call(plugin, {
cacheName,
event,
oldResponse,
newResponse: responseToCache,
request: effectiveRequest
});
}
};
const cacheWrapper = {
put: putWrapper,
match: matchWrapper
};
/*
Copyright 2019 Google LLC

@@ -1402,39 +1032,19 @@

/**
* Wrapper around the fetch API.
* Runs all of the callback functions, one at a time sequentially, in the order
* in which they were registered.
*
* Will call requestWillFetch on available plugins.
*
* @param {Object} options
* @param {Request|string} options.request
* @param {Object} [options.fetchOptions]
* @param {ExtendableEvent} [options.event]
* @param {Array<Object>} [options.plugins=[]]
* @return {Promise<Response>}
*
* @memberof module:workbox-core
* @private
* @memberof module:workbox-core
*/
const wrappedFetch = async ({
request,
fetchOptions,
event,
plugins = []
}) => {
if (typeof request === 'string') {
request = new Request(request);
} // We *should* be able to call `await event.preloadResponse` even if it's
// undefined, but for some reason, doing so leads to errors in our Node unit
// tests. To work around that, explicitly check preloadResponse's value first.
async function executeQuotaErrorCallbacks() {
{
logger.log(`About to run ${quotaErrorCallbacks.size} ` + `callbacks to clean up caches.`);
}
for (const callback of quotaErrorCallbacks) {
await callback();
if (event instanceof FetchEvent && event.preloadResponse) {
const possiblePreloadResponse = await event.preloadResponse;
if (possiblePreloadResponse) {
{
logger.log(`Using a preloaded navigation response for ` + `'${getFriendlyURL(request.url)}'`);
}
return possiblePreloadResponse;
{
logger.log(callback, 'is complete.');
}

@@ -1444,121 +1054,21 @@ }

{
finalAssertExports.isInstance(request, Request, {
paramName: 'request',
expectedClass: Request,
moduleName: 'workbox-core',
className: 'fetchWrapper',
funcName: 'wrappedFetch'
});
logger.log('Finished running callbacks.');
}
}
const failedFetchPlugins = pluginUtils.filter(plugins, "fetchDidFail"
/* FETCH_DID_FAIL */
); // If there is a fetchDidFail plugin, we need to save a clone of the
// original request before it's either modified by a requestWillFetch
// plugin or before the original request's body is consumed via fetch().
/*
Copyright 2018 Google LLC
const originalRequest = failedFetchPlugins.length > 0 ? request.clone() : null;
Use of this source code is governed by an MIT-style
license that can be found in the LICENSE file or at
https://opensource.org/licenses/MIT.
*/
try {
for (const plugin of plugins) {
if ("requestWillFetch"
/* REQUEST_WILL_FETCH */
in plugin) {
const pluginMethod = plugin["requestWillFetch"
/* REQUEST_WILL_FETCH */
];
const requestClone = request.clone();
request = await pluginMethod.call(plugin, {
request: requestClone,
event
});
const getFriendlyURL = url => {
const urlObj = new URL(String(url), location.href); // See https://github.com/GoogleChrome/workbox/issues/2323
// We want to include everything, except for the origin if it's same-origin.
if ("dev" !== 'production') {
if (request) {
finalAssertExports.isInstance(request, Request, {
moduleName: 'Plugin',
funcName: "cachedResponseWillBeUsed"
/* CACHED_RESPONSE_WILL_BE_USED */
,
isReturnValueProblem: true
});
}
}
}
}
} catch (err) {
throw new WorkboxError('plugin-error-request-will-fetch', {
thrownError: err
});
} // The request can be altered by plugins with `requestWillFetch` making
// the original request (Most likely from a `fetch` event) to be different
// to the Request we make. Pass both to `fetchDidFail` to aid debugging.
const pluginFilteredRequest = request.clone();
try {
let fetchResponse; // See https://github.com/GoogleChrome/workbox/issues/1796
if (request.mode === 'navigate') {
fetchResponse = await fetch(request);
} else {
fetchResponse = await fetch(request, fetchOptions);
}
if ("dev" !== 'production') {
logger.debug(`Network request for ` + `'${getFriendlyURL(request.url)}' returned a response with ` + `status '${fetchResponse.status}'.`);
}
for (const plugin of plugins) {
if ("fetchDidSucceed"
/* FETCH_DID_SUCCEED */
in plugin) {
fetchResponse = await plugin["fetchDidSucceed"
/* FETCH_DID_SUCCEED */
].call(plugin, {
event,
request: pluginFilteredRequest,
response: fetchResponse
});
if ("dev" !== 'production') {
if (fetchResponse) {
finalAssertExports.isInstance(fetchResponse, Response, {
moduleName: 'Plugin',
funcName: "fetchDidSucceed"
/* FETCH_DID_SUCCEED */
,
isReturnValueProblem: true
});
}
}
}
}
return fetchResponse;
} catch (error) {
{
logger.error(`Network request for ` + `'${getFriendlyURL(request.url)}' threw an error.`, error);
}
for (const plugin of failedFetchPlugins) {
await plugin["fetchDidFail"
/* FETCH_DID_FAIL */
].call(plugin, {
error,
event,
originalRequest: originalRequest.clone(),
request: pluginFilteredRequest.clone()
});
}
throw error;
}
return urlObj.href.replace(new RegExp(`^${location.origin}`), '');
};
const fetchWrapper = {
fetch: wrappedFetch
};
/*

@@ -1650,3 +1160,2 @@ Copyright 2019 Google LLC

cacheNames: cacheNames,
cacheWrapper: cacheWrapper,
canConstructReadableStream: canConstructReadableStream,

@@ -1659,3 +1168,2 @@ canConstructResponseFromBodyStream: canConstructResponseFromBodyStream,

executeQuotaErrorCallbacks: executeQuotaErrorCallbacks,
fetchWrapper: fetchWrapper,
getFriendlyURL: getFriendlyURL,

@@ -1733,2 +1241,5 @@ logger: logger,

*
* This method is intentionally limited to same-origin responses, regardless of
* whether CORS was used or not.
*
* @param {Response} response

@@ -1740,2 +1251,15 @@ * @param {Function} modifier

async function copyResponse(response, modifier) {
let origin = null; // If response.url isn't set, assume it's cross-origin and keep origin null.
if (response.url) {
const responseURL = new URL(response.url);
origin = responseURL.origin;
}
if (origin !== self.location.origin) {
throw new WorkboxError('cross-origin-copy-response', {
origin
});
}
const clonedResponse = response.clone(); // Create a fresh `ResponseInit` object by cloning the headers.

@@ -1843,6 +1367,6 @@

/**
* Force a service worker to activate immediately, instead of
* [waiting](https://developers.google.com/web/fundamentals/primers/service-workers/lifecycle#waiting)
* for existing clients to close.
* This method is deprecated, and will be removed in Workbox v7.
*
* Calling self.skipWaiting() is equivalent, and should be used instead.
*
* @memberof module:workbox-core

@@ -1852,5 +1376,9 @@ */

function skipWaiting() {
// We need to explicitly call `self.skipWaiting()` here because we're
// shadowing `skipWaiting` with this local function.
self.addEventListener('install', () => self.skipWaiting());
// Just call self.skipWaiting() directly.
// See https://github.com/GoogleChrome/workbox/issues/2525
{
logger.warn(`skipWaiting() from workbox-core is no longer recommended ` + `and will be removed in Workbox v7. Using self.skipWaiting() instead ` + `is equivalent.`);
}
self.skipWaiting();
}

@@ -1857,0 +1385,0 @@

@@ -1,2 +0,2 @@

this.workbox=this.workbox||{},this.workbox.core=function(e){"use strict";try{self["workbox:core:5.1.3"]&&_()}catch(e){}const t=(e,...t)=>{let n=e;return t.length>0&&(n+=` :: ${JSON.stringify(t)}`),n};class n extends Error{constructor(e,n){super(t(e,n)),this.name=e,this.details=n}}const s=new Set;const r={googleAnalytics:"googleAnalytics",precache:"precache-v2",prefix:"workbox",runtime:"runtime",suffix:"undefined"!=typeof registration?registration.scope:""},i=e=>[r.prefix,e,r.suffix].filter(e=>e&&e.length>0).join("-"),o={updateDetails:e=>{(e=>{for(const t of Object.keys(r))e(t)})(t=>{"string"==typeof e[t]&&(r[t]=e[t])})},getGoogleAnalyticsName:e=>e||i(r.googleAnalytics),getPrecacheName:e=>e||i(r.precache),getPrefix:()=>r.prefix,getRuntimeName:e=>e||i(r.runtime),getSuffix:()=>r.suffix};async function a(){for(const e of s)await e()}const c=e=>new URL(String(e),location.href).href.replace(new RegExp(`^${location.origin}`),""),u=(e,t)=>e.filter(e=>t in e),l=async({request:e,mode:t,plugins:n=[]})=>{const s=u(n,"cacheKeyWillBeUsed");let r=e;for(const e of s)r=await e.cacheKeyWillBeUsed.call(e,{mode:t,request:r}),"string"==typeof r&&(r=new Request(r));return r},f=async({cacheName:e,request:t,event:n,matchOptions:s,plugins:r=[]})=>{const i=await self.caches.open(e),o=await l({plugins:r,request:t,mode:"read"});let a=await i.match(o,s);for(const t of r)if("cachedResponseWillBeUsed"in t){const r=t.cachedResponseWillBeUsed;a=await r.call(t,{cacheName:e,event:n,matchOptions:s,cachedResponse:a,request:o})}return a},h={put:async({cacheName:e,request:t,response:s,event:r,plugins:i=[],matchOptions:o})=>{const h=await l({plugins:i,request:t,mode:"write"});if(!s)throw new n("cache-put-with-no-response",{url:c(h.url)});const w=await(async({request:e,response:t,event:n,plugins:s=[]})=>{let r=t,i=!1;for(const t of s)if("cacheWillUpdate"in t){i=!0;const s=t.cacheWillUpdate;if(r=await s.call(t,{request:e,response:r,event:n}),!r)break}return i||(r=r&&200===r.status?r:void 0),r||null})({event:r,plugins:i,response:s,request:h});if(!w)return;const p=await self.caches.open(e),d=u(i,"cacheDidUpdate"),g=d.length>0?await f({cacheName:e,matchOptions:o,request:h}):null;try{await p.put(h,w)}catch(e){throw"QuotaExceededError"===e.name&&await a(),e}for(const t of d)await t.cacheDidUpdate.call(t,{cacheName:e,event:r,oldResponse:g,newResponse:w,request:h})},match:f};let w,p;function d(){if(void 0===p){const e=new Response("");if("body"in e)try{new Response(e.body),p=!0}catch(e){p=!1}p=!1}return p}class g{constructor(e,t,{onupgradeneeded:n,onversionchange:s}={}){this.t=null,this.s=e,this.i=t,this.o=n,this.u=s||(()=>this.close())}get db(){return this.t}async open(){if(!this.t)return this.t=await new Promise((e,t)=>{let n=!1;setTimeout(()=>{n=!0,t(new Error("The open request was blocked and timed out"))},this.OPEN_TIMEOUT);const s=indexedDB.open(this.s,this.i);s.onerror=()=>t(s.error),s.onupgradeneeded=e=>{n?(s.transaction.abort(),s.result.close()):"function"==typeof this.o&&this.o(e)},s.onsuccess=()=>{const t=s.result;n?t.close():(t.onversionchange=this.u.bind(this),e(t))}}),this}async getKey(e,t){return(await this.getAllKeys(e,t,1))[0]}async getAll(e,t,n){return await this.getAllMatching(e,{query:t,count:n})}async getAllKeys(e,t,n){return(await this.getAllMatching(e,{query:t,count:n,includeKeys:!0})).map(e=>e.key)}async getAllMatching(e,{index:t,query:n=null,direction:s="next",count:r,includeKeys:i=!1}={}){return await this.transaction([e],"readonly",(o,a)=>{const c=o.objectStore(e),u=t?c.index(t):c,l=[],f=u.openCursor(n,s);f.onsuccess=()=>{const e=f.result;e?(l.push(i?e:e.value),r&&l.length>=r?a(l):e.continue()):a(l)}})}async transaction(e,t,n){return await this.open(),await new Promise((s,r)=>{const i=this.t.transaction(e,t);i.onabort=()=>r(i.error),i.oncomplete=()=>s(),n(i,e=>s(e))})}async l(e,t,n,...s){return await this.transaction([t],n,(n,r)=>{const i=n.objectStore(t),o=i[e].apply(i,s);o.onsuccess=()=>r(o.result)})}close(){this.t&&(this.t.close(),this.t=null)}}g.prototype.OPEN_TIMEOUT=2e3;const y={readonly:["get","count","getKey","getAll","getAllKeys"],readwrite:["add","put","clear","delete"]};for(const[e,t]of Object.entries(y))for(const n of t)n in IDBObjectStore.prototype&&(g.prototype[n]=async function(t,...s){return await this.l(n,t,e,...s)});const m={fetch:async({request:e,fetchOptions:t,event:s,plugins:r=[]})=>{if("string"==typeof e&&(e=new Request(e)),s instanceof FetchEvent&&s.preloadResponse){const e=await s.preloadResponse;if(e)return e}const i=u(r,"fetchDidFail"),o=i.length>0?e.clone():null;try{for(const t of r)if("requestWillFetch"in t){const n=t.requestWillFetch,r=e.clone();e=await n.call(t,{request:r,event:s})}}catch(e){throw new n("plugin-error-request-will-fetch",{thrownError:e})}const a=e.clone();try{let n;n="navigate"===e.mode?await fetch(e):await fetch(e,t);for(const e of r)"fetchDidSucceed"in e&&(n=await e.fetchDidSucceed.call(e,{event:s,request:a,response:n}));return n}catch(e){for(const t of i)await t.fetchDidFail.call(t,{error:e,event:s,originalRequest:o.clone(),request:a.clone()});throw e}}};function q(e){return new Promise(t=>setTimeout(t,e))}var v=Object.freeze({__proto__:null,assert:null,cacheNames:o,cacheWrapper:h,canConstructReadableStream:function(){if(void 0===w)try{new ReadableStream({start(){}}),w=!0}catch(e){w=!1}return w},canConstructResponseFromBodyStream:d,dontWaitFor:function(e){e.then(()=>{})},DBWrapper:g,Deferred:class{constructor(){this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}},deleteDatabase:async e=>{await new Promise((t,n)=>{const s=indexedDB.deleteDatabase(e);s.onerror=()=>{n(s.error)},s.onblocked=()=>{n(new Error("Delete blocked"))},s.onsuccess=()=>{t()}})},executeQuotaErrorCallbacks:a,fetchWrapper:m,getFriendlyURL:c,logger:null,resultingClientExists:async function(e){if(!e)return;let t=await self.clients.matchAll({type:"window"});const n=new Set(t.map(e=>e.id));let s;const r=performance.now();for(;performance.now()-r<2e3&&(t=await self.clients.matchAll({type:"window"}),s=t.find(t=>e?t.id===e:!n.has(t.id)),!s);)await q(100);return s},timeout:q,WorkboxError:n});const x={get googleAnalytics(){return o.getGoogleAnalyticsName()},get precache(){return o.getPrecacheName()},get prefix(){return o.getPrefix()},get runtime(){return o.getRuntimeName()},get suffix(){return o.getSuffix()}};return e._private=v,e.cacheNames=x,e.clientsClaim=function(){self.addEventListener("activate",()=>self.clients.claim())},e.copyResponse=async function(e,t){const n=e.clone(),s={headers:new Headers(n.headers),status:n.status,statusText:n.statusText},r=t?t(s):s,i=d()?n.body:await n.blob();return new Response(i,r)},e.registerQuotaErrorCallback=function(e){s.add(e)},e.setCacheNameDetails=function(e){o.updateDetails(e)},e.skipWaiting=function(){self.addEventListener("install",()=>self.skipWaiting())},e}({});
this.workbox=this.workbox||{},this.workbox.core=function(t){"use strict";try{self["workbox:core:5.1.3"]&&_()}catch(t){}const e=(t,...e)=>{let n=t;return e.length>0&&(n+=" :: "+JSON.stringify(e)),n};class n extends Error{constructor(t,n){super(e(t,n)),this.name=t,this.details=n}}const s=new Set;const r={googleAnalytics:"googleAnalytics",precache:"precache-v2",prefix:"workbox",runtime:"runtime",suffix:"undefined"!=typeof registration?registration.scope:""},i=t=>[r.prefix,t,r.suffix].filter(t=>t&&t.length>0).join("-"),o={updateDetails:t=>{(t=>{for(const e of Object.keys(r))t(e)})(e=>{"string"==typeof t[e]&&(r[e]=t[e])})},getGoogleAnalyticsName:t=>t||i(r.googleAnalytics),getPrecacheName:t=>t||i(r.precache),getPrefix:()=>r.prefix,getRuntimeName:t=>t||i(r.runtime),getSuffix:()=>r.suffix};let a,c;function u(){if(void 0===c){const t=new Response("");if("body"in t)try{new Response(t.body),c=!0}catch(t){c=!1}c=!1}return c}class l{constructor(t,e,{onupgradeneeded:n,onversionchange:s}={}){this.t=null,this.s=t,this.i=e,this.o=n,this.u=s||(()=>this.close())}get db(){return this.t}async open(){if(!this.t)return this.t=await new Promise((t,e)=>{let n=!1;setTimeout(()=>{n=!0,e(new Error("The open request was blocked and timed out"))},this.OPEN_TIMEOUT);const s=indexedDB.open(this.s,this.i);s.onerror=()=>e(s.error),s.onupgradeneeded=t=>{n?(s.transaction.abort(),s.result.close()):"function"==typeof this.o&&this.o(t)},s.onsuccess=()=>{const e=s.result;n?e.close():(e.onversionchange=this.u.bind(this),t(e))}}),this}async getKey(t,e){return(await this.getAllKeys(t,e,1))[0]}async getAll(t,e,n){return await this.getAllMatching(t,{query:e,count:n})}async getAllKeys(t,e,n){return(await this.getAllMatching(t,{query:e,count:n,includeKeys:!0})).map(t=>t.key)}async getAllMatching(t,{index:e,query:n=null,direction:s="next",count:r,includeKeys:i=!1}={}){return await this.transaction([t],"readonly",(o,a)=>{const c=o.objectStore(t),u=e?c.index(e):c,l=[],f=u.openCursor(n,s);f.onsuccess=()=>{const t=f.result;t?(l.push(i?t:t.value),r&&l.length>=r?a(l):t.continue()):a(l)}})}async transaction(t,e,n){return await this.open(),await new Promise((s,r)=>{const i=this.t.transaction(t,e);i.onabort=()=>r(i.error),i.oncomplete=()=>s(),n(i,t=>s(t))})}async l(t,e,n,...s){return await this.transaction([e],n,(n,r)=>{const i=n.objectStore(e),o=i[t].apply(i,s);o.onsuccess=()=>r(o.result)})}close(){this.t&&(this.t.close(),this.t=null)}}l.prototype.OPEN_TIMEOUT=2e3;const f={readonly:["get","count","getKey","getAll","getAllKeys"],readwrite:["add","put","clear","delete"]};for(const[t,e]of Object.entries(f))for(const n of e)n in IDBObjectStore.prototype&&(l.prototype[n]=async function(e,...s){return await this.l(n,e,t,...s)});function h(t){return new Promise(e=>setTimeout(e,t))}var w=Object.freeze({__proto__:null,assert:null,cacheNames:o,canConstructReadableStream:function(){if(void 0===a)try{new ReadableStream({start(){}}),a=!0}catch(t){a=!1}return a},canConstructResponseFromBodyStream:u,dontWaitFor:function(t){t.then(()=>{})},DBWrapper:l,Deferred:class{constructor(){this.promise=new Promise((t,e)=>{this.resolve=t,this.reject=e})}},deleteDatabase:async t=>{await new Promise((e,n)=>{const s=indexedDB.deleteDatabase(t);s.onerror=()=>{n(s.error)},s.onblocked=()=>{n(new Error("Delete blocked"))},s.onsuccess=()=>{e()}})},executeQuotaErrorCallbacks:async function(){for(const t of s)await t()},getFriendlyURL:t=>new URL(String(t),location.href).href.replace(new RegExp("^"+location.origin),""),logger:null,resultingClientExists:async function(t){if(!t)return;let e=await self.clients.matchAll({type:"window"});const n=new Set(e.map(t=>t.id));let s;const r=performance.now();for(;performance.now()-r<2e3&&(e=await self.clients.matchAll({type:"window"}),s=e.find(e=>t?e.id===t:!n.has(e.id)),!s);)await h(100);return s},timeout:h,WorkboxError:n});const d={get googleAnalytics(){return o.getGoogleAnalyticsName()},get precache(){return o.getPrecacheName()},get prefix(){return o.getPrefix()},get runtime(){return o.getRuntimeName()},get suffix(){return o.getSuffix()}};return t._private=w,t.cacheNames=d,t.clientsClaim=function(){self.addEventListener("activate",()=>self.clients.claim())},t.copyResponse=async function(t,e){let s=null;if(t.url){s=new URL(t.url).origin}if(s!==self.location.origin)throw new n("cross-origin-copy-response",{origin:s});const r=t.clone(),i={headers:new Headers(r.headers),status:r.status,statusText:r.statusText},o=e?e(i):i,a=u()?r.body:await r.blob();return new Response(a,o)},t.registerQuotaErrorCallback=function(t){s.add(t)},t.setCacheNameDetails=function(t){o.updateDetails(t)},t.skipWaiting=function(){self.skipWaiting()},t}({});
//# sourceMappingURL=workbox-core.prod.js.map

@@ -14,2 +14,5 @@ import './_version.js';

*
* This method is intentionally limited to same-origin responses, regardless of
* whether CORS was used or not.
*
* @param {Response} response

@@ -16,0 +19,0 @@ * @param {Function} modifier

@@ -9,2 +9,3 @@ /*

import { canConstructResponseFromBodyStream } from './_private/canConstructResponseFromBodyStream.js';
import { WorkboxError } from './_private/WorkboxError.js';
import './_version.js';

@@ -23,2 +24,5 @@ /**

*
* This method is intentionally limited to same-origin responses, regardless of
* whether CORS was used or not.
*
* @param {Response} response

@@ -29,2 +33,11 @@ * @param {Function} modifier

async function copyResponse(response, modifier) {
let origin = null;
// If response.url isn't set, assume it's cross-origin and keep origin null.
if (response.url) {
const responseURL = new URL(response.url);
origin = responseURL.origin;
}
if (origin !== self.location.origin) {
throw new WorkboxError('cross-origin-copy-response', { origin });
}
const clonedResponse = response.clone();

@@ -31,0 +44,0 @@ // Create a fresh `ResponseInit` object by cloning the headers.

@@ -0,9 +1,7 @@

import { MapLikeObject } from '../../types.js';
import '../../_version.js';
interface MessageParam {
[key: string]: any;
}
interface MessageMap {
[messageID: string]: (param: MessageParam) => string;
[messageID: string]: (param: MapLikeObject) => string;
}
export declare const messages: MessageMap;
export {};

@@ -197,4 +197,4 @@ /*

'bad-precaching-response': ({ url, status }) => {
return `The precaching request for '${url}' failed with an HTTP ` +
`status of ${status}.`;
return `The precaching request for '${url}' failed` +
(status ? ` with an HTTP status of ${status}.` : `.`);
},

@@ -213,2 +213,6 @@ 'non-precached-url': ({ url }) => {

},
'cross-origin-copy-response': ({ origin }) => {
return `workbox-core.copyResponse() can only be used with same-origin ` +
`responses. It was passed a response with origin ${origin}.`;
},
};
{
"name": "workbox-core",
"version": "5.1.3",
"version": "6.0.0-alpha.0",
"license": "MIT",

@@ -16,10 +16,5 @@ "author": "Google's Web DevRel Team",

],
"scripts": {
"build": "gulp build-packages --package workbox-core",
"version": "npm run build",
"prepare": "npm run build"
},
"workbox": {
"browserNamespace": "workbox.core",
"packageType": "browser"
"packageType": "sw"
},

@@ -29,3 +24,3 @@ "main": "index.js",

"types": "index.d.ts",
"gitHead": "fe4399505e02c3af6515fc8ffae8c58791f43f3c"
"gitHead": "3dfe1f4c5ed450bc4b7420321f1a113ff4382d1b"
}
import './_version.js';
/**
* Force a service worker to activate immediately, instead of
* [waiting](https://developers.google.com/web/fundamentals/primers/service-workers/lifecycle#waiting)
* for existing clients to close.
* This method is deprecated, and will be removed in Workbox v7.
*
* Calling self.skipWaiting() is equivalent, and should be used instead.
*
* @memberof module:workbox-core

@@ -8,0 +8,0 @@ */

@@ -8,15 +8,21 @@ /*

*/
import { logger } from './_private/logger.js';
import './_version.js';
/**
* Force a service worker to activate immediately, instead of
* [waiting](https://developers.google.com/web/fundamentals/primers/service-workers/lifecycle#waiting)
* for existing clients to close.
* This method is deprecated, and will be removed in Workbox v7.
*
* Calling self.skipWaiting() is equivalent, and should be used instead.
*
* @memberof module:workbox-core
*/
function skipWaiting() {
// We need to explicitly call `self.skipWaiting()` here because we're
// shadowing `skipWaiting` with this local function.
self.addEventListener('install', () => self.skipWaiting());
// Just call self.skipWaiting() directly.
// See https://github.com/GoogleChrome/workbox/issues/2525
if (process.env.NODE_ENV !== 'production') {
logger.warn(`skipWaiting() from workbox-core is no longer recommended ` +
`and will be removed in Workbox v7. Using self.skipWaiting() instead ` +
`is equivalent.`);
}
self.skipWaiting();
}
export { skipWaiting };

@@ -12,3 +12,2 @@ /*

import {cacheNames} from './_private/cacheNames.js';
import {cacheWrapper} from './_private/cacheWrapper.js';
import {canConstructReadableStream} from './_private/canConstructReadableStream.js';

@@ -21,3 +20,2 @@ import {canConstructResponseFromBodyStream} from './_private/canConstructResponseFromBodyStream.js';

import {executeQuotaErrorCallbacks} from './_private/executeQuotaErrorCallbacks.js';
import {fetchWrapper} from './_private/fetchWrapper.js';
import {getFriendlyURL} from './_private/getFriendlyURL.js';

@@ -34,3 +32,2 @@ import {logger} from './_private/logger.js';

cacheNames,
cacheWrapper,
canConstructReadableStream,

@@ -43,3 +40,2 @@ canConstructResponseFromBodyStream,

executeQuotaErrorCallbacks,
fetchWrapper,
getFriendlyURL,

@@ -46,0 +42,0 @@ logger,

@@ -9,3 +9,4 @@ /*

import {WorkboxError, WorkboxErrorDetails} from '../_private/WorkboxError.js';
import {WorkboxError} from '../_private/WorkboxError.js';
import {MapLikeObject} from '../types.js';
import '../_version.js';

@@ -21,3 +22,3 @@

value: any[],
details: WorkboxErrorDetails,
details: MapLikeObject,
) => {

@@ -30,5 +31,5 @@ if (!Array.isArray(value)) {

const hasMethod = (
object: {[key: string]: any},
object: MapLikeObject,
expectedMethod: string,
details: WorkboxErrorDetails,
details: MapLikeObject,
) => {

@@ -45,3 +46,3 @@ const type = typeof object[expectedMethod];

expectedType: string,
details: WorkboxErrorDetails,
details: MapLikeObject,
) => {

@@ -57,3 +58,3 @@ if (typeof object !== expectedType) {

expectedClass: Function,
details: WorkboxErrorDetails,
details: MapLikeObject,
) => {

@@ -69,3 +70,3 @@ if (!(object instanceof expectedClass)) {

validValues: any[],
details: WorkboxErrorDetails) => {
details: MapLikeObject) => {
if (!validValues.includes(value)) {

@@ -81,3 +82,3 @@ details['validValueDescription'] =

expectedClass: Function,
details: WorkboxErrorDetails,
details: MapLikeObject,
) => {

@@ -84,0 +85,0 @@ const error = new WorkboxError('not-array-of-class', details);

@@ -10,9 +10,5 @@ /*

import {messageGenerator} from '../models/messages/messageGenerator.js';
import {MapLikeObject} from '../types.js';
import '../_version.js';
// TODO(philipwalton): remove once the switch to TypeScript is complete and
// we no longer need the `assert` module.
export interface WorkboxErrorDetails {
[propName: string]: any;
}

@@ -30,3 +26,3 @@ /**

name: string;
details?: WorkboxErrorDetails;
details?: MapLikeObject;

@@ -41,3 +37,3 @@ /**

*/
constructor(errorCode: string, details?: WorkboxErrorDetails) {
constructor(errorCode: string, details?: MapLikeObject) {
const message = messageGenerator(errorCode, details);

@@ -44,0 +40,0 @@

@@ -10,5 +10,6 @@ /*

import {canConstructResponseFromBodyStream} from './_private/canConstructResponseFromBodyStream.js';
import {WorkboxError} from './_private/WorkboxError.js';
import './_version.js';
/**

@@ -25,2 +26,5 @@ * Allows developers to copy a response and modify its `headers`, `status`,

* new object.
*
* This method is intentionally limited to same-origin responses, regardless of
* whether CORS was used or not.
*

@@ -35,2 +39,13 @@ * @param {Response} response

) {
let origin = null;
// If response.url isn't set, assume it's cross-origin and keep origin null.
if (response.url) {
const responseURL = new URL(response.url);
origin = responseURL.origin;
}
if (origin !== self.location.origin) {
throw new WorkboxError('cross-origin-copy-response', {origin});
}
const clonedResponse = response.clone();

@@ -37,0 +52,0 @@

@@ -9,11 +9,8 @@ /*

import {MapLikeObject} from '../../types.js';
import '../../_version.js';
interface MessageParam {
[key: string]: any;
}
interface MessageMap {
[messageID: string]: (param: MessageParam) => string;
[messageID: string]: (param: MapLikeObject) => string;
}

@@ -250,4 +247,4 @@

'bad-precaching-response': ({url, status}) => {
return `The precaching request for '${url}' failed with an HTTP ` +
`status of ${status}.`;
return `The precaching request for '${url}' failed` +
(status ? ` with an HTTP status of ${status}.` : `.`);
},

@@ -269,2 +266,7 @@

},
'cross-origin-copy-response': ({origin}) => {
return `workbox-core.copyResponse() can only be used with same-origin ` +
`responses. It was passed a response with origin ${origin}.`;
},
};

@@ -9,5 +9,6 @@ /*

import {logger} from './_private/logger.js';
import './_version.js';
// Give TypeScript the correct global.

@@ -17,5 +18,5 @@ declare let self: ServiceWorkerGlobalScope;

/**
* Force a service worker to activate immediately, instead of
* [waiting](https://developers.google.com/web/fundamentals/primers/service-workers/lifecycle#waiting)
* for existing clients to close.
* This method is deprecated, and will be removed in Workbox v7.
*
* Calling self.skipWaiting() is equivalent, and should be used instead.
*

@@ -25,7 +26,13 @@ * @memberof module:workbox-core

function skipWaiting() {
// We need to explicitly call `self.skipWaiting()` here because we're
// shadowing `skipWaiting` with this local function.
self.addEventListener('install', () => self.skipWaiting());
// Just call self.skipWaiting() directly.
// See https://github.com/GoogleChrome/workbox/issues/2525
if (process.env.NODE_ENV !== 'production') {
logger.warn(`skipWaiting() from workbox-core is no longer recommended ` +
`and will be removed in Workbox v7. Using self.skipWaiting() instead ` +
`is equivalent.`);
}
self.skipWaiting();
}
export {skipWaiting}

@@ -12,9 +12,20 @@ /*

export interface MapLikeObject {
[key: string]: any;
}
/**
* Using a plain `MapLikeObject` for now, but could extend/restrict this
* in the future.
*/
export type PluginState = MapLikeObject;
/**
* Options passed to a `RouteMatchCallback` function.
*/
export interface RouteMatchCallbackOptions {
event: ExtendableEvent;
request: Request;
sameOrigin: boolean;
url: URL;
request: Request;
event?: ExtendableEvent;
}

@@ -41,8 +52,19 @@

export interface RouteHandlerCallbackOptions {
event: ExtendableEvent;
request: Request;
url: URL;
params?: string[] | MapLikeObject;
}
/**
* Options passed to a `ManualHandlerCallback` function.
*/
export interface ManualHandlerCallbackOptions {
event: ExtendableEvent;
request: Request | string;
url?: URL;
event?: ExtendableEvent;
params?: string[] | {[paramName: string]: string};
}
export type HandlerCallbackOptions =
RouteHandlerCallbackOptions | ManualHandlerCallbackOptions;
/**

@@ -61,2 +83,14 @@ * The "handler" callback is invoked whenever a `Router` matches a URL/Request

/**
* The "handler" callback is invoked whenever a `Router` matches a URL/Request
* to a `Route` via its `RouteMatchCallback`. This handler callback should
* return a `Promise` that resolves with a `Response`.
*
* If a non-empty array or object is returned by the `RouteMatchCallback` it
* will be passed in as this handler's `options.params` argument.
*/
export interface ManualHandlerCallback {
(options: ManualHandlerCallbackOptions): Promise<Response>;
}
/**
* An object with a `handle` method of type `RouteHandlerCallback`.

@@ -78,8 +112,19 @@ *

export interface HandlerWillStartCallbackParam {
request: Request;
event: ExtendableEvent;
state?: PluginState;
}
export interface HandlerWillStartCallback {
(param: HandlerWillStartCallbackParam): Promise<void | null | undefined>;
}
export interface CacheDidUpdateCallbackParam {
cacheName: string;
oldResponse?: Response | null;
newResponse: Response;
request: Request;
event?: Event;
event: ExtendableEvent;
oldResponse?: Response | null;
state?: PluginState;
}

@@ -92,4 +137,7 @@

export interface CacheKeyWillBeUsedCallbackParam {
mode: string;
request: Request;
mode: string;
event: ExtendableEvent;
params?: any;
state?: PluginState;
}

@@ -101,10 +149,11 @@

export interface CacheWillUpdateCallbackParamParam {
export interface CacheWillUpdateCallbackParam {
request: Request;
response: Response;
request: Request;
event?: ExtendableEvent;
event: ExtendableEvent;
state?: PluginState;
}
export interface CacheWillUpdateCallback {
(param: CacheWillUpdateCallbackParamParam): Promise<Response | void | null | undefined>;
(param: CacheWillUpdateCallbackParam): Promise<Response | void | null | undefined>;
}

@@ -115,5 +164,6 @@

request: Request;
cachedResponse?: Response;
event: ExtendableEvent;
matchOptions?: CacheQueryOptions;
cachedResponse?: Response;
event?: ExtendableEvent;
state?: PluginState;
}

@@ -126,6 +176,7 @@

export interface FetchDidFailCallbackParam {
error: Error;
originalRequest: Request;
error: Error;
request: Request;
event?: ExtendableEvent;
event: ExtendableEvent;
state?: PluginState;
}

@@ -140,2 +191,4 @@

response: Response;
event: ExtendableEvent;
state?: PluginState;
}

@@ -149,8 +202,55 @@

request: Request;
event: ExtendableEvent;
state?: PluginState;
}
export interface RequestWillFetchCallback {
(param: RequestWillFetchCallbackParam): Promise<Request | void | null | undefined>;
(param: RequestWillFetchCallbackParam): Promise<Request>;
}
export interface HandlerWillRespondCallbackParam {
request: Request;
response: Response;
event: ExtendableEvent;
state?: PluginState;
}
export interface HandlerWillRespondCallback {
(param: HandlerWillRespondCallbackParam): Promise<Response>;
}
interface HandlerDidErrorCallbackParam {
request: Request;
event: ExtendableEvent;
error: Error;
state?: PluginState;
}
export interface HandlerDidErrorCallback {
(param: HandlerDidErrorCallbackParam): Promise<Response | undefined>;
}
export interface HandlerDidRespondCallbackParam {
request: Request;
event: ExtendableEvent;
response?: Response;
state?: PluginState;
}
export interface HandlerDidRespondCallback {
(param: HandlerDidRespondCallbackParam): Promise<void | null | undefined>;
}
export interface HandlerDidCompleteCallbackParam {
request: Request;
error?: Error;
event: ExtendableEvent;
response?: Response;
state?: PluginState;
}
export interface HandlerDidCompleteCallback {
(param: HandlerDidCompleteCallbackParam): Promise<void | null | undefined>;
}
/**

@@ -162,8 +262,28 @@ * An object with optional lifecycle callback properties for the fetch and

cacheDidUpdate?: CacheDidUpdateCallback;
cachedResponseWillBeUsed?: CachedResponseWillBeUsedCallback;
cacheKeyWillBeUsed?: CacheKeyWillBeUsedCallback;
cacheWillUpdate?: CacheWillUpdateCallback;
cachedResponseWillBeUsed?: CachedResponseWillBeUsedCallback;
fetchDidFail?: FetchDidFailCallback;
fetchDidSucceed?: FetchDidSucceedCallback;
handlerDidComplete?: HandlerDidCompleteCallback;
handlerDidError?: HandlerDidErrorCallback;
handlerDidRespond?: HandlerDidRespondCallback;
handlerWillRespond?: HandlerWillRespondCallback;
handlerWillStart?: HandlerWillStartCallback;
requestWillFetch?: RequestWillFetchCallback;
}
export interface WorkboxPluginCallbackParam {
cacheDidUpdate: CacheDidUpdateCallbackParam;
cachedResponseWillBeUsed: CachedResponseWillBeUsedCallbackParam;
cacheKeyWillBeUsed: CacheKeyWillBeUsedCallbackParam;
cacheWillUpdate: CacheWillUpdateCallbackParam;
fetchDidFail: FetchDidFailCallbackParam;
fetchDidSucceed: FetchDidSucceedCallbackParam;
handlerDidComplete: HandlerDidCompleteCallbackParam;
handlerDidError: HandlerDidErrorCallbackParam;
handlerDidRespond: HandlerDidRespondCallbackParam;
handlerWillRespond: HandlerWillRespondCallbackParam;
handlerWillStart: HandlerWillStartCallbackParam;
requestWillFetch: RequestWillFetchCallbackParam;
}
import './_version.js';
export interface MapLikeObject {
[key: string]: any;
}
/**
* Using a plain `MapLikeObject` for now, but could extend/restrict this
* in the future.
*/
export declare type PluginState = MapLikeObject;
/**
* Options passed to a `RouteMatchCallback` function.
*/
export interface RouteMatchCallbackOptions {
event: ExtendableEvent;
request: Request;
sameOrigin: boolean;
url: URL;
request: Request;
event?: ExtendableEvent;
}

@@ -28,9 +37,15 @@ /**

export interface RouteHandlerCallbackOptions {
event: ExtendableEvent;
request: Request;
url: URL;
params?: string[] | MapLikeObject;
}
/**
* Options passed to a `ManualHandlerCallback` function.
*/
export interface ManualHandlerCallbackOptions {
event: ExtendableEvent;
request: Request | string;
url?: URL;
event?: ExtendableEvent;
params?: string[] | {
[paramName: string]: string;
};
}
export declare type HandlerCallbackOptions = RouteHandlerCallbackOptions | ManualHandlerCallbackOptions;
/**

@@ -48,2 +63,13 @@ * The "handler" callback is invoked whenever a `Router` matches a URL/Request

/**
* The "handler" callback is invoked whenever a `Router` matches a URL/Request
* to a `Route` via its `RouteMatchCallback`. This handler callback should
* return a `Promise` that resolves with a `Response`.
*
* If a non-empty array or object is returned by the `RouteMatchCallback` it
* will be passed in as this handler's `options.params` argument.
*/
export interface ManualHandlerCallback {
(options: ManualHandlerCallbackOptions): Promise<Response>;
}
/**
* An object with a `handle` method of type `RouteHandlerCallback`.

@@ -63,8 +89,17 @@ *

export declare type RouteHandler = RouteHandlerCallback | RouteHandlerObject;
export interface HandlerWillStartCallbackParam {
request: Request;
event: ExtendableEvent;
state?: PluginState;
}
export interface HandlerWillStartCallback {
(param: HandlerWillStartCallbackParam): Promise<void | null | undefined>;
}
export interface CacheDidUpdateCallbackParam {
cacheName: string;
oldResponse?: Response | null;
newResponse: Response;
request: Request;
event?: Event;
event: ExtendableEvent;
oldResponse?: Response | null;
state?: PluginState;
}

@@ -75,4 +110,7 @@ export interface CacheDidUpdateCallback {

export interface CacheKeyWillBeUsedCallbackParam {
mode: string;
request: Request;
mode: string;
event: ExtendableEvent;
params?: any;
state?: PluginState;
}

@@ -82,9 +120,10 @@ export interface CacheKeyWillBeUsedCallback {

}
export interface CacheWillUpdateCallbackParamParam {
export interface CacheWillUpdateCallbackParam {
request: Request;
response: Response;
request: Request;
event?: ExtendableEvent;
event: ExtendableEvent;
state?: PluginState;
}
export interface CacheWillUpdateCallback {
(param: CacheWillUpdateCallbackParamParam): Promise<Response | void | null | undefined>;
(param: CacheWillUpdateCallbackParam): Promise<Response | void | null | undefined>;
}

@@ -94,5 +133,6 @@ export interface CachedResponseWillBeUsedCallbackParam {

request: Request;
cachedResponse?: Response;
event: ExtendableEvent;
matchOptions?: CacheQueryOptions;
cachedResponse?: Response;
event?: ExtendableEvent;
state?: PluginState;
}

@@ -103,6 +143,7 @@ export interface CachedResponseWillBeUsedCallback {

export interface FetchDidFailCallbackParam {
error: Error;
originalRequest: Request;
error: Error;
request: Request;
event?: ExtendableEvent;
event: ExtendableEvent;
state?: PluginState;
}

@@ -115,2 +156,4 @@ export interface FetchDidFailCallback {

response: Response;
event: ExtendableEvent;
state?: PluginState;
}

@@ -122,6 +165,45 @@ export interface FetchDidSucceedCallback {

request: Request;
event: ExtendableEvent;
state?: PluginState;
}
export interface RequestWillFetchCallback {
(param: RequestWillFetchCallbackParam): Promise<Request | void | null | undefined>;
(param: RequestWillFetchCallbackParam): Promise<Request>;
}
export interface HandlerWillRespondCallbackParam {
request: Request;
response: Response;
event: ExtendableEvent;
state?: PluginState;
}
export interface HandlerWillRespondCallback {
(param: HandlerWillRespondCallbackParam): Promise<Response>;
}
interface HandlerDidErrorCallbackParam {
request: Request;
event: ExtendableEvent;
error: Error;
state?: PluginState;
}
export interface HandlerDidErrorCallback {
(param: HandlerDidErrorCallbackParam): Promise<Response | undefined>;
}
export interface HandlerDidRespondCallbackParam {
request: Request;
event: ExtendableEvent;
response?: Response;
state?: PluginState;
}
export interface HandlerDidRespondCallback {
(param: HandlerDidRespondCallbackParam): Promise<void | null | undefined>;
}
export interface HandlerDidCompleteCallbackParam {
request: Request;
error?: Error;
event: ExtendableEvent;
response?: Response;
state?: PluginState;
}
export interface HandlerDidCompleteCallback {
(param: HandlerDidCompleteCallbackParam): Promise<void | null | undefined>;
}
/**

@@ -133,8 +215,28 @@ * An object with optional lifecycle callback properties for the fetch and

cacheDidUpdate?: CacheDidUpdateCallback;
cachedResponseWillBeUsed?: CachedResponseWillBeUsedCallback;
cacheKeyWillBeUsed?: CacheKeyWillBeUsedCallback;
cacheWillUpdate?: CacheWillUpdateCallback;
cachedResponseWillBeUsed?: CachedResponseWillBeUsedCallback;
fetchDidFail?: FetchDidFailCallback;
fetchDidSucceed?: FetchDidSucceedCallback;
handlerDidComplete?: HandlerDidCompleteCallback;
handlerDidError?: HandlerDidErrorCallback;
handlerDidRespond?: HandlerDidRespondCallback;
handlerWillRespond?: HandlerWillRespondCallback;
handlerWillStart?: HandlerWillStartCallback;
requestWillFetch?: RequestWillFetchCallback;
}
export interface WorkboxPluginCallbackParam {
cacheDidUpdate: CacheDidUpdateCallbackParam;
cachedResponseWillBeUsed: CachedResponseWillBeUsedCallbackParam;
cacheKeyWillBeUsed: CacheKeyWillBeUsedCallbackParam;
cacheWillUpdate: CacheWillUpdateCallbackParam;
fetchDidFail: FetchDidFailCallbackParam;
fetchDidSucceed: FetchDidSucceedCallbackParam;
handlerDidComplete: HandlerDidCompleteCallbackParam;
handlerDidError: HandlerDidErrorCallbackParam;
handlerDidRespond: HandlerDidRespondCallbackParam;
handlerWillRespond: HandlerWillRespondCallbackParam;
handlerWillStart: HandlerWillStartCallbackParam;
requestWillFetch: RequestWillFetchCallbackParam;
}
export {};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc