Socket
Socket
Sign inDemoInstall

workbox-strategies

Package Overview
Dependencies
Maintainers
4
Versions
82
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

workbox-strategies - npm Package Compare versions

Comparing version 5.0.0-rc.1 to 5.0.0-rc.2

2

_version.js
"use strict";
// @ts-ignore
try {
self['workbox:strategies:5.0.0-rc.1'] && _();
self['workbox:strategies:5.0.0-rc.2'] && _();
}
catch (e) { }
this.workbox = this.workbox || {};
this.workbox.strategies = (function (exports, logger_js, assert_js, cacheNames_js, cacheWrapper_js, fetchWrapper_js, getFriendlyURL_js, WorkboxError_js) {
this.workbox.strategies = (function (exports, assert_js, cacheNames_js, cacheWrapper_js, fetchWrapper_js, getFriendlyURL_js, logger_js, WorkboxError_js) {
'use strict';
try {
self['workbox:strategies:5.0.0-rc.1'] && _();
self['workbox:strategies:5.0.0-rc.2'] && _();
} catch (e) {}

@@ -45,3 +45,3 @@

*
* @memberof workbox.strategies
* @memberof module:workbox-strategies
*/

@@ -54,3 +54,3 @@

* requests. Defaults to cache names provided by
* [workbox-core]{@link workbox.core.cacheNames}.
* [workbox-core]{@link module:workbox-core.cacheNames}.
* @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}

@@ -72,6 +72,6 @@ * to use in conjunction with this caching strategy.

* will work with the
* [Workbox Router]{@link workbox.routing.Router}.
* [Workbox Router]{@link module:workbox-routing.Router}.
*
* @param {Object} options
* @param {Request} options.request The request to run this strategy for.
* @param {Request|string} options.request A request to run this strategy for.
* @param {Event} [options.event] The event that triggered the request.

@@ -88,2 +88,6 @@ * @return {Promise<Response>}

if (typeof request === 'string') {
request = new Request(request);
}
{

@@ -211,3 +215,3 @@ assert_js.assert.isInstance(request, Request, {

*
* @memberof workbox.strategies
* @memberof module:workbox-strategies
*/

@@ -220,3 +224,3 @@

* requests. Defaults to cache names provided by
* [workbox-core]{@link workbox.core.cacheNames}.
* [workbox-core]{@link module:workbox-core.cacheNames}.
* @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}

@@ -234,6 +238,6 @@ * to use in conjunction with this caching strategy.

* will work with the
* [Workbox Router]{@link workbox.routing.Router}.
* [Workbox Router]{@link module:workbox-routing.Router}.
*
* @param {Object} options
* @param {Request} options.request The request to run this strategy for.
* @param {Request|string} options.request A request to run this strategy for.
* @param {Event} [options.event] The event that triggered the request.

@@ -248,2 +252,6 @@ * @return {Promise<Response>}

}) {
if (typeof request === 'string') {
request = new Request(request);
}
{

@@ -339,3 +347,3 @@ assert_js.assert.isInstance(request, Request, {

*
* @memberof workbox.strategies
* @memberof module:workbox-strategies
*/

@@ -348,3 +356,3 @@

* requests. Defaults to cache names provided by
* [workbox-core]{@link workbox.core.cacheNames}.
* [workbox-core]{@link module:workbox-core.cacheNames}.
* @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}

@@ -393,6 +401,6 @@ * to use in conjunction with this caching strategy.

* will work with the
* [Workbox Router]{@link workbox.routing.Router}.
* [Workbox Router]{@link module:workbox-routing.Router}.
*
* @param {Object} options
* @param {Request} options.request The request to run this strategy for.
* @param {Request|string} options.request A request to run this strategy for.
* @param {Event} [options.event] The event that triggered the request.

@@ -409,2 +417,6 @@ * @return {Promise<Response>}

if (typeof request === 'string') {
request = new Request(request);
}
{

@@ -637,3 +649,3 @@ assert_js.assert.isInstance(request, Request, {

*
* @memberof workbox.strategies
* @memberof module:workbox-strategies
*/

@@ -646,3 +658,3 @@

* requests. Defaults to cache names provided by
* [workbox-core]{@link workbox.core.cacheNames}.
* [workbox-core]{@link module:workbox-core.cacheNames}.
* @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}

@@ -661,6 +673,6 @@ * to use in conjunction with this caching strategy.

* will work with the
* [Workbox Router]{@link workbox.routing.Router}.
* [Workbox Router]{@link module:workbox-routing.Router}.
*
* @param {Object} options
* @param {Request} options.request The request to run this strategy for.
* @param {Request|string} options.request The request to run this strategy for.
* @param {Event} [options.event] The event that triggered the request.

@@ -675,2 +687,6 @@ * @return {Promise<Response>}

}) {
if (typeof request === 'string') {
request = new Request(request);
}
{

@@ -749,3 +765,3 @@ assert_js.assert.isInstance(request, Request, {

*
* @memberof workbox.strategies
* @memberof module:workbox-strategies
*/

@@ -758,3 +774,3 @@

* requests. Defaults to cache names provided by
* [workbox-core]{@link workbox.core.cacheNames}.
* [workbox-core]{@link module:workbox-core.cacheNames}.
* @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}

@@ -785,6 +801,6 @@ * to use in conjunction with this caching strategy.

* will work with the
* [Workbox Router]{@link workbox.routing.Router}.
* [Workbox Router]{@link module:workbox-routing.Router}.
*
* @param {Object} options
* @param {Request} options.request The request to run this strategy for.
* @param {Request|string} options.request A request to run this strategy for.
* @param {Event} [options.event] The event that triggered the request.

@@ -801,2 +817,6 @@ * @return {Promise<Response>}

if (typeof request === 'string') {
request = new Request(request);
}
{

@@ -914,70 +934,2 @@ assert_js.assert.isInstance(request, Request, {

/*
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 mapping = {
cacheFirst: CacheFirst,
cacheOnly: CacheOnly,
networkFirst: NetworkFirst,
networkOnly: NetworkOnly,
staleWhileRevalidate: StaleWhileRevalidate
};
const deprecate = strategy => {
const StrategyCtr = mapping[strategy];
return options => {
{
const strategyCtrName = strategy[0].toUpperCase() + strategy.slice(1);
logger_js.logger.warn(`The 'workbox.strategies.${strategy}()' function has been ` + `deprecated and will be removed in a future version of Workbox.\n` + `Please use 'new workbox.strategies.${strategyCtrName}()' instead.`);
}
return new StrategyCtr(options);
};
};
/**
* @function workbox.strategies.cacheFirst
* @param {Object} options See the {@link workbox.strategies.CacheFirst}
* constructor for more info.
* @deprecated since v4.0.0
*/
const cacheFirst = deprecate('cacheFirst');
/**
* @function workbox.strategies.cacheOnly
* @param {Object} options See the {@link workbox.strategies.CacheOnly}
* constructor for more info.
* @deprecated since v4.0.0
*/
const cacheOnly = deprecate('cacheOnly');
/**
* @function workbox.strategies.networkFirst
* @param {Object} options See the {@link workbox.strategies.NetworkFirst}
* constructor for more info.
* @deprecated since v4.0.0
*/
const networkFirst = deprecate('networkFirst');
/**
* @function workbox.strategies.networkOnly
* @param {Object} options See the {@link workbox.strategies.NetworkOnly}
* constructor for more info.
* @deprecated since v4.0.0
*/
const networkOnly = deprecate('networkOnly');
/**
* @function workbox.strategies.staleWhileRevalidate
* @param {Object} options See the
* {@link workbox.strategies.StaleWhileRevalidate} constructor for more info.
* @deprecated since v4.0.0
*/
const staleWhileRevalidate = deprecate('staleWhileRevalidate');
exports.CacheFirst = CacheFirst;

@@ -988,7 +940,2 @@ exports.CacheOnly = CacheOnly;

exports.StaleWhileRevalidate = StaleWhileRevalidate;
exports.cacheFirst = cacheFirst;
exports.cacheOnly = cacheOnly;
exports.networkFirst = networkFirst;
exports.networkOnly = networkOnly;
exports.staleWhileRevalidate = staleWhileRevalidate;

@@ -995,0 +942,0 @@ return exports;

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

this.workbox=this.workbox||{},this.workbox.strategies=function(t,e,s,i,r){"use strict";try{self["workbox:strategies:5.0.0-rc.1"]&&_()}catch(t){}class n{constructor(t={}){this.t=e.cacheNames.getRuntimeName(t.cacheName),this.s=t.plugins||[],this.i=t.fetchOptions,this.h=t.matchOptions}async handle({event:t,request:e}){let i,n=await s.cacheWrapper.match({cacheName:this.t,request:e,event:t,matchOptions:this.h,plugins:this.s});if(!n)try{n=await this.o(e,t)}catch(t){i=t}if(!n)throw new r.WorkboxError("no-response",{url:e.url,error:i});return n}async o(t,e){const r=await i.fetchWrapper.fetch({request:t,event:e,fetchOptions:this.i,plugins:this.s}),n=r.clone(),h=s.cacheWrapper.put({cacheName:this.t,request:t,response:n,event:e,plugins:this.s});if(e)try{e.waitUntil(h)}catch(t){}return r}}class h{constructor(t={}){this.t=e.cacheNames.getRuntimeName(t.cacheName),this.s=t.plugins||[],this.h=t.matchOptions}async handle({event:t,request:e}){const i=await s.cacheWrapper.match({cacheName:this.t,request:e,event:t,matchOptions:this.h,plugins:this.s});if(!i)throw new r.WorkboxError("no-response",{url:e.url});return i}}const c={cacheWillUpdate:async({response:t})=>200===t.status||0===t.status?t:null};class a{constructor(t={}){if(this.t=e.cacheNames.getRuntimeName(t.cacheName),t.plugins){let e=t.plugins.some(t=>!!t.cacheWillUpdate);this.s=e?t.plugins:[c,...t.plugins]}else this.s=[c];this.u=t.networkTimeoutSeconds||0,this.i=t.fetchOptions,this.h=t.matchOptions}async handle({event:t,request:e}){const s=[],i=[];let n;if(this.u){const{id:r,promise:h}=this.l({request:e,event:t,logs:s});n=r,i.push(h)}const h=this.p({timeoutId:n,request:e,event:t,logs:s});i.push(h);let c=await Promise.race(i);if(c||(c=await h),!c)throw new r.WorkboxError("no-response",{url:e.url});return c}l({request:t,logs:e,event:s}){let i;return{promise:new Promise(e=>{i=setTimeout(async()=>{e(await this.v({request:t,event:s}))},1e3*this.u)}),id:i}}async p({timeoutId:t,request:e,logs:r,event:n}){let h,c;try{c=await i.fetchWrapper.fetch({request:e,event:n,fetchOptions:this.i,plugins:this.s})}catch(t){h=t}if(t&&clearTimeout(t),h||!c)c=await this.v({request:e,event:n});else{const t=c.clone(),i=s.cacheWrapper.put({cacheName:this.t,request:e,response:t,event:n,plugins:this.s});if(n)try{n.waitUntil(i)}catch(t){}}return c}v({event:t,request:e}){return s.cacheWrapper.match({cacheName:this.t,request:e,event:t,matchOptions:this.h,plugins:this.s})}}class o{constructor(t={}){this.s=t.plugins||[],this.i=t.fetchOptions}async handle({event:t,request:e}){let s,n;try{n=await i.fetchWrapper.fetch({request:e,event:t,fetchOptions:this.i,plugins:this.s})}catch(t){s=t}if(!n)throw new r.WorkboxError("no-response",{url:e.url,error:s});return n}}class u{constructor(t={}){if(this.t=e.cacheNames.getRuntimeName(t.cacheName),this.s=t.plugins||[],t.plugins){let e=t.plugins.some(t=>!!t.cacheWillUpdate);this.s=e?t.plugins:[c,...t.plugins]}else this.s=[c];this.i=t.fetchOptions,this.h=t.matchOptions}async handle({event:t,request:e}){const i=this.o({request:e,event:t});let n,h=await s.cacheWrapper.match({cacheName:this.t,request:e,event:t,matchOptions:this.h,plugins:this.s});if(h){if(t)try{t.waitUntil(i)}catch(n){}}else try{h=await i}catch(t){n=t}if(!h)throw new r.WorkboxError("no-response",{url:e.url,error:n});return h}async o({request:t,event:e}){const r=await i.fetchWrapper.fetch({request:t,event:e,fetchOptions:this.i,plugins:this.s}),n=s.cacheWrapper.put({cacheName:this.t,request:t,response:r.clone(),event:e,plugins:this.s});if(e)try{e.waitUntil(n)}catch(t){}return r}}const l={cacheFirst:n,cacheOnly:h,networkFirst:a,networkOnly:o,staleWhileRevalidate:u},w=t=>{const e=l[t];return t=>new e(t)},p=w("cacheFirst"),v=w("cacheOnly"),m=w("networkFirst"),q=w("networkOnly"),y=w("staleWhileRevalidate");return t.CacheFirst=n,t.CacheOnly=h,t.NetworkFirst=a,t.NetworkOnly=o,t.StaleWhileRevalidate=u,t.cacheFirst=p,t.cacheOnly=v,t.networkFirst=m,t.networkOnly=q,t.staleWhileRevalidate=y,t}({},workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private);
this.workbox=this.workbox||{},this.workbox.strategies=function(t,e,s,i,n){"use strict";try{self["workbox:strategies:5.0.0-rc.2"]&&_()}catch(t){}const r={cacheWillUpdate:async({response:t})=>200===t.status||0===t.status?t:null};return t.CacheFirst=class{constructor(t={}){this.t=e.cacheNames.getRuntimeName(t.cacheName),this.s=t.plugins||[],this.i=t.fetchOptions,this.h=t.matchOptions}async handle({event:t,request:e}){"string"==typeof e&&(e=new Request(e));let i,r=await s.cacheWrapper.match({cacheName:this.t,request:e,event:t,matchOptions:this.h,plugins:this.s});if(!r)try{r=await this.o(e,t)}catch(t){i=t}if(!r)throw new n.WorkboxError("no-response",{url:e.url,error:i});return r}async o(t,e){const n=await i.fetchWrapper.fetch({request:t,event:e,fetchOptions:this.i,plugins:this.s}),r=n.clone(),h=s.cacheWrapper.put({cacheName:this.t,request:t,response:r,event:e,plugins:this.s});if(e)try{e.waitUntil(h)}catch(t){}return n}},t.CacheOnly=class{constructor(t={}){this.t=e.cacheNames.getRuntimeName(t.cacheName),this.s=t.plugins||[],this.h=t.matchOptions}async handle({event:t,request:e}){"string"==typeof e&&(e=new Request(e));const i=await s.cacheWrapper.match({cacheName:this.t,request:e,event:t,matchOptions:this.h,plugins:this.s});if(!i)throw new n.WorkboxError("no-response",{url:e.url});return i}},t.NetworkFirst=class{constructor(t={}){if(this.t=e.cacheNames.getRuntimeName(t.cacheName),t.plugins){let e=t.plugins.some(t=>!!t.cacheWillUpdate);this.s=e?t.plugins:[r,...t.plugins]}else this.s=[r];this.u=t.networkTimeoutSeconds||0,this.i=t.fetchOptions,this.h=t.matchOptions}async handle({event:t,request:e}){const s=[];"string"==typeof e&&(e=new Request(e));const i=[];let r;if(this.u){const{id:n,promise:h}=this.l({request:e,event:t,logs:s});r=n,i.push(h)}const h=this.p({timeoutId:r,request:e,event:t,logs:s});i.push(h);let o=await Promise.race(i);if(o||(o=await h),!o)throw new n.WorkboxError("no-response",{url:e.url});return o}l({request:t,logs:e,event:s}){let i;return{promise:new Promise(e=>{i=setTimeout(async()=>{e(await this.q({request:t,event:s}))},1e3*this.u)}),id:i}}async p({timeoutId:t,request:e,logs:n,event:r}){let h,o;try{o=await i.fetchWrapper.fetch({request:e,event:r,fetchOptions:this.i,plugins:this.s})}catch(t){h=t}if(t&&clearTimeout(t),h||!o)o=await this.q({request:e,event:r});else{const t=o.clone(),i=s.cacheWrapper.put({cacheName:this.t,request:e,response:t,event:r,plugins:this.s});if(r)try{r.waitUntil(i)}catch(t){}}return o}q({event:t,request:e}){return s.cacheWrapper.match({cacheName:this.t,request:e,event:t,matchOptions:this.h,plugins:this.s})}},t.NetworkOnly=class{constructor(t={}){this.s=t.plugins||[],this.i=t.fetchOptions}async handle({event:t,request:e}){let s,r;"string"==typeof e&&(e=new Request(e));try{r=await i.fetchWrapper.fetch({request:e,event:t,fetchOptions:this.i,plugins:this.s})}catch(t){s=t}if(!r)throw new n.WorkboxError("no-response",{url:e.url,error:s});return r}},t.StaleWhileRevalidate=class{constructor(t={}){if(this.t=e.cacheNames.getRuntimeName(t.cacheName),this.s=t.plugins||[],t.plugins){let e=t.plugins.some(t=>!!t.cacheWillUpdate);this.s=e?t.plugins:[r,...t.plugins]}else this.s=[r];this.i=t.fetchOptions,this.h=t.matchOptions}async handle({event:t,request:e}){"string"==typeof e&&(e=new Request(e));const i=this.o({request:e,event:t});let r,h=await s.cacheWrapper.match({cacheName:this.t,request:e,event:t,matchOptions:this.h,plugins:this.s});if(h){if(t)try{t.waitUntil(i)}catch(r){}}else try{h=await i}catch(t){r=t}if(!h)throw new n.WorkboxError("no-response",{url:e.url,error:r});return h}async o({request:t,event:e}){const n=await i.fetchWrapper.fetch({request:t,event:e,fetchOptions:this.i,plugins:this.s}),r=s.cacheWrapper.put({cacheName:this.t,request:t,response:n.clone(),event:e,plugins:this.s});if(e)try{e.waitUntil(r)}catch(t){}return n}},t}({},workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private);
//# sourceMappingURL=workbox-strategies.prod.js.map

@@ -20,3 +20,3 @@ import { RouteHandlerObject, RouteHandlerCallbackOptions, WorkboxPlugin } from 'workbox-core/types.js';

*
* @memberof workbox.strategies
* @memberof module:workbox-strategies
*/

@@ -32,3 +32,3 @@ declare class CacheFirst implements RouteHandlerObject {

* requests. Defaults to cache names provided by
* [workbox-core]{@link workbox.core.cacheNames}.
* [workbox-core]{@link module:workbox-core.cacheNames}.
* @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}

@@ -45,6 +45,6 @@ * to use in conjunction with this caching strategy.

* will work with the
* [Workbox Router]{@link workbox.routing.Router}.
* [Workbox Router]{@link module:workbox-routing.Router}.
*
* @param {Object} options
* @param {Request} options.request The request to run this strategy for.
* @param {Request|string} options.request A request to run this strategy for.
* @param {Event} [options.event] The event that triggered the request.

@@ -51,0 +51,0 @@ * @return {Promise<Response>}

@@ -28,3 +28,3 @@ /*

*
* @memberof workbox.strategies
* @memberof module:workbox-strategies
*/

@@ -36,3 +36,3 @@ class CacheFirst {

* requests. Defaults to cache names provided by
* [workbox-core]{@link workbox.core.cacheNames}.
* [workbox-core]{@link module:workbox-core.cacheNames}.
* @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}

@@ -54,6 +54,6 @@ * to use in conjunction with this caching strategy.

* will work with the
* [Workbox Router]{@link workbox.routing.Router}.
* [Workbox Router]{@link module:workbox-routing.Router}.
*
* @param {Object} options
* @param {Request} options.request The request to run this strategy for.
* @param {Request|string} options.request A request to run this strategy for.
* @param {Event} [options.event] The event that triggered the request.

@@ -64,2 +64,5 @@ * @return {Promise<Response>}

const logs = [];
if (typeof request === 'string') {
request = new Request(request);
}
if (process.env.NODE_ENV !== 'production') {

@@ -66,0 +69,0 @@ assert.isInstance(request, Request, {

@@ -18,3 +18,3 @@ import { RouteHandlerObject, RouteHandlerCallbackOptions, WorkboxPlugin } from 'workbox-core/types.js';

*
* @memberof workbox.strategies
* @memberof module:workbox-strategies
*/

@@ -29,3 +29,3 @@ declare class CacheOnly implements RouteHandlerObject {

* requests. Defaults to cache names provided by
* [workbox-core]{@link workbox.core.cacheNames}.
* [workbox-core]{@link module:workbox-core.cacheNames}.
* @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}

@@ -39,6 +39,6 @@ * to use in conjunction with this caching strategy.

* will work with the
* [Workbox Router]{@link workbox.routing.Router}.
* [Workbox Router]{@link module:workbox-routing.Router}.
*
* @param {Object} options
* @param {Request} options.request The request to run this strategy for.
* @param {Request|string} options.request A request to run this strategy for.
* @param {Event} [options.event] The event that triggered the request.

@@ -45,0 +45,0 @@ * @return {Promise<Response>}

@@ -25,3 +25,3 @@ /*

*
* @memberof workbox.strategies
* @memberof module:workbox-strategies
*/

@@ -33,3 +33,3 @@ class CacheOnly {

* requests. Defaults to cache names provided by
* [workbox-core]{@link workbox.core.cacheNames}.
* [workbox-core]{@link module:workbox-core.cacheNames}.
* @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}

@@ -47,6 +47,6 @@ * to use in conjunction with this caching strategy.

* will work with the
* [Workbox Router]{@link workbox.routing.Router}.
* [Workbox Router]{@link module:workbox-routing.Router}.
*
* @param {Object} options
* @param {Request} options.request The request to run this strategy for.
* @param {Request|string} options.request A request to run this strategy for.
* @param {Event} [options.event] The event that triggered the request.

@@ -56,2 +56,5 @@ * @return {Promise<Response>}

async handle({ event, request }) {
if (typeof request === 'string') {
request = new Request(request);
}
if (process.env.NODE_ENV !== 'production') {

@@ -58,0 +61,0 @@ assert.isInstance(request, Request, {

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

import { RouteHandler } from 'workbox-core/types.js';
import { CacheFirst } from './CacheFirst.js';

@@ -9,42 +8,7 @@ import { CacheOnly } from './CacheOnly.js';

/**
* @function workbox.strategies.cacheFirst
* @param {Object} options See the {@link workbox.strategies.CacheFirst}
* constructor for more info.
* @deprecated since v4.0.0
*/
declare const cacheFirst: (options: object) => RouteHandler;
/**
* @function workbox.strategies.cacheOnly
* @param {Object} options See the {@link workbox.strategies.CacheOnly}
* constructor for more info.
* @deprecated since v4.0.0
*/
declare const cacheOnly: (options: object) => RouteHandler;
/**
* @function workbox.strategies.networkFirst
* @param {Object} options See the {@link workbox.strategies.NetworkFirst}
* constructor for more info.
* @deprecated since v4.0.0
*/
declare const networkFirst: (options: object) => RouteHandler;
/**
* @function workbox.strategies.networkOnly
* @param {Object} options See the {@link workbox.strategies.NetworkOnly}
* constructor for more info.
* @deprecated since v4.0.0
*/
declare const networkOnly: (options: object) => RouteHandler;
/**
* @function workbox.strategies.staleWhileRevalidate
* @param {Object} options See the
* {@link workbox.strategies.StaleWhileRevalidate} constructor for more info.
* @deprecated since v4.0.0
*/
declare const staleWhileRevalidate: (options: object) => RouteHandler;
/**
* There are common caching strategies that most service workers will need
* and use. This module provides simple implementations of these strategies.
*
* @namespace workbox.strategies
* @module workbox-strategies
*/
export { CacheFirst, CacheOnly, NetworkFirst, NetworkOnly, StaleWhileRevalidate, cacheFirst, cacheOnly, networkFirst, networkOnly, staleWhileRevalidate, };
export { CacheFirst, CacheOnly, NetworkFirst, NetworkOnly, StaleWhileRevalidate, };

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

*/
import { logger } from 'workbox-core/_private/logger.js';
import { CacheFirst } from './CacheFirst.js';

@@ -16,64 +15,8 @@ import { CacheOnly } from './CacheOnly.js';

import './_version.js';
const mapping = {
cacheFirst: CacheFirst,
cacheOnly: CacheOnly,
networkFirst: NetworkFirst,
networkOnly: NetworkOnly,
staleWhileRevalidate: StaleWhileRevalidate,
};
const deprecate = (strategy) => {
const StrategyCtr = mapping[strategy];
return (options) => {
if (process.env.NODE_ENV !== 'production') {
const strategyCtrName = strategy[0].toUpperCase() + strategy.slice(1);
logger.warn(`The 'workbox.strategies.${strategy}()' function has been ` +
`deprecated and will be removed in a future version of Workbox.\n` +
`Please use 'new workbox.strategies.${strategyCtrName}()' instead.`);
}
return new StrategyCtr(options);
};
};
/**
* @function workbox.strategies.cacheFirst
* @param {Object} options See the {@link workbox.strategies.CacheFirst}
* constructor for more info.
* @deprecated since v4.0.0
*/
const cacheFirst = deprecate('cacheFirst');
/**
* @function workbox.strategies.cacheOnly
* @param {Object} options See the {@link workbox.strategies.CacheOnly}
* constructor for more info.
* @deprecated since v4.0.0
*/
const cacheOnly = deprecate('cacheOnly');
/**
* @function workbox.strategies.networkFirst
* @param {Object} options See the {@link workbox.strategies.NetworkFirst}
* constructor for more info.
* @deprecated since v4.0.0
*/
const networkFirst = deprecate('networkFirst');
/**
* @function workbox.strategies.networkOnly
* @param {Object} options See the {@link workbox.strategies.NetworkOnly}
* constructor for more info.
* @deprecated since v4.0.0
*/
const networkOnly = deprecate('networkOnly');
/**
* @function workbox.strategies.staleWhileRevalidate
* @param {Object} options See the
* {@link workbox.strategies.StaleWhileRevalidate} constructor for more info.
* @deprecated since v4.0.0
*/
const staleWhileRevalidate = deprecate('staleWhileRevalidate');
/**
* There are common caching strategies that most service workers will need
* and use. This module provides simple implementations of these strategies.
*
* @namespace workbox.strategies
* @module workbox-strategies
*/
export { CacheFirst, CacheOnly, NetworkFirst, NetworkOnly, StaleWhileRevalidate,
// Deprecated...
cacheFirst, cacheOnly, networkFirst, networkOnly, staleWhileRevalidate, };
export { CacheFirst, CacheOnly, NetworkFirst, NetworkOnly, StaleWhileRevalidate, };

@@ -23,3 +23,3 @@ import { RouteHandlerObject, RouteHandlerCallbackOptions, WorkboxPlugin } from 'workbox-core/types.js';

*
* @memberof workbox.strategies
* @memberof module:workbox-strategies
*/

@@ -36,3 +36,3 @@ declare class NetworkFirst implements RouteHandlerObject {

* requests. Defaults to cache names provided by
* [workbox-core]{@link workbox.core.cacheNames}.
* [workbox-core]{@link module:workbox-core.cacheNames}.
* @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}

@@ -55,6 +55,6 @@ * to use in conjunction with this caching strategy.

* will work with the
* [Workbox Router]{@link workbox.routing.Router}.
* [Workbox Router]{@link module:workbox-routing.Router}.
*
* @param {Object} options
* @param {Request} options.request The request to run this strategy for.
* @param {Request|string} options.request A request to run this strategy for.
* @param {Event} [options.event] The event that triggered the request.

@@ -61,0 +61,0 @@ * @return {Promise<Response>}

@@ -31,3 +31,3 @@ /*

*
* @memberof workbox.strategies
* @memberof module:workbox-strategies
*/

@@ -39,3 +39,3 @@ class NetworkFirst {

* requests. Defaults to cache names provided by
* [workbox-core]{@link workbox.core.cacheNames}.
* [workbox-core]{@link module:workbox-core.cacheNames}.
* @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}

@@ -82,6 +82,6 @@ * to use in conjunction with this caching strategy.

* will work with the
* [Workbox Router]{@link workbox.routing.Router}.
* [Workbox Router]{@link module:workbox-routing.Router}.
*
* @param {Object} options
* @param {Request} options.request The request to run this strategy for.
* @param {Request|string} options.request A request to run this strategy for.
* @param {Event} [options.event] The event that triggered the request.

@@ -92,2 +92,5 @@ * @return {Promise<Response>}

const logs = [];
if (typeof request === 'string') {
request = new Request(request);
}
if (process.env.NODE_ENV !== 'production') {

@@ -94,0 +97,0 @@ assert.isInstance(request, Request, {

@@ -17,3 +17,3 @@ import { RouteHandlerObject, RouteHandlerCallbackOptions, WorkboxPlugin } from 'workbox-core/types.js';

*
* @memberof workbox.strategies
* @memberof module:workbox-strategies
*/

@@ -27,3 +27,3 @@ declare class NetworkOnly implements RouteHandlerObject {

* requests. Defaults to cache names provided by
* [workbox-core]{@link workbox.core.cacheNames}.
* [workbox-core]{@link module:workbox-core.cacheNames}.
* @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}

@@ -39,6 +39,6 @@ * to use in conjunction with this caching strategy.

* will work with the
* [Workbox Router]{@link workbox.routing.Router}.
* [Workbox Router]{@link module:workbox-routing.Router}.
*
* @param {Object} options
* @param {Request} options.request The request to run this strategy for.
* @param {Request|string} options.request The request to run this strategy for.
* @param {Event} [options.event] The event that triggered the request.

@@ -45,0 +45,0 @@ * @return {Promise<Response>}

@@ -24,3 +24,3 @@ /*

*
* @memberof workbox.strategies
* @memberof module:workbox-strategies
*/

@@ -32,3 +32,3 @@ class NetworkOnly {

* requests. Defaults to cache names provided by
* [workbox-core]{@link workbox.core.cacheNames}.
* [workbox-core]{@link module:workbox-core.cacheNames}.
* @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}

@@ -47,6 +47,6 @@ * to use in conjunction with this caching strategy.

* will work with the
* [Workbox Router]{@link workbox.routing.Router}.
* [Workbox Router]{@link module:workbox-routing.Router}.
*
* @param {Object} options
* @param {Request} options.request The request to run this strategy for.
* @param {Request|string} options.request The request to run this strategy for.
* @param {Event} [options.event] The event that triggered the request.

@@ -56,2 +56,5 @@ * @return {Promise<Response>}

async handle({ event, request }) {
if (typeof request === 'string') {
request = new Request(request);
}
if (process.env.NODE_ENV !== 'production') {

@@ -58,0 +61,0 @@ assert.isInstance(request, Request, {

{
"name": "workbox-strategies",
"version": "5.0.0-rc.1",
"version": "5.0.0-rc.2",
"license": "MIT",

@@ -31,6 +31,6 @@ "author": "Google's Web DevRel Team",

"dependencies": {
"workbox-core": "^5.0.0-rc.1",
"workbox-routing": "^5.0.0-rc.1"
"workbox-core": "^5.0.0-rc.2",
"workbox-routing": "^5.0.0-rc.2"
},
"gitHead": "f03f71e50507e13d82d4e0a875cc49ba4501aff3"
"gitHead": "89904768b2210e59c830dd380cf88a06e1c26a2b"
}
// @ts-ignore
try{self['workbox:strategies:5.0.0-rc.1']&&_()}catch(e){}
try{self['workbox:strategies:5.0.0-rc.2']&&_()}catch(e){}

@@ -39,3 +39,3 @@ /*

*
* @memberof workbox.strategies
* @memberof module:workbox-strategies
*/

@@ -52,3 +52,3 @@ class CacheFirst implements RouteHandlerObject {

* requests. Defaults to cache names provided by
* [workbox-core]{@link workbox.core.cacheNames}.
* [workbox-core]{@link module:workbox-core.cacheNames}.
* @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}

@@ -71,6 +71,6 @@ * to use in conjunction with this caching strategy.

* will work with the
* [Workbox Router]{@link workbox.routing.Router}.
* [Workbox Router]{@link module:workbox-routing.Router}.
*
* @param {Object} options
* @param {Request} options.request The request to run this strategy for.
* @param {Request|string} options.request A request to run this strategy for.
* @param {Event} [options.event] The event that triggered the request.

@@ -82,2 +82,6 @@ * @return {Promise<Response>}

if (typeof request === 'string') {
request = new Request(request);
}
if (process.env.NODE_ENV !== 'production') {

@@ -84,0 +88,0 @@ assert!.isInstance(request, Request, {

@@ -35,3 +35,3 @@ /*

*
* @memberof workbox.strategies
* @memberof module:workbox-strategies
*/

@@ -47,3 +47,3 @@ class CacheOnly implements RouteHandlerObject {

* requests. Defaults to cache names provided by
* [workbox-core]{@link workbox.core.cacheNames}.
* [workbox-core]{@link module:workbox-core.cacheNames}.
* @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}

@@ -62,6 +62,6 @@ * to use in conjunction with this caching strategy.

* will work with the
* [Workbox Router]{@link workbox.routing.Router}.
* [Workbox Router]{@link module:workbox-routing.Router}.
*
* @param {Object} options
* @param {Request} options.request The request to run this strategy for.
* @param {Request|string} options.request A request to run this strategy for.
* @param {Event} [options.event] The event that triggered the request.

@@ -71,2 +71,6 @@ * @return {Promise<Response>}

async handle({event, request}: RouteHandlerCallbackOptions): Promise<Response> {
if (typeof request === 'string') {
request = new Request(request);
}
if (process.env.NODE_ENV !== 'production') {

@@ -73,0 +77,0 @@ assert!.isInstance(request, Request, {

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

import {logger} from 'workbox-core/_private/logger.js';
import {RouteHandler} from 'workbox-core/types.js';
import {CacheFirst} from './CacheFirst.js';

@@ -20,77 +18,7 @@ import {CacheOnly} from './CacheOnly.js';

interface StrategyClass {
new({}: object): RouteHandler
}
interface StrategyDeprecationMap {
[strategyName: string]: StrategyClass;
}
const mapping: StrategyDeprecationMap = {
cacheFirst: CacheFirst,
cacheOnly: CacheOnly,
networkFirst: NetworkFirst,
networkOnly: NetworkOnly,
staleWhileRevalidate: StaleWhileRevalidate,
};
const deprecate = (strategy: string) => {
const StrategyCtr = mapping[strategy];
return (options: object) => {
if (process.env.NODE_ENV !== 'production') {
const strategyCtrName = strategy[0].toUpperCase() + strategy.slice(1);
logger.warn(`The 'workbox.strategies.${strategy}()' function has been ` +
`deprecated and will be removed in a future version of Workbox.\n` +
`Please use 'new workbox.strategies.${strategyCtrName}()' instead.`);
}
return new StrategyCtr(options);
};
};
/**
* @function workbox.strategies.cacheFirst
* @param {Object} options See the {@link workbox.strategies.CacheFirst}
* constructor for more info.
* @deprecated since v4.0.0
*/
const cacheFirst = deprecate('cacheFirst');
/**
* @function workbox.strategies.cacheOnly
* @param {Object} options See the {@link workbox.strategies.CacheOnly}
* constructor for more info.
* @deprecated since v4.0.0
*/
const cacheOnly = deprecate('cacheOnly');
/**
* @function workbox.strategies.networkFirst
* @param {Object} options See the {@link workbox.strategies.NetworkFirst}
* constructor for more info.
* @deprecated since v4.0.0
*/
const networkFirst = deprecate('networkFirst');
/**
* @function workbox.strategies.networkOnly
* @param {Object} options See the {@link workbox.strategies.NetworkOnly}
* constructor for more info.
* @deprecated since v4.0.0
*/
const networkOnly = deprecate('networkOnly');
/**
* @function workbox.strategies.staleWhileRevalidate
* @param {Object} options See the
* {@link workbox.strategies.StaleWhileRevalidate} constructor for more info.
* @deprecated since v4.0.0
*/
const staleWhileRevalidate = deprecate('staleWhileRevalidate');
/**
* There are common caching strategies that most service workers will need
* and use. This module provides simple implementations of these strategies.
*
* @namespace workbox.strategies
* @module workbox-strategies
*/

@@ -104,10 +32,3 @@

StaleWhileRevalidate,
// Deprecated...
cacheFirst,
cacheOnly,
networkFirst,
networkOnly,
staleWhileRevalidate,
};

@@ -43,3 +43,3 @@ /*

*
* @memberof workbox.strategies
* @memberof module:workbox-strategies
*/

@@ -57,3 +57,3 @@ class NetworkFirst implements RouteHandlerObject {

* requests. Defaults to cache names provided by
* [workbox-core]{@link workbox.core.cacheNames}.
* [workbox-core]{@link module:workbox-core.cacheNames}.
* @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}

@@ -104,6 +104,6 @@ * to use in conjunction with this caching strategy.

* will work with the
* [Workbox Router]{@link workbox.routing.Router}.
* [Workbox Router]{@link module:workbox-routing.Router}.
*
* @param {Object} options
* @param {Request} options.request The request to run this strategy for.
* @param {Request|string} options.request A request to run this strategy for.
* @param {Event} [options.event] The event that triggered the request.

@@ -113,3 +113,7 @@ * @return {Promise<Response>}

async handle({event, request}: RouteHandlerCallbackOptions): Promise<Response> {
const logs: any[] = [];
const logs: any[] = [];
if (typeof request === 'string') {
request = new Request(request);
}

@@ -116,0 +120,0 @@ if (process.env.NODE_ENV !== 'production') {

@@ -33,3 +33,3 @@ /*

*
* @memberof workbox.strategies
* @memberof module:workbox-strategies
*/

@@ -44,3 +44,3 @@ class NetworkOnly implements RouteHandlerObject {

* requests. Defaults to cache names provided by
* [workbox-core]{@link workbox.core.cacheNames}.
* [workbox-core]{@link module:workbox-core.cacheNames}.
* @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}

@@ -60,6 +60,6 @@ * to use in conjunction with this caching strategy.

* will work with the
* [Workbox Router]{@link workbox.routing.Router}.
* [Workbox Router]{@link module:workbox-routing.Router}.
*
* @param {Object} options
* @param {Request} options.request The request to run this strategy for.
* @param {Request|string} options.request The request to run this strategy for.
* @param {Event} [options.event] The event that triggered the request.

@@ -69,2 +69,6 @@ * @return {Promise<Response>}

async handle({event, request}: RouteHandlerCallbackOptions): Promise<Response> {
if (typeof request === 'string') {
request = new Request(request);
}
if (process.env.NODE_ENV !== 'production') {

@@ -71,0 +75,0 @@ assert!.isInstance(request, Request, {

@@ -47,3 +47,3 @@ /*

*
* @memberof workbox.strategies
* @memberof module:workbox-strategies
*/

@@ -60,3 +60,3 @@ class StaleWhileRevalidate implements RouteHandlerObject {

* requests. Defaults to cache names provided by
* [workbox-core]{@link workbox.core.cacheNames}.
* [workbox-core]{@link module:workbox-core.cacheNames}.
* @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}

@@ -90,6 +90,6 @@ * to use in conjunction with this caching strategy.

* will work with the
* [Workbox Router]{@link workbox.routing.Router}.
* [Workbox Router]{@link module:workbox-routing.Router}.
*
* @param {Object} options
* @param {Request} options.request The request to run this strategy for.
* @param {Request|string} options.request A request to run this strategy for.
* @param {Event} [options.event] The event that triggered the request.

@@ -99,4 +99,8 @@ * @return {Promise<Response>}

async handle({event, request}: RouteHandlerCallbackOptions): Promise<Response> {
const logs = [];
const logs = [];
if (typeof request === 'string') {
request = new Request(request);
}
if (process.env.NODE_ENV !== 'production') {

@@ -103,0 +107,0 @@ assert!.isInstance(request, Request, {

@@ -27,3 +27,3 @@ import { RouteHandlerObject, RouteHandlerCallbackOptions, WorkboxPlugin } from 'workbox-core/types.js';

*
* @memberof workbox.strategies
* @memberof module:workbox-strategies
*/

@@ -39,3 +39,3 @@ declare class StaleWhileRevalidate implements RouteHandlerObject {

* requests. Defaults to cache names provided by
* [workbox-core]{@link workbox.core.cacheNames}.
* [workbox-core]{@link module:workbox-core.cacheNames}.
* @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}

@@ -52,6 +52,6 @@ * to use in conjunction with this caching strategy.

* will work with the
* [Workbox Router]{@link workbox.routing.Router}.
* [Workbox Router]{@link module:workbox-routing.Router}.
*
* @param {Object} options
* @param {Request} options.request The request to run this strategy for.
* @param {Request|string} options.request A request to run this strategy for.
* @param {Event} [options.event] The event that triggered the request.

@@ -58,0 +58,0 @@ * @return {Promise<Response>}

@@ -36,3 +36,3 @@ /*

*
* @memberof workbox.strategies
* @memberof module:workbox-strategies
*/

@@ -44,3 +44,3 @@ class StaleWhileRevalidate {

* requests. Defaults to cache names provided by
* [workbox-core]{@link workbox.core.cacheNames}.
* [workbox-core]{@link module:workbox-core.cacheNames}.
* @param {Array<Object>} options.plugins [Plugins]{@link https://developers.google.com/web/tools/workbox/guides/using-plugins}

@@ -71,6 +71,6 @@ * to use in conjunction with this caching strategy.

* will work with the
* [Workbox Router]{@link workbox.routing.Router}.
* [Workbox Router]{@link module:workbox-routing.Router}.
*
* @param {Object} options
* @param {Request} options.request The request to run this strategy for.
* @param {Request|string} options.request A request to run this strategy for.
* @param {Event} [options.event] The event that triggered the request.

@@ -81,2 +81,5 @@ * @return {Promise<Response>}

const logs = [];
if (typeof request === 'string') {
request = new Request(request);
}
if (process.env.NODE_ENV !== 'production') {

@@ -83,0 +86,0 @@ assert.isInstance(request, Request, {

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

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