Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

workbox-precaching

Package Overview
Dependencies
Maintainers
6
Versions
96
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

workbox-precaching - npm Package Compare versions

Comparing version 6.1.5 to 6.2.0-alpha.0

2

_version.js
"use strict";
// @ts-ignore
try {
self['workbox:precaching:6.1.5'] && _();
self['workbox:precaching:6.2.0-alpha.0'] && _();
}
catch (e) { }

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

try {
self['workbox:precaching:6.1.5'] && _();
self['workbox:precaching:6.2.0-alpha.0'] && _();
} catch (e) {}

@@ -131,9 +131,11 @@

if (event.type === 'install') {
// TODO: `state` should never be undefined...
const url = state.originalRequest.url;
if (state && state.originalRequest && state.originalRequest instanceof Request) {
// TODO: `state` should never be undefined...
const url = state.originalRequest.url;
if (cachedResponse) {
this.notUpdatedURLs.push(url);
} else {
this.updatedURLs.push(url);
if (cachedResponse) {
this.notUpdatedURLs.push(url);
} else {
this.updatedURLs.push(url);
}
}

@@ -170,2 +172,4 @@ }

}) => {
// Params is type any, can't change right now.
// eslint-disable-next-line
const cacheKey = params && params.cacheKey || this._precacheController.getCacheKeyForURL(request.url);

@@ -373,6 +377,10 @@

{
// Params in handlers is type any, can't change right now.
// eslint-disable-next-line
const cacheKey = handler.params && handler.params.cacheKey || (await handler.getCacheKey(request, 'read')); // Workbox is going to handle the route.
// print the routing details to the console.
logger_js.logger.groupCollapsed(`Precaching is responding to: ` + getFriendlyURL_js.getFriendlyURL(request.url));
logger_js.logger.groupCollapsed(`Precaching is responding to: ` + getFriendlyURL_js.getFriendlyURL(request.url)); // cacheKey is type any, can't change right now.
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
logger_js.logger.log(`Serving the precached url: ${getFriendlyURL_js.getFriendlyURL(cacheKey.url)}`);

@@ -635,2 +643,4 @@ logger_js.logger.groupCollapsed(`View request details here.`);

install(event) {
// waitUntil returns Promise<any>
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return waitUntil_js.waitUntil(event, async () => {

@@ -688,2 +698,4 @@ const installReportPlugin = new PrecacheInstallReportPlugin();

activate(event) {
// waitUntil returns Promise<any>
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return waitUntil_js.waitUntil(event, async () => {

@@ -690,0 +702,0 @@ const cache = await self.caches.open(this.strategy.cacheName);

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

this.workbox=this.workbox||{},this.workbox.precaching=function(t,e,s,n,i,c,r,o){"use strict";function a(){return(a=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var s=arguments[e];for(var n in s)Object.prototype.hasOwnProperty.call(s,n)&&(t[n]=s[n])}return t}).apply(this,arguments)}try{self["workbox:precaching:6.1.5"]&&_()}catch(t){}function h(t){if(!t)throw new s.WorkboxError("add-to-cache-list-unexpected-type",{entry:t});if("string"==typeof t){const e=new URL(t,location.href);return{cacheKey:e.href,url:e.href}}const{revision:e,url:n}=t;if(!n)throw new s.WorkboxError("add-to-cache-list-unexpected-type",{entry:t});if(!e){const t=new URL(n,location.href);return{cacheKey:t.href,url:t.href}}const i=new URL(n,location.href),c=new URL(n,location.href);return i.searchParams.set("__WB_REVISION__",e),{cacheKey:i.href,url:c.href}}class l{constructor(){this.updatedURLs=[],this.notUpdatedURLs=[],this.handlerWillStart=async({request:t,state:e})=>{e&&(e.originalRequest=t)},this.cachedResponseWillBeUsed=async({event:t,state:e,cachedResponse:s})=>{if("install"===t.type){const t=e.originalRequest.url;s?this.notUpdatedURLs.push(t):this.updatedURLs.push(t)}return s}}}class u{constructor({precacheController:t}){this.cacheKeyWillBeUsed=async({request:t,params:e})=>{const s=e&&e.cacheKey||this.et.getCacheKeyForURL(t.url);return s?new Request(s):t},this.et=t}}class f extends c.Strategy{constructor(t={}){t.cacheName=e.cacheNames.getPrecacheName(t.cacheName),super(t),this.st=!1!==t.fallbackToNetwork,this.plugins.push(f.copyRedirectedCacheableResponsesPlugin)}async _handle(t,e){const s=await e.cacheMatch(t);return s||(e.event&&"install"===e.event.type?await this.nt(t,e):await this.it(t,e))}async it(t,e){let n;if(!this.st)throw new s.WorkboxError("missing-precache-entry",{cacheName:this.cacheName,url:t.url});return n=await e.fetch(t),n}async nt(t,e){this.ct();const n=await e.fetch(t);if(!await e.cachePut(t,n.clone()))throw new s.WorkboxError("bad-precaching-response",{url:t.url,status:n.status});return n}ct(){let t=null,e=0;for(const[s,n]of this.plugins.entries())n!==f.copyRedirectedCacheableResponsesPlugin&&(n===f.defaultPrecacheCacheabilityPlugin&&(t=s),n.cacheWillUpdate&&e++);0===e?this.plugins.push(f.defaultPrecacheCacheabilityPlugin):e>1&&null!==t&&this.plugins.splice(t,1)}}f.defaultPrecacheCacheabilityPlugin={cacheWillUpdate:async({response:t})=>!t||t.status>=400?null:t},f.copyRedirectedCacheableResponsesPlugin={cacheWillUpdate:async({response:t})=>t.redirected?await i.copyResponse(t):t};class w{constructor({cacheName:t,plugins:s=[],fallbackToNetwork:n=!0}={}){this.rt=new Map,this.ot=new Map,this.at=new Map,this.ht=new f({cacheName:e.cacheNames.getPrecacheName(t),plugins:[...s,new u({precacheController:this})],fallbackToNetwork:n}),this.install=this.install.bind(this),this.activate=this.activate.bind(this)}get strategy(){return this.ht}precache(t){this.addToCacheList(t),this.lt||(self.addEventListener("install",this.install),self.addEventListener("activate",this.activate),this.lt=!0)}addToCacheList(t){const e=[];for(const n of t){"string"==typeof n?e.push(n):n&&void 0===n.revision&&e.push(n.url);const{cacheKey:t,url:i}=h(n),c="string"!=typeof n&&n.revision?"reload":"default";if(this.rt.has(i)&&this.rt.get(i)!==t)throw new s.WorkboxError("add-to-cache-list-conflicting-entries",{firstEntry:this.rt.get(i),secondEntry:t});if("string"!=typeof n&&n.integrity){if(this.at.has(t)&&this.at.get(t)!==n.integrity)throw new s.WorkboxError("add-to-cache-list-conflicting-integrities",{url:i});this.at.set(t,n.integrity)}if(this.rt.set(i,t),this.ot.set(i,c),e.length>0){const t=`Workbox is precaching URLs without revision info: ${e.join(", ")}\nThis is generally NOT safe. Learn more at https://bit.ly/wb-precache`;console.warn(t)}}}install(t){return n.waitUntil(t,(async()=>{const e=new l;this.strategy.plugins.push(e);for(const[e,s]of this.rt){const n=this.at.get(s),i=this.ot.get(e),c=new Request(e,{integrity:n,cache:i,credentials:"same-origin"});await Promise.all(this.strategy.handleAll({params:{cacheKey:s},request:c,event:t}))}const{updatedURLs:s,notUpdatedURLs:n}=e;return{updatedURLs:s,notUpdatedURLs:n}}))}activate(t){return n.waitUntil(t,(async()=>{const t=await self.caches.open(this.strategy.cacheName),e=await t.keys(),s=new Set(this.rt.values()),n=[];for(const i of e)s.has(i.url)||(await t.delete(i),n.push(i.url));return{deletedURLs:n}}))}getURLsToCacheKeys(){return this.rt}getCachedURLs(){return[...this.rt.keys()]}getCacheKeyForURL(t){const e=new URL(t,location.href);return this.rt.get(e.href)}async matchPrecache(t){const e=t instanceof Request?t.url:t,s=this.getCacheKeyForURL(e);if(s){return(await self.caches.open(this.strategy.cacheName)).match(s)}}createHandlerBoundToURL(t){const e=this.getCacheKeyForURL(t);if(!e)throw new s.WorkboxError("non-precached-url",{url:t});return s=>(s.request=new Request(t),s.params=a({cacheKey:e},s.params),this.strategy.handle(s))}}let d;const y=()=>(d||(d=new w),d);class p extends o.Route{constructor(t,e){super((({request:s})=>{const n=t.getURLsToCacheKeys();for(const t of function*(t,{ignoreURLParametersMatching:e=[/^utm_/,/^fbclid$/],directoryIndex:s="index.html",cleanURLs:n=!0,urlManipulation:i}={}){const c=new URL(t,location.href);c.hash="",yield c.href;const r=function(t,e=[]){for(const s of[...t.searchParams.keys()])e.some((t=>t.test(s)))&&t.searchParams.delete(s);return t}(c,e);if(yield r.href,s&&r.pathname.endsWith("/")){const t=new URL(r.href);t.pathname+=s,yield t.href}if(n){const t=new URL(r.href);t.pathname+=".html",yield t.href}if(i){const t=i({url:c});for(const e of t)yield e.href}}(s.url,e)){const e=n.get(t);if(e)return{cacheKey:e}}}),t.strategy)}}function R(t){const e=y(),s=new p(e,t);r.registerRoute(s)}function U(t){y().precache(t)}return t.PrecacheController=w,t.PrecacheFallbackPlugin=class{constructor({fallbackURL:t,precacheController:e}){this.handlerDidError=()=>this.et.matchPrecache(this.ut),this.ut=t,this.et=e||y()}},t.PrecacheRoute=p,t.PrecacheStrategy=f,t.addPlugins=function(t){y().strategy.plugins.push(...t)},t.addRoute=R,t.cleanupOutdatedCaches=function(){self.addEventListener("activate",(t=>{const s=e.cacheNames.getPrecacheName();t.waitUntil((async(t,e="-precache-")=>{const s=(await self.caches.keys()).filter((s=>s.includes(e)&&s.includes(self.registration.scope)&&s!==t));return await Promise.all(s.map((t=>self.caches.delete(t)))),s})(s).then((t=>{})))}))},t.createHandlerBoundToURL=function(t){return y().createHandlerBoundToURL(t)},t.getCacheKeyForURL=function(t){return y().getCacheKeyForURL(t)},t.matchPrecache=function(t){return y().matchPrecache(t)},t.precache=U,t.precacheAndRoute=function(t,e){U(t),R(e)},t}({},workbox.core._private,workbox.core._private,workbox.core._private,workbox.core,workbox.strategies,workbox.routing,workbox.routing);
this.workbox=this.workbox||{},this.workbox.precaching=function(t,e,s,n,i,c,r,o){"use strict";function a(){return(a=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var s=arguments[e];for(var n in s)Object.prototype.hasOwnProperty.call(s,n)&&(t[n]=s[n])}return t}).apply(this,arguments)}try{self["workbox:precaching:6.2.0-alpha.0"]&&_()}catch(t){}function h(t){if(!t)throw new s.WorkboxError("add-to-cache-list-unexpected-type",{entry:t});if("string"==typeof t){const e=new URL(t,location.href);return{cacheKey:e.href,url:e.href}}const{revision:e,url:n}=t;if(!n)throw new s.WorkboxError("add-to-cache-list-unexpected-type",{entry:t});if(!e){const t=new URL(n,location.href);return{cacheKey:t.href,url:t.href}}const i=new URL(n,location.href),c=new URL(n,location.href);return i.searchParams.set("__WB_REVISION__",e),{cacheKey:i.href,url:c.href}}class l{constructor(){this.updatedURLs=[],this.notUpdatedURLs=[],this.handlerWillStart=async({request:t,state:e})=>{e&&(e.originalRequest=t)},this.cachedResponseWillBeUsed=async({event:t,state:e,cachedResponse:s})=>{if("install"===t.type&&e&&e.originalRequest&&e.originalRequest instanceof Request){const t=e.originalRequest.url;s?this.notUpdatedURLs.push(t):this.updatedURLs.push(t)}return s}}}class u{constructor({precacheController:t}){this.cacheKeyWillBeUsed=async({request:t,params:e})=>{const s=e&&e.cacheKey||this.Y.getCacheKeyForURL(t.url);return s?new Request(s):t},this.Y=t}}class f extends c.Strategy{constructor(t={}){t.cacheName=e.cacheNames.getPrecacheName(t.cacheName),super(t),this.Z=!1!==t.fallbackToNetwork,this.plugins.push(f.copyRedirectedCacheableResponsesPlugin)}async _handle(t,e){const s=await e.cacheMatch(t);return s||(e.event&&"install"===e.event.type?await this.tt(t,e):await this.et(t,e))}async et(t,e){let n;if(!this.Z)throw new s.WorkboxError("missing-precache-entry",{cacheName:this.cacheName,url:t.url});return n=await e.fetch(t),n}async tt(t,e){this.st();const n=await e.fetch(t);if(!await e.cachePut(t,n.clone()))throw new s.WorkboxError("bad-precaching-response",{url:t.url,status:n.status});return n}st(){let t=null,e=0;for(const[s,n]of this.plugins.entries())n!==f.copyRedirectedCacheableResponsesPlugin&&(n===f.defaultPrecacheCacheabilityPlugin&&(t=s),n.cacheWillUpdate&&e++);0===e?this.plugins.push(f.defaultPrecacheCacheabilityPlugin):e>1&&null!==t&&this.plugins.splice(t,1)}}f.defaultPrecacheCacheabilityPlugin={cacheWillUpdate:async({response:t})=>!t||t.status>=400?null:t},f.copyRedirectedCacheableResponsesPlugin={cacheWillUpdate:async({response:t})=>t.redirected?await i.copyResponse(t):t};class w{constructor({cacheName:t,plugins:s=[],fallbackToNetwork:n=!0}={}){this.nt=new Map,this.it=new Map,this.ct=new Map,this.rt=new f({cacheName:e.cacheNames.getPrecacheName(t),plugins:[...s,new u({precacheController:this})],fallbackToNetwork:n}),this.install=this.install.bind(this),this.activate=this.activate.bind(this)}get strategy(){return this.rt}precache(t){this.addToCacheList(t),this.ot||(self.addEventListener("install",this.install),self.addEventListener("activate",this.activate),this.ot=!0)}addToCacheList(t){const e=[];for(const n of t){"string"==typeof n?e.push(n):n&&void 0===n.revision&&e.push(n.url);const{cacheKey:t,url:i}=h(n),c="string"!=typeof n&&n.revision?"reload":"default";if(this.nt.has(i)&&this.nt.get(i)!==t)throw new s.WorkboxError("add-to-cache-list-conflicting-entries",{firstEntry:this.nt.get(i),secondEntry:t});if("string"!=typeof n&&n.integrity){if(this.ct.has(t)&&this.ct.get(t)!==n.integrity)throw new s.WorkboxError("add-to-cache-list-conflicting-integrities",{url:i});this.ct.set(t,n.integrity)}if(this.nt.set(i,t),this.it.set(i,c),e.length>0){const t=`Workbox is precaching URLs without revision info: ${e.join(", ")}\nThis is generally NOT safe. Learn more at https://bit.ly/wb-precache`;console.warn(t)}}}install(t){return n.waitUntil(t,(async()=>{const e=new l;this.strategy.plugins.push(e);for(const[e,s]of this.nt){const n=this.ct.get(s),i=this.it.get(e),c=new Request(e,{integrity:n,cache:i,credentials:"same-origin"});await Promise.all(this.strategy.handleAll({params:{cacheKey:s},request:c,event:t}))}const{updatedURLs:s,notUpdatedURLs:n}=e;return{updatedURLs:s,notUpdatedURLs:n}}))}activate(t){return n.waitUntil(t,(async()=>{const t=await self.caches.open(this.strategy.cacheName),e=await t.keys(),s=new Set(this.nt.values()),n=[];for(const i of e)s.has(i.url)||(await t.delete(i),n.push(i.url));return{deletedURLs:n}}))}getURLsToCacheKeys(){return this.nt}getCachedURLs(){return[...this.nt.keys()]}getCacheKeyForURL(t){const e=new URL(t,location.href);return this.nt.get(e.href)}async matchPrecache(t){const e=t instanceof Request?t.url:t,s=this.getCacheKeyForURL(e);if(s){return(await self.caches.open(this.strategy.cacheName)).match(s)}}createHandlerBoundToURL(t){const e=this.getCacheKeyForURL(t);if(!e)throw new s.WorkboxError("non-precached-url",{url:t});return s=>(s.request=new Request(t),s.params=a({cacheKey:e},s.params),this.strategy.handle(s))}}let d;const y=()=>(d||(d=new w),d);class p extends o.Route{constructor(t,e){super((({request:s})=>{const n=t.getURLsToCacheKeys();for(const t of function*(t,{ignoreURLParametersMatching:e=[/^utm_/,/^fbclid$/],directoryIndex:s="index.html",cleanURLs:n=!0,urlManipulation:i}={}){const c=new URL(t,location.href);c.hash="",yield c.href;const r=function(t,e=[]){for(const s of[...t.searchParams.keys()])e.some((t=>t.test(s)))&&t.searchParams.delete(s);return t}(c,e);if(yield r.href,s&&r.pathname.endsWith("/")){const t=new URL(r.href);t.pathname+=s,yield t.href}if(n){const t=new URL(r.href);t.pathname+=".html",yield t.href}if(i){const t=i({url:c});for(const e of t)yield e.href}}(s.url,e)){const e=n.get(t);if(e)return{cacheKey:e}}}),t.strategy)}}function R(t){const e=y(),s=new p(e,t);r.registerRoute(s)}function U(t){y().precache(t)}return t.PrecacheController=w,t.PrecacheFallbackPlugin=class{constructor({fallbackURL:t,precacheController:e}){this.handlerDidError=()=>this.Y.matchPrecache(this.at),this.at=t,this.Y=e||y()}},t.PrecacheRoute=p,t.PrecacheStrategy=f,t.addPlugins=function(t){y().strategy.plugins.push(...t)},t.addRoute=R,t.cleanupOutdatedCaches=function(){self.addEventListener("activate",(t=>{const s=e.cacheNames.getPrecacheName();t.waitUntil((async(t,e="-precache-")=>{const s=(await self.caches.keys()).filter((s=>s.includes(e)&&s.includes(self.registration.scope)&&s!==t));return await Promise.all(s.map((t=>self.caches.delete(t)))),s})(s).then((t=>{})))}))},t.createHandlerBoundToURL=function(t){return y().createHandlerBoundToURL(t)},t.getCacheKeyForURL=function(t){return y().getCacheKeyForURL(t)},t.matchPrecache=function(t){return y().matchPrecache(t)},t.precache=U,t.precacheAndRoute=function(t,e){U(t),R(e)},t}({},workbox.core._private,workbox.core._private,workbox.core._private,workbox.core,workbox.strategies,workbox.routing,workbox.routing);
//# sourceMappingURL=workbox-precaching.prod.js.map

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

import { RouteHandlerCallback } from 'workbox-core/types.js';
import './_version.js';

@@ -19,3 +20,3 @@ /**

*/
declare function createHandlerBoundToURL(url: string): import("workbox-core/types").RouteHandlerCallback;
declare function createHandlerBoundToURL(url: string): RouteHandlerCallback;
export { createHandlerBoundToURL };
{
"name": "workbox-precaching",
"version": "6.1.5",
"version": "6.2.0-alpha.0",
"license": "MIT",

@@ -24,7 +24,7 @@ "author": "Google's Web DevRel Team",

"dependencies": {
"workbox-core": "^6.1.5",
"workbox-routing": "^6.1.5",
"workbox-strategies": "^6.1.5"
"workbox-core": "^6.2.0-alpha.0",
"workbox-routing": "^6.2.0-alpha.0",
"workbox-strategies": "^6.2.0-alpha.0"
},
"gitHead": "d559fc8b3240f723fd9721f3976797dcedf7112b"
"gitHead": "46af63c1780955345c117c63c8c8dd54f3d40220"
}
import { Strategy } from 'workbox-strategies/Strategy.js';
import { RouteHandlerCallback, WorkboxPlugin } from 'workbox-core/types.js';
import { PrecacheEntry } from './_types.js';
import { PrecacheEntry, InstallResult, CleanupResult } from './_types.js';
import './_version.js';

@@ -71,3 +71,3 @@ declare global {

*/
install(event: ExtendableEvent): Promise<any>;
install(event: ExtendableEvent): Promise<InstallResult>;
/**

@@ -83,3 +83,3 @@ * Deletes assets that are no longer present in the current precache manifest.

*/
activate(event: ExtendableEvent): Promise<any>;
activate(event: ExtendableEvent): Promise<CleanupResult>;
/**

@@ -98,3 +98,3 @@ * Returns a mapping of a precached URL to the corresponding cache key, taking

*/
getCachedURLs(): string[];
getCachedURLs(): Array<string>;
/**

@@ -101,0 +101,0 @@ * Returns the cache key used for storing a given URL. If that URL is

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

install(event) {
// waitUntil returns Promise<any>
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return waitUntil(event, async () => {

@@ -187,2 +189,4 @@ const installReportPlugin = new PrecacheInstallReportPlugin();

activate(event) {
// waitUntil returns Promise<any>
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return waitUntil(event, async () => {

@@ -189,0 +193,0 @@ const cache = await self.caches.open(this.strategy.cacheName);

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

if (process.env.NODE_ENV !== 'production') {
// Params in handlers is type any, can't change right now.
// eslint-disable-next-line
const cacheKey = handler.params && handler.params.cacheKey ||

@@ -103,2 +105,4 @@ await handler.getCacheKey(request, 'read');

getFriendlyURL(request.url));
// cacheKey is type any, can't change right now.
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
logger.log(`Serving the precached url: ${getFriendlyURL(cacheKey.url)}`);

@@ -105,0 +109,0 @@ logger.groupCollapsed(`View request details here.`);

// @ts-ignore
try{self['workbox:precaching:6.1.5']&&_()}catch(e){}
try{self['workbox:precaching:6.2.0-alpha.0']&&_()}catch(e){}

@@ -21,3 +21,3 @@ /*

*/
function addPlugins(plugins: WorkboxPlugin[]) {
function addPlugins(plugins: WorkboxPlugin[]): void {
const precacheController = getOrCreatePrecacheController();

@@ -24,0 +24,0 @@ precacheController.strategy.plugins.push(...plugins);

@@ -33,3 +33,3 @@

*/
function addRoute(options?: PrecacheRouteOptions) {
function addRoute(options?: PrecacheRouteOptions): void {
const precacheController = getOrCreatePrecacheController();

@@ -36,0 +36,0 @@

@@ -21,3 +21,3 @@ /*

*/
function cleanupOutdatedCaches() {
function cleanupOutdatedCaches(): void {
// See https://github.com/Microsoft/TypeScript/issues/28357#issuecomment-436484705

@@ -24,0 +24,0 @@ self.addEventListener('activate', ((event: ExtendableEvent) => {

@@ -10,3 +10,3 @@ /*

import {getOrCreatePrecacheController} from './utils/getOrCreatePrecacheController.js';
import {RouteHandlerCallback} from 'workbox-core/types.js';
import './_version.js';

@@ -31,3 +31,3 @@

*/
function createHandlerBoundToURL(url: string) {
function createHandlerBoundToURL(url: string): RouteHandlerCallback {
const precacheController = getOrCreatePrecacheController();

@@ -34,0 +34,0 @@ return precacheController.createHandlerBoundToURL(url);

@@ -32,3 +32,3 @@ /*

*/
function getCacheKeyForURL(url: string) {
function getCacheKeyForURL(url: string): string | undefined {
const precacheController = getOrCreatePrecacheController();

@@ -35,0 +35,0 @@ return precacheController.getCacheKeyForURL(url);

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

*/
function matchPrecache(request: string|Request) {
function matchPrecache(request: string | Request): Promise<Response | undefined> {
const precacheController = getOrCreatePrecacheController();

@@ -31,0 +31,0 @@ return precacheController.matchPrecache(request);

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

*/
function precache(entries: Array<PrecacheEntry|string>) {
function precache(entries: Array<PrecacheEntry | string>): void {
const precacheController = getOrCreatePrecacheController();

@@ -36,0 +36,0 @@ precacheController.precache(entries);

@@ -29,3 +29,3 @@ /*

*/
function precacheAndRoute(entries: Array<PrecacheEntry|string>, options?: PrecacheRouteOptions) {
function precacheAndRoute(entries: Array<PrecacheEntry | string>, options?: PrecacheRouteOptions): void {
precache(entries);

@@ -32,0 +32,0 @@ addRoute(options);

@@ -23,3 +23,3 @@ /*

import {PrecacheStrategy} from './PrecacheStrategy.js';
import {PrecacheEntry} from './_types.js';
import {PrecacheEntry, InstallResult, CleanupResult} from './_types.js';
import './_version.js';

@@ -84,3 +84,3 @@

*/
get strategy() {
get strategy(): Strategy {
return this._strategy;

@@ -99,3 +99,3 @@ }

*/
precache(entries: Array<PrecacheEntry | string>) {
precache(entries: Array<PrecacheEntry | string>): void {
this.addToCacheList(entries);

@@ -117,3 +117,3 @@

*/
addToCacheList(entries: Array<PrecacheEntry|string>) {
addToCacheList(entries: Array<PrecacheEntry | string>): void {
if (process.env.NODE_ENV !== 'production') {

@@ -187,3 +187,5 @@ assert!.isArray(entries, {

*/
install(event: ExtendableEvent) {
install(event: ExtendableEvent): Promise<InstallResult> {
// waitUntil returns Promise<any>
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return waitUntil(event, async () => {

@@ -232,3 +234,5 @@ const installReportPlugin = new PrecacheInstallReportPlugin();

*/
activate(event: ExtendableEvent) {
activate(event: ExtendableEvent): Promise<CleanupResult> {
// waitUntil returns Promise<any>
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return waitUntil(event, async () => {

@@ -261,3 +265,3 @@ const cache = await self.caches.open(this.strategy.cacheName);

*/
getURLsToCacheKeys() {
getURLsToCacheKeys(): Map<string, string> {
return this._urlsToCacheKeys;

@@ -272,3 +276,3 @@ }

*/
getCachedURLs() {
getCachedURLs(): Array<string> {
return [...this._urlsToCacheKeys.keys()];

@@ -286,3 +290,3 @@ }

*/
getCacheKeyForURL(url: string) {
getCacheKeyForURL(url: string): string | undefined {
const urlObject = new URL(url, location.href);

@@ -289,0 +293,0 @@ return this._urlsToCacheKeys.get(urlObject.href);

@@ -44,3 +44,3 @@ /*

}
return response;

@@ -93,3 +93,3 @@ }

*/
async _handle(request: Request, handler: StrategyHandler) {
async _handle(request: Request, handler: StrategyHandler): Promise<Response> {
const response = await handler.cacheMatch(request);

@@ -109,3 +109,3 @@ if (!response) {

async _handleFetch(request: Request, handler: StrategyHandler) {
async _handleFetch(request: Request, handler: StrategyHandler): Promise<Response> {
let response;

@@ -132,2 +132,4 @@

if (process.env.NODE_ENV !== 'production') {
// Params in handlers is type any, can't change right now.
// eslint-disable-next-line
const cacheKey = handler.params && handler.params.cacheKey ||

@@ -140,2 +142,4 @@ await handler.getCacheKey(request, 'read');

getFriendlyURL(request.url));
// cacheKey is type any, can't change right now.
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
logger.log(`Serving the precached url: ${getFriendlyURL(cacheKey.url)}`);

@@ -156,3 +160,3 @@

async _handleInstall(request: Request, handler: StrategyHandler) {
async _handleInstall(request: Request, handler: StrategyHandler): Promise<Response> {
this._useDefaultCacheabilityPluginIfNeeded();

@@ -179,17 +183,17 @@

* This method is complex, as there a number of things to account for:
*
*
* The `plugins` array can be set at construction, and/or it might be added to
* to at any time before the strategy is used.
*
*
* At the time the strategy is used (i.e. during an `install` event), there
* needs to be at least one plugin that implements `cacheWillUpdate` in the
* array, other than `copyRedirectedCacheableResponsesPlugin`.
*
*
* - If this method is called and there are no suitable `cacheWillUpdate`
* plugins, we need to add `defaultPrecacheCacheabilityPlugin`.
*
*
* - If this method is called and there is exactly one `cacheWillUpdate`, then
* we don't have to do anything (this might be a previously added
* `defaultPrecacheCacheabilityPlugin`, or it might be a custom plugin).
*
* `defaultPrecacheCacheabilityPlugin`, or it might be a custom plugin).
*
* - If this method is called and there is more than one `cacheWillUpdate`,

@@ -200,3 +204,3 @@ * then we need to check if one is `defaultPrecacheCacheabilityPlugin`. If so,

* and then later on after manually adding a custom `cacheWillUpdate`.)
*
*
* See https://github.com/GoogleChrome/workbox/issues/2737 for more context.

@@ -203,0 +207,0 @@ *

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

currentPrecacheName: string,
substringToFind: string = SUBSTRING_TO_FIND) => {
substringToFind: string = SUBSTRING_TO_FIND): Promise<string[]> => {
const cacheNames = await self.caches.keys();

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

@@ -29,3 +29,3 @@ /*

urlManipulation,
}: PrecacheRouteOptions = {}) {
}: PrecacheRouteOptions = {}): Generator<string, void, unknown> {
const urlObject = new URL(url, location.href);

@@ -32,0 +32,0 @@ urlObject.hash = '';

@@ -19,3 +19,3 @@ /*

*/
export const getOrCreatePrecacheController = () => {
export const getOrCreatePrecacheController = (): PrecacheController => {
if (!precacheController) {

@@ -22,0 +22,0 @@ precacheController = new PrecacheController();

@@ -18,3 +18,3 @@ /*

* the corresponding cache key, based on the current revision info.
*
*
* @private

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

}: WorkboxPluginCallbackParam['cacheKeyWillBeUsed']) => {
// Params is type any, can't change right now.
// eslint-disable-next-line
const cacheKey = params && params.cacheKey ||

@@ -35,0 +37,0 @@ this._precacheController.getCacheKeyForURL(request.url);

@@ -17,3 +17,3 @@ /*

* of assets that were updated (or not updated) during the install event.
*
*
* @private

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

if (event.type === 'install') {
if (state && state.originalRequest
&& state.originalRequest instanceof Request) {
// TODO: `state` should never be undefined...
const url = state!.originalRequest.url;
const url = state.originalRequest.url;
if (cachedResponse) {
this.notUpdatedURLs.push(url);
} else {
this.updatedURLs.push(url);
if (cachedResponse) {
this.notUpdatedURLs.push(url);
} else {
this.updatedURLs.push(url);
}
}

@@ -50,0 +53,0 @@ }

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

*/
export function printCleanupDetails(deletedURLs: string[]) {
export function printCleanupDetails(deletedURLs: string[]): void {
const deletionCount = deletedURLs.length;

@@ -38,0 +38,0 @@ if (deletionCount > 0) {

@@ -19,3 +19,3 @@ /*

*/
function _nestedGroup(groupTitle: string, urls: string[]) {
function _nestedGroup(groupTitle: string, urls: string[]): void {
if (urls.length === 0) {

@@ -41,3 +41,3 @@ return;

*/
export function printInstallDetails(urlsToPrecache: string[], urlsAlreadyPrecached: string[]) {
export function printInstallDetails(urlsToPrecache: string[], urlsAlreadyPrecached: string[]): void {
const precachedCount = urlsToPrecache.length;

@@ -44,0 +44,0 @@ const alreadyPrecachedCount = urlsAlreadyPrecached.length;

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

this.cacheKeyWillBeUsed = async ({ request, params, }) => {
// Params is type any, can't change right now.
// eslint-disable-next-line
const cacheKey = params && params.cacheKey ||

@@ -20,0 +22,0 @@ this._precacheController.getCacheKeyForURL(request.url);

@@ -27,10 +27,13 @@ /*

if (event.type === 'install') {
// TODO: `state` should never be undefined...
const url = state.originalRequest.url;
if (cachedResponse) {
this.notUpdatedURLs.push(url);
if (state && state.originalRequest
&& state.originalRequest instanceof Request) {
// TODO: `state` should never be undefined...
const url = state.originalRequest.url;
if (cachedResponse) {
this.notUpdatedURLs.push(url);
}
else {
this.updatedURLs.push(url);
}
}
else {
this.updatedURLs.push(url);
}
}

@@ -37,0 +40,0 @@ return cachedResponse;

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