diff --git a/package-lock.json b/package-lock.json index 737903d..6fd768e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,17 +19,17 @@ } }, "node_modules/@base-framework/atoms": { - "version": "1.0.36", - "resolved": "https://registry.npmjs.org/@base-framework/atoms/-/atoms-1.0.36.tgz", - "integrity": "sha512-7mp6WyNnQJ+SpmzvgQiad5Xysb4sur0GDTOtBqvX4l9v52ntPqPUWijmcj+BRJQGkuUwxfrqrb5bZXteFTxhBQ==", + "version": "1.0.40", + "resolved": "https://registry.npmjs.org/@base-framework/atoms/-/atoms-1.0.40.tgz", + "integrity": "sha512-Li6Vh/Q6vPcxb+E/+SqiXzeU0lwbbyQtT+QuNQZGEUOjHWzWnYQWvpS0eoidA7vZkgFrvS6QrwE5UEsiELGtjg==", "dependencies": { "@base-framework/base": "^3.0.184" } }, "node_modules/@base-framework/base": { - "version": "3.0.197", - "resolved": "https://registry.npmjs.org/@base-framework/base/-/base-3.0.197.tgz", - "integrity": "sha512-1xPsXeQkmNQCi22RNvt1177nprsHYz4nG8Hqqv+2IC4XsOP06VClsWQ0c6zY42wFx9w6OKCiaca0U1CIQN6gGA==" + "version": "3.0.243", + "resolved": "https://registry.npmjs.org/@base-framework/base/-/base-3.0.243.tgz", + "integrity": "sha512-w/oszgZeoGB8WJpZUAsVijOG2a812Hzt+be4cunPvLVNa/BRGXiFMeNKEB++BWp6dkilcZhXjuFEtVSSQoKd4g==" }, "node_modules/@esbuild/android-arm": { "version": "0.15.18", @@ -430,9 +430,9 @@ } }, "node_modules/is-core-module": { - "version": "2.15.1", - "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.15.1.tgz", - "integrity": "sha512-z0vtXSwucUJtANQWldhbtbt7BnL0vxiFjIdDLAatwhDYty2bad6s+rijD6Ri4YuYJubLzIJLUidCh09e1djEVQ==", + "version": "2.16.1", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.16.1.tgz", + "integrity": "sha512-UfoeMA6fIJ8wTYFEUjelnaGI67v6+N7qXJEvQuIGa99l4xsCruSYOVSQ0uPANn4dAzm8lkYPaKLrrijLq7x23w==", "dependencies": { "hasown": "^2.0.2" }, @@ -471,9 +471,9 @@ "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==" }, "node_modules/postcss": { - "version": "8.4.49", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.49.tgz", - "integrity": "sha512-OCVPnIObs4N29kxTjzLfUryOkvZEq+pf8jTF0lg8E7uETuWHA+v7j3c/xJmiqpX450191LlmZfUKkXxkTry7nA==", + "version": "8.5.1", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.1.tgz", + "integrity": "sha512-6oz2beyjc5VMn/KV1pPw8fliQkhBXrVn1Z3TVyqZxU8kZpzEKhBdmCFqI6ZbmGtamQvQGuU1sgPTk8ZrXDD7jQ==", "funding": [ { "type": "opencollective", @@ -489,7 +489,7 @@ } ], "dependencies": { - "nanoid": "^3.3.7", + "nanoid": "^3.3.8", "picocolors": "^1.1.1", "source-map-js": "^1.2.1" }, @@ -498,17 +498,20 @@ } }, "node_modules/resolve": { - "version": "1.22.8", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.8.tgz", - "integrity": "sha512-oKWePCxqpd6FlLvGV1VU0x7bkPmmCNolxzjMf4NczoDnQcIWrAF+cPtZn5i6n+RfD2d9i0tzpKnG6Yk168yIyw==", + "version": "1.22.10", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.10.tgz", + "integrity": "sha512-NPRy+/ncIMeDlTAsuqwKIiferiawhefFJtkNSW0qZJEqMEb+qBt/77B/jGeeek+F0uOeN05CDa6HXbbIgtVX4w==", "dependencies": { - "is-core-module": "^2.13.0", + "is-core-module": "^2.16.0", "path-parse": "^1.0.7", "supports-preserve-symlinks-flag": "^1.0.0" }, "bin": { "resolve": "bin/resolve" }, + "engines": { + "node": ">= 0.4" + }, "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -547,9 +550,9 @@ } }, "node_modules/typescript": { - "version": "5.7.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.7.2.tgz", - "integrity": "sha512-i5t66RHxDvVN40HfDd1PsEThGNnlMCMT3jMUuoh9/0TaqWevNontacunWyN02LA9/fIbEWlcHZcgTKb9QoaLfg==", + "version": "5.7.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.7.3.tgz", + "integrity": "sha512-84MVSjMEHP+FQRPy3pX9sTVV/INIex71s9TL2Gm5FG/WG1SqXeKyZ0k7/blY/4FdOzI12CBy1vGc4og/eus0fw==", "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" diff --git a/package.json b/package.json index 5207ca5..6840f0c 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "vite": "^3.1.0" }, "files": [ - "pacakge.json", + "package.json", "readme.md" ], "homepage": "https://github.com/chrisdurfee/multisplode/" diff --git a/public/sw.js b/public/sw.js index b333015..9aaa633 100644 --- a/public/sw.js +++ b/public/sw.js @@ -1,13 +1,38 @@ importScripts('./worker/cache-controller.js', './worker/service.js'); -const appName = 'multisplode', -version = '0.0.17'; +/** + * This is the name of the app and the version. This is used to + * create the cache name. + * + * @const + * @type {string} appName + */ +const APP_NAME = 'multisplode', -const files = +/** + * This is the version of the app. This is used to create the cache + * + * @const + * @type {string} version + */ +version = '0.0.18'; + +/** + * This will add these files to cache. Add any files you want to + * cache here. As files are fetched, they will be added to the cache. + * + * @const + * @type {Array} DEFAULT_FILES + */ +const DEFAULT_FILES = [ './', './index.html' ]; -const appNameId = appName + '-v' + version; -const service = new Service(appNameId, files); +/** + * This will set up the service worker controller with + * the app name and the files to cache. + */ +const appNameId = `${APP_NAME}-${version}`; +const service = new Service(appNameId, DEFAULT_FILES); diff --git a/public/worker/cache-controller.js b/public/worker/cache-controller.js index 540a4f1..13c6131 100644 --- a/public/worker/cache-controller.js +++ b/public/worker/cache-controller.js @@ -89,7 +89,12 @@ class CacheController }); } - + /** + * This will add files to the cache. + * + * @param {array} files + * @returns {Promise} + */ addFiles(files) { return this.open(this.cacheName, (cache) => @@ -98,6 +103,11 @@ class CacheController }); } + /** + * This will delete files from the cache. + * + * @returns {void} + */ deleteFiles() { caches.delete(this.cacheName).then((success) => @@ -106,6 +116,12 @@ class CacheController }); } + /** + * This will get files from the cache. + * + * @param {object} e + * @returns {Promise} + */ fetchFile(e) { const request = e.request; diff --git a/public/worker/service.js b/public/worker/service.js index ba76ec1..764d4e2 100644 --- a/public/worker/service.js +++ b/public/worker/service.js @@ -5,17 +5,24 @@ * * @class Service */ -class Service extends CacheController +class Service { /** - * This will create a service that will cache files. - * - * @param {string} prefix - * @param {Array} files - */ + * This will create a new service. + * + * @param {string} prefix + * @param {Array} files + */ constructor(prefix, files = []) { - super(prefix); + /** + * @member {CacheController} cache + */ + this.cache = new CacheController(prefix); + + /** + * @member {Array} files + */ this.files = files; this.addEvents(); @@ -33,14 +40,14 @@ class Service extends CacheController self.skipWaiting(); e.waitUntil( - this.addFiles(this.files) + this.cache.addFiles(this.files) ); }); self.addEventListener('activate', (e) => { e.waitUntil( - this.refresh() + this.cache.refresh() ); return self.clients.claim(); @@ -50,7 +57,7 @@ class Service extends CacheController { if(e.data === 'delete') { - this.deleteFiles(); + this.cache.deleteFiles(); } }); @@ -76,7 +83,7 @@ class Service extends CacheController return false; } - const response = this.fetchFile(e); + const response = this.cache.fetchFile(e); e.respondWith(response); }); }