saloe 0.0.29 → 0.0.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cookie.cjs.js +1 -1
- package/dist/cookie.es.js +1 -1
- package/dist/urlpattern.cjs.js +1 -1
- package/dist/urlpattern.es.js +1 -1
- package/package.json +5 -1
- package/src/cookie.js +2 -2
- package/src/offline.js +69 -0
- package/src/urlpattern.js +1 -1
package/dist/cookie.cjs.js
CHANGED
|
@@ -263,7 +263,7 @@ if (!("cookies" in ServiceWorkerRegistration.prototype)) {
|
|
|
263
263
|
});
|
|
264
264
|
}
|
|
265
265
|
const cookieStore = Object.create(CookieStore.prototype);
|
|
266
|
-
self.cookieStore
|
|
266
|
+
if (!self.cookieStore) self.cookieStore = cookieStore;
|
|
267
267
|
const setCookie = ({ key, value, config }) => {
|
|
268
268
|
var _a;
|
|
269
269
|
return (_a = self.cookieStore) == null ? void 0 : _a.set(key, value, config);
|
package/dist/cookie.es.js
CHANGED
|
@@ -261,7 +261,7 @@ if (!("cookies" in ServiceWorkerRegistration.prototype)) {
|
|
|
261
261
|
});
|
|
262
262
|
}
|
|
263
263
|
const cookieStore = Object.create(CookieStore.prototype);
|
|
264
|
-
self.cookieStore
|
|
264
|
+
if (!self.cookieStore) self.cookieStore = cookieStore;
|
|
265
265
|
const setCookie = ({ key, value, config }) => {
|
|
266
266
|
var _a;
|
|
267
267
|
return (_a = self.cookieStore) == null ? void 0 : _a.set(key, value, config);
|
package/dist/urlpattern.cjs.js
CHANGED
|
@@ -18,6 +18,6 @@ function _interopNamespaceDefault(e) {
|
|
|
18
18
|
return Object.freeze(n);
|
|
19
19
|
}
|
|
20
20
|
const URLPatternPolyfill__namespace = /* @__PURE__ */ _interopNamespaceDefault(URLPatternPolyfill);
|
|
21
|
-
self.URLPattern
|
|
21
|
+
if (!self.URLPattern) self.URLPattern = URLPatternPolyfill__namespace.URLPattern;
|
|
22
22
|
const getURLPatern = ({ pathname }) => new self.URLPattern({ pathname });
|
|
23
23
|
exports.getURLPatern = getURLPatern;
|
package/dist/urlpattern.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as URLPatternPolyfill from "urlpattern-polyfill";
|
|
2
|
-
self.URLPattern
|
|
2
|
+
if (!self.URLPattern) self.URLPattern = URLPatternPolyfill.URLPattern;
|
|
3
3
|
const getURLPatern = ({ pathname }) => new self.URLPattern({ pathname });
|
|
4
4
|
export {
|
|
5
5
|
getURLPatern
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "saloe",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.31",
|
|
4
4
|
"description": "Tools for making web development easy and efficient",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -38,6 +38,10 @@
|
|
|
38
38
|
"import": "./dist/listener.es.js",
|
|
39
39
|
"require": "./dist/listener.cjs.js"
|
|
40
40
|
},
|
|
41
|
+
"./offline": {
|
|
42
|
+
"import": "./dist/offline.es.js",
|
|
43
|
+
"require": "./dist/offline.cjs.js"
|
|
44
|
+
},
|
|
41
45
|
"./router": {
|
|
42
46
|
"import": "./dist/router.es.js",
|
|
43
47
|
"require": "./dist/router.cjs.js"
|
package/src/cookie.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as CookieStorePolyfill from 'cookie-store'
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
self.cookieStore
|
|
4
|
+
if (!self.cookieStore) self.cookieStore = CookieStorePolyfill.cookieStore
|
|
5
5
|
|
|
6
6
|
const setCookie = ({ key, value, config }) => {
|
|
7
7
|
return self.cookieStore?.set(key, value, config)
|
package/src/offline.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { fetch as fetchAsWorker } from './worker'
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
// TODO: Function is too specific
|
|
5
|
+
const cacheAssets = async ({ cachePrefix, cacheName }) => {
|
|
6
|
+
try {
|
|
7
|
+
const assetsResult = await fetchAsWorker({ url: '/dist.json' })
|
|
8
|
+
const assetsJSON = assetsResult?.err ? {} : await assetsResult?.response?.json()
|
|
9
|
+
|
|
10
|
+
const cache = await caches.open(`${cachePrefix}-${cacheName}`)
|
|
11
|
+
|
|
12
|
+
return assetsJSON?.map(async (path) => {
|
|
13
|
+
const url = path?.replace('dist/', '/')
|
|
14
|
+
try {
|
|
15
|
+
await cache.add(url)
|
|
16
|
+
} catch (err) {
|
|
17
|
+
console.log(`${err} - ${url}`)
|
|
18
|
+
}
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
} catch (err) {
|
|
22
|
+
console.error(err)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const installStaticAssets = async ({ cachePrefix, cacheName }) => {
|
|
27
|
+
cacheAssets({ cachePrefix, cacheName })
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const removePreviousCaches = async ({ version, cachePrefix }) => {
|
|
31
|
+
const cacheNames = await caches.keys()
|
|
32
|
+
return Promise.all(
|
|
33
|
+
cacheNames?.filter((cacheName) => {
|
|
34
|
+
const startsWithPrefix = cacheName?.startsWith(cachePrefix)
|
|
35
|
+
const endsWithVersion = cacheName?.endsWith(version)
|
|
36
|
+
const cacheToDelete = startsWithPrefix && !endsWithVersion
|
|
37
|
+
return cacheToDelete
|
|
38
|
+
})?.map((cacheName) => caches?.delete(cacheName))
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const serveFromCache = async ({ request, cachePrefix, cacheName }) => {
|
|
43
|
+
try {
|
|
44
|
+
const cache = await caches.open(`${cachePrefix}-${cacheName}`)
|
|
45
|
+
const response = await cache.match(request, { ignoreSearch: true })
|
|
46
|
+
return { response }
|
|
47
|
+
} catch (err) {
|
|
48
|
+
console.error(err)
|
|
49
|
+
return { err }
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const cacheFirstThenNetwork = async ({ request, cachePrefix, cacheName }) => {
|
|
54
|
+
const cacheResult = await serveFromCache({ request, cachePrefix, cacheName })
|
|
55
|
+
if (cacheResult?.response) return cacheResult
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
const fetchResult = await fetchAsWorker({ request })
|
|
59
|
+
return fetchResult
|
|
60
|
+
} catch (err) {
|
|
61
|
+
return { err }
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export {
|
|
66
|
+
installStaticAssets,
|
|
67
|
+
removePreviousCaches,
|
|
68
|
+
cacheFirstThenNetwork,
|
|
69
|
+
}
|
package/src/urlpattern.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as URLPatternPolyfill from 'urlpattern-polyfill'
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
self.URLPattern
|
|
4
|
+
if (!self.URLPattern ) self.URLPattern = URLPatternPolyfill.URLPattern
|
|
5
5
|
|
|
6
6
|
const getURLPatern = ({ pathname }) => new self.URLPattern({ pathname })
|
|
7
7
|
|