@fullstackunicorn/webapp 2.1.2 → 2.1.3
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/files.json +1 -1
- package/imports/cache.js +71 -11
- package/package.json +1 -1
- package/package.md +12 -0
package/files.json
CHANGED
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
{
|
|
72
72
|
"path": "imports/cache.js",
|
|
73
73
|
"class": "byte-sacred",
|
|
74
|
-
"sha256": "
|
|
74
|
+
"sha256": "53afdb2dddc6a623d1c9543f702b80f7c06b1a52ebb73c373f906f0351308bfa",
|
|
75
75
|
"referenceSha256": "0c89a1146701f65ea10cdf590630d7c6d43f402d13eb253a7065086cf7130071"
|
|
76
76
|
},
|
|
77
77
|
{
|
package/imports/cache.js
CHANGED
|
@@ -12,9 +12,20 @@ class Cache {
|
|
|
12
12
|
generation = 0
|
|
13
13
|
commits = new Map()
|
|
14
14
|
sources = new Map()
|
|
15
|
+
fallback = new Map()
|
|
16
|
+
metadata = new Map()
|
|
17
|
+
unreadable = new Set()
|
|
18
|
+
|
|
19
|
+
persist = async (operation, work, fallback) => {
|
|
20
|
+
try { return await work() }
|
|
21
|
+
catch (error) {
|
|
22
|
+
console.warn('cache-persistence-failed', { operation, error })
|
|
23
|
+
return fallback()
|
|
24
|
+
}
|
|
25
|
+
}
|
|
15
26
|
|
|
16
27
|
initialize = () => {
|
|
17
|
-
if (!this.initialization) this.initialization = entries().then(values => {
|
|
28
|
+
if (!this.initialization) this.initialization = this.persist('indexeddb.entries', () => entries(), () => []).then(values => {
|
|
18
29
|
for (const [key, value] of values) if (typeof key === 'string' && key.startsWith('version:') && value) this.versions.set(key.slice(8), value)
|
|
19
30
|
for (const [key, value] of values) if (typeof key === 'string' && key.startsWith('source:') && value) this.sources.set(key.slice(7), value)
|
|
20
31
|
this.initialized = true
|
|
@@ -32,8 +43,8 @@ class Cache {
|
|
|
32
43
|
await this.initialize()
|
|
33
44
|
if (this.source(origin) === revision && this.release(origin) === cursor) return false
|
|
34
45
|
const state = { revision, cursor }
|
|
35
|
-
await set('source:' + origin, state)
|
|
36
46
|
this.sources.set(origin, state)
|
|
47
|
+
await this.writeMeta('source:' + origin, state)
|
|
37
48
|
return true
|
|
38
49
|
}
|
|
39
50
|
|
|
@@ -78,7 +89,47 @@ class Cache {
|
|
|
78
89
|
return lastDay < this.todayUTC()
|
|
79
90
|
}
|
|
80
91
|
|
|
81
|
-
open = async (name) =>
|
|
92
|
+
open = async (name) => {
|
|
93
|
+
const store = await this.persist('cache.open', () => caches.open(name), () => null)
|
|
94
|
+
const key = request => typeof request === 'string' ? request : request.url
|
|
95
|
+
const retain = (request, response) => {
|
|
96
|
+
if (!this.fallback.has(name)) this.fallback.set(name, new Map())
|
|
97
|
+
this.fallback.get(name).set(key(request), response)
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
match: async request => {
|
|
101
|
+
const retained = this.fallback.get(name)
|
|
102
|
+
if (retained?.has(key(request))) return retained.get(key(request))?.clone()
|
|
103
|
+
return store ? await this.persist('cache.match', async () => {
|
|
104
|
+
const response = await store.match(request)
|
|
105
|
+
this.unreadable.delete(name)
|
|
106
|
+
return response
|
|
107
|
+
}, () => { this.unreadable.add(name); return undefined }) : undefined
|
|
108
|
+
},
|
|
109
|
+
put: async (request, response) => {
|
|
110
|
+
const copy = response.clone()
|
|
111
|
+
const written = store && await this.persist('cache.put', async () => { await store.put(request, response); return true }, () => false)
|
|
112
|
+
if (written && !this.unreadable.has(name)) this.fallback.get(name)?.delete(key(request))
|
|
113
|
+
else retain(request, copy)
|
|
114
|
+
},
|
|
115
|
+
delete: async request => {
|
|
116
|
+
const retained = this.fallback.get(name)?.get(key(request))
|
|
117
|
+
const result = store && await this.persist('cache.delete', async () => ({ removed: await store.delete(request) }), () => null)
|
|
118
|
+
if (result) this.fallback.get(name)?.delete(key(request))
|
|
119
|
+
else retain(request, null)
|
|
120
|
+
return !!retained || !!result?.removed
|
|
121
|
+
},
|
|
122
|
+
keys: async () => {
|
|
123
|
+
const stored = store ? await this.persist('cache.keys', () => store.keys(), () => []) : []
|
|
124
|
+
const result = new Map(stored.map(request => [request.url, request]))
|
|
125
|
+
for (const [key, response] of this.fallback.get(name) || []) {
|
|
126
|
+
if (response) result.set(key, new Request(key))
|
|
127
|
+
else result.delete(key)
|
|
128
|
+
}
|
|
129
|
+
return [...result.values()]
|
|
130
|
+
},
|
|
131
|
+
}
|
|
132
|
+
}
|
|
82
133
|
|
|
83
134
|
get = async (cache, key, isBlob) => {
|
|
84
135
|
const match = await cache.match(key)
|
|
@@ -109,27 +160,36 @@ class Cache {
|
|
|
109
160
|
await cache.put(key, response)
|
|
110
161
|
}
|
|
111
162
|
|
|
163
|
+
readMeta = async key => this.metadata.has(key) ? this.metadata.get(key)
|
|
164
|
+
: await this.persist('indexeddb.get', () => get(key), () => undefined)
|
|
165
|
+
|
|
166
|
+
writeMeta = async (key, value) => {
|
|
167
|
+
const written = await this.persist('indexeddb.set', async () => { await set(key, value); return true }, () => false)
|
|
168
|
+
if (written) this.metadata.delete(key)
|
|
169
|
+
else this.metadata.set(key, value)
|
|
170
|
+
}
|
|
171
|
+
|
|
112
172
|
getMeta = async (key) => {
|
|
113
|
-
const etag = await
|
|
114
|
-
const timestamp = (await
|
|
173
|
+
const etag = await this.readMeta(`etag:${key}`)
|
|
174
|
+
const timestamp = (await this.readMeta(`timestamp:${key}`)) || 0
|
|
115
175
|
return { etag, timestamp }
|
|
116
176
|
}
|
|
117
177
|
|
|
118
178
|
setMeta = async (key, etag, version) => {
|
|
119
179
|
await this.initialize()
|
|
120
180
|
if (version !== undefined) {
|
|
121
|
-
await set(`version:${key}`, version)
|
|
122
181
|
if (version) this.versions.set(key, version)
|
|
123
182
|
else this.versions.delete(key)
|
|
183
|
+
await this.writeMeta(`version:${key}`, version)
|
|
124
184
|
}
|
|
125
|
-
if (etag) await
|
|
126
|
-
await
|
|
185
|
+
if (etag) await this.writeMeta(`etag:${key}`, etag)
|
|
186
|
+
await this.writeMeta(`timestamp:${key}`, Date.now())
|
|
127
187
|
}
|
|
128
188
|
|
|
129
189
|
remove = async (cache, key) => {
|
|
130
190
|
await cache.delete(key)
|
|
131
|
-
await
|
|
132
|
-
await
|
|
191
|
+
await this.writeMeta(`etag:${key}`, undefined)
|
|
192
|
+
await this.writeMeta(`timestamp:${key}`, undefined)
|
|
133
193
|
await this.setMeta(key, undefined, null)
|
|
134
194
|
this.generation += 1
|
|
135
195
|
}
|
|
@@ -140,7 +200,7 @@ class Cache {
|
|
|
140
200
|
const store = await this.open(name)
|
|
141
201
|
for (const request of await store.keys()) await this.remove(store, request.url)
|
|
142
202
|
this.generation += 1
|
|
143
|
-
return caches.delete(name)
|
|
203
|
+
return await this.persist('cache.delete-store', () => caches.delete(name), () => false)
|
|
144
204
|
}
|
|
145
205
|
|
|
146
206
|
preBlob = (data) => {
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.1.
|
|
2
|
+
"version": "2.1.3",
|
|
3
3
|
"name": "@fullstackunicorn/webapp",
|
|
4
4
|
"author": "lucanigido (https://fullstackunicorn.dev/author/lucanigido)",
|
|
5
5
|
"description": "Shared Web and Native runtime engines and core components for Fullstack Unicorn applications",
|
package/package.md
CHANGED
|
@@ -95,3 +95,15 @@ explicit direct downloads, Native adapters, and browser-owned DOM/CSS asset
|
|
|
95
95
|
requests remain unchanged. This does not introduce font prefetch or a new cache.
|
|
96
96
|
The focused permanent file suite covers the demonstrated font path and is part
|
|
97
97
|
of the package's maintainer tests.
|
|
98
|
+
|
|
99
|
+
Version 2.1.3 keeps valid responses available when browser persistence fails.
|
|
100
|
+
Only the existing Cache changes: failed CacheStorage operations retain the same
|
|
101
|
+
Response and identity in memory, and failed IndexedDB operations retain metadata
|
|
102
|
+
alongside the existing version/source maps. Normal successful storage has no
|
|
103
|
+
duplicate memory cache. Volatile values take precedence over older disk entries;
|
|
104
|
+
failed deletes leave a tombstone, and successful writes replace only their own
|
|
105
|
+
fallback. This fallback lasts for the current page and never claims persistence
|
|
106
|
+
across reload. Storage failures remain diagnostic warnings. JSON/Blob parsing,
|
|
107
|
+
HTTP identity and hash checks, cancellation and serialized revision commits
|
|
108
|
+
retain their existing behavior. No cache clearing, new controller or endpoint
|
|
109
|
+
is introduced; Client, Native and the frontend readers are unchanged.
|