@hkdigital/lib-sveltekit 0.1.73 → 0.1.75
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/classes/cache/IndexedDbCache.d.ts +78 -74
- package/dist/classes/cache/IndexedDbCache.js +1013 -312
- package/dist/classes/cache/index.js +0 -1
- package/dist/classes/cache/typedef.d.ts +24 -7
- package/dist/classes/cache/typedef.js +23 -7
- package/dist/widgets/presenter/Presenter.state.svelte.js +3 -1
- package/package.json +1 -1
- package/dist/classes/cache/CacheStorage.js__ +0 -45
- package/dist/classes/cache/PersistentResponseCache.js__ +0 -165
@@ -2,33 +2,34 @@ declare const _default: {};
|
|
2
2
|
export default _default;
|
3
3
|
export type CacheEntry = {
|
4
4
|
/**
|
5
|
-
*
|
5
|
+
* - Cached Response object
|
6
6
|
*/
|
7
7
|
response: Response;
|
8
8
|
/**
|
9
|
-
* Cache metadata
|
9
|
+
* - Cache entry metadata
|
10
10
|
*/
|
11
11
|
metadata: any;
|
12
12
|
/**
|
13
|
-
*
|
13
|
+
* - Original URL
|
14
14
|
*/
|
15
15
|
url: string;
|
16
16
|
/**
|
17
|
-
* When the entry was cached
|
17
|
+
* - When the entry was cached
|
18
18
|
*/
|
19
19
|
timestamp: number;
|
20
20
|
/**
|
21
|
-
*
|
21
|
+
* - Expiration timestamp (null if no expiration)
|
22
22
|
*/
|
23
23
|
expires: number | null;
|
24
24
|
/**
|
25
|
-
* ETag
|
25
|
+
* - ETag header if present
|
26
26
|
*/
|
27
27
|
etag: string | null;
|
28
28
|
/**
|
29
|
-
* Last-Modified
|
29
|
+
* - Last-Modified header if present
|
30
30
|
*/
|
31
31
|
lastModified: string | null;
|
32
|
+
cacheVersion: string | null;
|
32
33
|
};
|
33
34
|
export type CacheStorage = {
|
34
35
|
/**
|
@@ -48,3 +49,19 @@ export type CacheStorage = {
|
|
48
49
|
*/
|
49
50
|
clear: () => Promise<void>;
|
50
51
|
};
|
52
|
+
export type IDBRequestEvent = {
|
53
|
+
/**
|
54
|
+
* - The request that generated the event
|
55
|
+
*/
|
56
|
+
target: IDBRequest;
|
57
|
+
};
|
58
|
+
export type IDBVersionChangeEvent = {
|
59
|
+
/**
|
60
|
+
* - The request that generated the event
|
61
|
+
*/
|
62
|
+
target: IDBOpenDBRequest;
|
63
|
+
/**
|
64
|
+
* - The transaction for database upgrade
|
65
|
+
*/
|
66
|
+
transaction?: IDBTransaction;
|
67
|
+
};
|
@@ -1,13 +1,14 @@
|
|
1
1
|
|
2
2
|
/**
|
3
3
|
* @typedef {Object} CacheEntry
|
4
|
-
* @property {Response} response
|
5
|
-
* @property {Object} metadata Cache metadata
|
6
|
-
* @property {string} url
|
7
|
-
* @property {number} timestamp When the entry was cached
|
8
|
-
* @property {number|null} expires
|
9
|
-
* @property {string|null} etag ETag
|
10
|
-
* @property {string|null} lastModified Last-Modified
|
4
|
+
* @property {Response} response - Cached Response object
|
5
|
+
* @property {Object} metadata - Cache entry metadata
|
6
|
+
* @property {string} url - Original URL
|
7
|
+
* @property {number} timestamp - When the entry was cached
|
8
|
+
* @property {number|null} expires - Expiration timestamp (null if no expiration)
|
9
|
+
* @property {string|null} etag - ETag header if present
|
10
|
+
* @property {string|null} lastModified - Last-Modified header if present
|
11
|
+
* @property {string|null} cacheVersion
|
11
12
|
*/
|
12
13
|
|
13
14
|
/**
|
@@ -22,4 +23,19 @@
|
|
22
23
|
* Clear all cached responses
|
23
24
|
*/
|
24
25
|
|
26
|
+
// > IndexedDB
|
27
|
+
|
28
|
+
/**
|
29
|
+
* @typedef {Object} IDBRequestEvent
|
30
|
+
* @property {IDBRequest} target - The request that generated the event
|
31
|
+
*/
|
32
|
+
|
33
|
+
/**
|
34
|
+
* @typedef {Object} IDBVersionChangeEvent
|
35
|
+
* @property {IDBOpenDBRequest} target - The request that generated the event
|
36
|
+
* @property {IDBTransaction} [target.transaction] - The transaction for database upgrade
|
37
|
+
*/
|
38
|
+
|
39
|
+
// > Export default
|
40
|
+
|
25
41
|
export default {};
|
@@ -289,7 +289,9 @@ export class PresenterState {
|
|
289
289
|
}
|
290
290
|
|
291
291
|
if (slide.name === this.currentSlideName) {
|
292
|
-
throw new Error(`gotoSlide cannot transition to current slide`);
|
292
|
+
//throw new Error(`gotoSlide cannot transition to current slide`);
|
293
|
+
console.error(`gotoSlide cannot transition to current slide`);
|
294
|
+
return;
|
293
295
|
}
|
294
296
|
|
295
297
|
this.nextSlideName = slide.name;
|
package/package.json
CHANGED
@@ -1,45 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* @typedef {Object} CacheEntry
|
3
|
-
* @property {Response} response The cached response
|
4
|
-
* @property {Object} metadata Cache metadata including expiration
|
5
|
-
* @property {string} url The request URL
|
6
|
-
* @property {number} timestamp When the entry was cached
|
7
|
-
* @property {number|null} expires When the entry expires
|
8
|
-
* @property {string|null} etag ETag for conditional requests
|
9
|
-
* @property {string|null} lastModified Last-Modified for conditional requests
|
10
|
-
*/
|
11
|
-
|
12
|
-
/**
|
13
|
-
* Cache Storage Interface
|
14
|
-
* @interface
|
15
|
-
*/
|
16
|
-
class CacheStorage {
|
17
|
-
/**
|
18
|
-
* Get a cached response for a key
|
19
|
-
* @param {string} key Cache key
|
20
|
-
* @returns {Promise<CacheEntry|null>} Cached response or null if not found
|
21
|
-
*/
|
22
|
-
async get(key) { throw new Error('Not implemented'); }
|
23
|
-
|
24
|
-
/**
|
25
|
-
* Store a response in the cache
|
26
|
-
* @param {string} key Cache key
|
27
|
-
* @param {Response} response Response to cache
|
28
|
-
* @param {Object} metadata Cache metadata
|
29
|
-
* @returns {Promise<void>}
|
30
|
-
*/
|
31
|
-
async set(key, response, metadata) { throw new Error('Not implemented'); }
|
32
|
-
|
33
|
-
/**
|
34
|
-
* Remove a cached response
|
35
|
-
* @param {string} key Cache key
|
36
|
-
* @returns {Promise<boolean>} True if entry was removed
|
37
|
-
*/
|
38
|
-
async delete(key) { throw new Error('Not implemented'); }
|
39
|
-
|
40
|
-
/**
|
41
|
-
* Clear all cached responses
|
42
|
-
* @returns {Promise<void>}
|
43
|
-
*/
|
44
|
-
async clear() { throw new Error('Not implemented'); }
|
45
|
-
}
|
@@ -1,165 +0,0 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
/**
|
4
|
-
* ReponseCache
|
5
|
-
* Using IndexedDB for persistent storage
|
6
|
-
*/
|
7
|
-
export default class ResponseCache {
|
8
|
-
/**
|
9
|
-
* Create a new IndexedDB cache storage
|
10
|
-
* @param {string} dbName Database name
|
11
|
-
* @param {string} storeName Store name
|
12
|
-
*/
|
13
|
-
constructor(dbName = 'http-cache', storeName = 'responses') {
|
14
|
-
this.dbName = dbName;
|
15
|
-
this.storeName = storeName;
|
16
|
-
this.dbPromise = this._openDatabase();
|
17
|
-
}
|
18
|
-
|
19
|
-
/**
|
20
|
-
* Open the IndexedDB database
|
21
|
-
* @private
|
22
|
-
* @returns {Promise<IDBDatabase>}
|
23
|
-
*/
|
24
|
-
async _openDatabase() {
|
25
|
-
return new Promise((resolve, reject) => {
|
26
|
-
const request = indexedDB.open(this.dbName, 1);
|
27
|
-
|
28
|
-
request.onerror = () => reject(request.error);
|
29
|
-
request.onsuccess = () => resolve(request.result);
|
30
|
-
|
31
|
-
request.onupgradeneeded = (event) => {
|
32
|
-
const db = event.target.result;
|
33
|
-
if (!db.objectStoreNames.contains(this.storeName)) {
|
34
|
-
db.createObjectStore(this.storeName, { keyPath: 'key' });
|
35
|
-
}
|
36
|
-
};
|
37
|
-
});
|
38
|
-
}
|
39
|
-
|
40
|
-
/**
|
41
|
-
* Get a cached response
|
42
|
-
* @param {string} key Cache key
|
43
|
-
* @returns {Promise<import('./typedef').CacheEntry|null>}
|
44
|
-
*/
|
45
|
-
async get(key) {
|
46
|
-
const db = await this.dbPromise;
|
47
|
-
|
48
|
-
return new Promise((resolve, reject) => {
|
49
|
-
const transaction = db.transaction(this.storeName, 'readonly');
|
50
|
-
const store = transaction.objectStore(this.storeName);
|
51
|
-
const request = store.get(key);
|
52
|
-
|
53
|
-
request.onerror = () => reject(request.error);
|
54
|
-
request.onsuccess = () => {
|
55
|
-
const entry = request.result;
|
56
|
-
|
57
|
-
if (!entry) {
|
58
|
-
resolve(null);
|
59
|
-
return;
|
60
|
-
}
|
61
|
-
|
62
|
-
// Check if expired
|
63
|
-
if (entry.expires && Date.now() > entry.expires) {
|
64
|
-
// Delete expired entry
|
65
|
-
this.delete(key).catch(console.error);
|
66
|
-
resolve(null);
|
67
|
-
return;
|
68
|
-
}
|
69
|
-
|
70
|
-
// Deserialize the response
|
71
|
-
const response = new Response(entry.body, {
|
72
|
-
status: entry.status,
|
73
|
-
statusText: entry.statusText,
|
74
|
-
headers: new Headers(entry.headers)
|
75
|
-
});
|
76
|
-
|
77
|
-
resolve({
|
78
|
-
response,
|
79
|
-
metadata: entry.metadata,
|
80
|
-
url: entry.url,
|
81
|
-
timestamp: entry.timestamp,
|
82
|
-
expires: entry.expires,
|
83
|
-
etag: entry.etag,
|
84
|
-
lastModified: entry.lastModified
|
85
|
-
});
|
86
|
-
};
|
87
|
-
});
|
88
|
-
}
|
89
|
-
|
90
|
-
/**
|
91
|
-
* Store a response in the cache
|
92
|
-
* @param {string} key Cache key
|
93
|
-
* @param {Response} response Response to cache
|
94
|
-
* @param {Object} metadata Cache metadata
|
95
|
-
* @returns {Promise<void>}
|
96
|
-
*/
|
97
|
-
async set(key, response, metadata) {
|
98
|
-
const db = await this.dbPromise;
|
99
|
-
|
100
|
-
// Clone the response to avoid consuming it
|
101
|
-
const clonedResponse = response.clone();
|
102
|
-
|
103
|
-
// Extract response data
|
104
|
-
const body = await clonedResponse.blob();
|
105
|
-
const headers = Array.from(clonedResponse.headers.entries());
|
106
|
-
|
107
|
-
const entry = {
|
108
|
-
key,
|
109
|
-
url: clonedResponse.url,
|
110
|
-
status: clonedResponse.status,
|
111
|
-
statusText: clonedResponse.statusText,
|
112
|
-
headers,
|
113
|
-
body,
|
114
|
-
metadata,
|
115
|
-
timestamp: Date.now(),
|
116
|
-
expires: metadata.expires || null,
|
117
|
-
etag: clonedResponse.headers.get('ETag'),
|
118
|
-
lastModified: clonedResponse.headers.get('Last-Modified')
|
119
|
-
};
|
120
|
-
|
121
|
-
return new Promise((resolve, reject) => {
|
122
|
-
const transaction = db.transaction(this.storeName, 'readwrite');
|
123
|
-
const store = transaction.objectStore(this.storeName);
|
124
|
-
const request = store.put(entry);
|
125
|
-
|
126
|
-
request.onerror = () => reject(request.error);
|
127
|
-
request.onsuccess = () => resolve();
|
128
|
-
});
|
129
|
-
}
|
130
|
-
|
131
|
-
/**
|
132
|
-
* Delete a cached response
|
133
|
-
* @param {string} key Cache key
|
134
|
-
* @returns {Promise<boolean>}
|
135
|
-
*/
|
136
|
-
async delete(key) {
|
137
|
-
const db = await this.dbPromise;
|
138
|
-
|
139
|
-
return new Promise((resolve, reject) => {
|
140
|
-
const transaction = db.transaction(this.storeName, 'readwrite');
|
141
|
-
const store = transaction.objectStore(this.storeName);
|
142
|
-
const request = store.delete(key);
|
143
|
-
|
144
|
-
request.onerror = () => reject(request.error);
|
145
|
-
request.onsuccess = () => resolve(true);
|
146
|
-
});
|
147
|
-
}
|
148
|
-
|
149
|
-
/**
|
150
|
-
* Clear all cached responses
|
151
|
-
* @returns {Promise<void>}
|
152
|
-
*/
|
153
|
-
async clear() {
|
154
|
-
const db = await this.dbPromise;
|
155
|
-
|
156
|
-
return new Promise((resolve, reject) => {
|
157
|
-
const transaction = db.transaction(this.storeName, 'readwrite');
|
158
|
-
const store = transaction.objectStore(this.storeName);
|
159
|
-
const request = store.clear();
|
160
|
-
|
161
|
-
request.onerror = () => reject(request.error);
|
162
|
-
request.onsuccess = () => resolve();
|
163
|
-
});
|
164
|
-
}
|
165
|
-
}
|