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

workbox-precaching

Package Overview
Dependencies
Maintainers
3
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 1.0.0 to 1.1.0

build/importScripts/workbox-precaching.dev.v1.1.0.js

10

package.json
{
"name": "workbox-precaching",
"version": "1.0.0",
"version": "1.1.0",
"description": "A lower-level server worker library to precache a manifest of URLs.",

@@ -27,7 +27,7 @@ "keywords": [

"devDependencies": {
"workbox-routing": "^1.0.0",
"workbox-runtime-caching": "^1.0.0"
"workbox-routing": "^1.1.0",
"workbox-runtime-caching": "^1.1.0"
},
"main": "build/importScripts/workbox-precaching.prod.v1.0.0.js",
"module": "build/modules/workbox-precaching.prod.v1.0.0.mjs"
"main": "build/importScripts/workbox-precaching.prod.v1.1.0.js",
"module": "build/modules/workbox-precaching.prod.v1.1.0.mjs"
}

@@ -59,11 +59,11 @@ /*

*/
import ErrorFactory from './lib/error-factory';
import RevisionedCacheManager from
'./lib/controllers/revisioned-cache-manager.js';
import environment from '../../../lib/environment.js';
import WorkboxError from '../../../lib/workbox-error';
import {isServiceWorkerGlobalScope} from '../../../lib/environment.js';
if (!environment.isServiceWorkerGlobalScope()) {
if (!isServiceWorkerGlobalScope()) {
// We are not running in a service worker, print error message
throw ErrorFactory.createError('not-in-sw');
throw new WorkboxError('not-in-sw');
}

@@ -70,0 +70,0 @@

@@ -1,3 +0,4 @@

import ErrorFactory from '../error-factory';
import {RequestWrapper} from '../../../../workbox-runtime-caching/src/index';
import WorkboxError from '../../../../../lib/workbox-error';
/**

@@ -23,3 +24,3 @@ * This class handles the shared logic for caching revisioned and unrevisioned

if (cacheId && (typeof cacheId !== 'string' || cacheId.length === 0)) {
throw ErrorFactory.createError('bad-cache-id');
throw new WorkboxError('bad-cache-id', {cacheId});
}

@@ -158,5 +159,5 @@

} catch (err) {
throw ErrorFactory.createError('request-not-cached', {
message: `Failed to get a cacheable response for ` +
`'${precacheEntry.request.url}': ${err.message}`,
throw new WorkboxError('request-not-cached', {
url: precacheEntry.request.url,
error: err,
});

@@ -189,12 +190,9 @@ }

const cachedRequestsToDelete = allCachedRequests.filter((cachedRequest) => {
if (requestsCachedOnInstall.includes(cachedRequest.url)) {
return false;
}
return true;
});
const cachedRequestsToDelete = allCachedRequests.filter(
(cachedRequest) => !requestsCachedOnInstall.includes(cachedRequest.url));
return Promise.all(
cachedRequestsToDelete.map((cachedRequest) => {
return openCache.delete(cachedRequest);
cachedRequestsToDelete.map(async (cachedRequest) => {
await openCache.delete(cachedRequest);
await this._onEntryDeleted(cachedRequest.url);
})

@@ -229,3 +227,3 @@ );

_parseEntry(input) {
throw ErrorFactory.createError('should-override');
throw new WorkboxError('requires-overriding');
}

@@ -246,3 +244,3 @@

_onDuplicateEntryFound(newEntry, previous) {
throw ErrorFactory.createError('should-override');
throw new WorkboxError('requires-overriding');
}

@@ -262,3 +260,3 @@

_isAlreadyCached(precacheEntry) {
throw ErrorFactory.createError('should-override');
throw new WorkboxError('requires-overriding');
}

@@ -278,6 +276,19 @@

_onEntryCached(precacheEntry) {
throw ErrorFactory.createError('should-override');
throw new WorkboxError('requires-overriding');
}
/**
* Subclasses can use this method for any work that needs to be done once a
* URL has been deleted from the cache.
*
* @private
* @abstract
* @param {String} url The URL of the entry that was deleted.
* @return {Promise} Returns a Promise that resolves once the work is done.
*/
_onEntryDeleted(url) {
throw new WorkboxError('requires-overriding');
}
}
export default BaseCacheManager;

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

import ErrorFactory from '../error-factory';
import BaseCacheManager from './base-cache-manager';
import RevisionDetailsModel from '../models/revision-details-model';
import {defaultRevisionedCacheName} from '../constants';
import StringPrecacheEntry from
'../models/precache-entries/string-precache-entry';
import StringCacheEntry from
'../models/precache-entries/string-cache-entry';
import ObjectPrecacheEntry from
'../models/precache-entries/object-precache-entry';
import assert from '../../../../../lib/assert';
import {isInstance} from '../../../../../lib/assert';
import logHelper from '../../../../../lib/log-helper';
import WorkboxError from '../../../../../lib/workbox-error';

@@ -76,3 +76,3 @@ /**

addToCacheList({revisionedFiles} = {}) {
assert.isInstance({revisionedFiles}, Array);
isInstance({revisionedFiles}, Array);
super._addEntries(revisionedFiles);

@@ -111,12 +111,10 @@

_parseEntry(input) {
if (typeof input === 'undefined' || input === null) {
throw ErrorFactory.createError('invalid-revisioned-entry',
new Error('Invalid file entry: ' + JSON.stringify(input))
);
if (input === null) {
throw new WorkboxError('unexpected-precache-entry', {input});
}
let precacheEntry;
switch(typeof input) {
switch (typeof input) {
case 'string':
precacheEntry = new StringPrecacheEntry(input);
precacheEntry = new StringCacheEntry(input);
break;

@@ -127,6 +125,3 @@ case 'object':

default:
throw ErrorFactory.createError('invalid-revisioned-entry',
new Error('Invalid file entry: ' +
JSON.stringify(precacheEntry))
);
throw new WorkboxError('unexpected-precache-entry', {input});
}

@@ -149,6 +144,12 @@

if (previousEntry.revision !== newEntry.revision) {
throw ErrorFactory.createError(
'duplicate-entry-diff-revisions',
new Error(`${JSON.stringify(previousEntry)} <=> ` +
`${JSON.stringify(newEntry)}`));
throw new WorkboxError('duplicate-entry-diff-revisions', {
firstEntry: {
url: previousEntry.request.url,
revision: previousEntry.revision,
},
secondEntry: {
url: newEntry.request.url,
revision: newEntry.revision,
},
});
}

@@ -193,2 +194,13 @@ }

/**
* Removes a URL from IndexedDB when the corresponding entry has been removed
* from the Cache Storage API.
*
* @private
* @param {String} url The URL that has been deleted from the cache.
*/
async _onEntryDeleted(url) {
await this._revisionDetailsModel.delete(url);
}
/**
* This method closes the indexdDB helper. This is used for unit testing

@@ -195,0 +207,0 @@ * to ensure cleanup between tests.

@@ -5,4 +5,4 @@ import ErrorFactory from '../error-factory';

import StringPrecacheEntry from
'../models/precache-entries/string-precache-entry';
import assert from '../../../../../lib/assert';
'../models/precache-entries/string-cache-entry';
import {isInstance} from '../../../../../lib/assert';

@@ -52,3 +52,3 @@ /**

addToCacheList({unrevisionedFiles} = {}) {
assert.isInstance({unrevisionedFiles}, Array);
isInstance({unrevisionedFiles}, Array);
super._addEntries(unrevisionedFiles);

@@ -114,4 +114,14 @@ }

}
/**
* @private
* @param {String} url The URL of the entry that was deleted.
* @return {Promise} Returns a Promise that resolves once the work is done.
*/
_onEntryDeleted(url) {
// Effectively a no-op.
return Promise.resolve();
}
}
export default UnrevisionedCacheManager;

@@ -1,4 +0,4 @@

import ErrorFactory from '../../error-factory';
import WorkboxError from '../../../../../../lib/workbox-error';
import BaseCacheEntry from './base-precache-entry';
import assert from '../../../../../../lib/assert';
import {isType} from '../../../../../../lib/assert';

@@ -13,3 +13,3 @@ /**

*/
class DefaultsCacheEntry extends BaseCacheEntry {
class ObjectCacheEntry extends BaseCacheEntry {
/**

@@ -34,24 +34,21 @@ * This class gives most control over configuring a cache entry.

assert.isType({revision}, 'string');
isType({revision}, 'string');
if (revision.length === 0) {
throw ErrorFactory.createError('invalid-revisioned-entry',
new Error('Bad revision Parameter. It should be a string with at ' +
'least one character: ' + JSON.stringify(revision)));
throw new WorkboxError('invalid-object-entry',
{problemParam: 'revision', problemValue: revision});
}
assert.isType({url}, 'string');
isType({url}, 'string');
if (url.length === 0) {
throw ErrorFactory.createError('invalid-revisioned-entry',
new Error('Bad url Parameter. It should be a string:' +
JSON.stringify(url)));
throw new WorkboxError('invalid-object-entry',
{problemParam: 'url', problemValue: url});
}
assert.isType({entryID}, 'string');
isType({entryID}, 'string');
if (entryID.length === 0) {
throw ErrorFactory.createError('invalid-revisioned-entry',
new Error('Bad entryID Parameter. It should be a string with at ' +
'least one character: ' + JSON.stringify(entryID)));
throw new WorkboxError('invalid-object-entry',
{problemParam: 'entryID', problemValue: entryID});
}
assert.isType({cacheBust}, 'boolean');
isType({cacheBust}, 'boolean');

@@ -67,2 +64,2 @@ super({

export default DefaultsCacheEntry;
export default ObjectCacheEntry;

@@ -41,2 +41,11 @@ import IDBHelper from '../../../../../lib/idb-helper.js';

/**
* This method deletes the revision details from indexedDB for a given entry.
* @param {String} entryID The ID of the revision.
* @return {Promise} Promise that resolves once the data has been deleted.
*/
delete(entryID) {
return this._idbHelper.delete(entryID);
}
/**
* This method closes the indexdDB helper. This is only used for unit testing

@@ -43,0 +52,0 @@ * to ensure clean state between tests.

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