@hkdigital/lib-sveltekit 0.1.69 → 0.1.71
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 +212 -0
- package/dist/classes/cache/IndexedDbCache.js +673 -0
- package/dist/classes/cache/MemoryResponseCache.d.ts +101 -14
- package/dist/classes/cache/MemoryResponseCache.js +97 -12
- package/dist/classes/cache/index.d.ts +1 -1
- package/dist/classes/cache/index.js +2 -1
- package/dist/classes/events/EventEmitter.d.ts +142 -0
- package/dist/classes/events/EventEmitter.js +275 -0
- package/dist/classes/events/index.d.ts +1 -0
- package/dist/classes/events/index.js +2 -0
- package/dist/classes/logging/Logger.d.ts +74 -0
- package/dist/classes/logging/Logger.js +158 -0
- package/dist/classes/logging/constants.d.ts +14 -0
- package/dist/classes/logging/constants.js +18 -0
- package/dist/classes/logging/index.d.ts +2 -0
- package/dist/classes/logging/index.js +4 -0
- package/dist/classes/services/ServiceBase.d.ts +153 -0
- package/dist/classes/services/ServiceBase.js +409 -0
- package/dist/classes/services/ServiceManager.d.ts +350 -0
- package/dist/classes/services/ServiceManager.js +1114 -0
- package/dist/classes/services/constants.d.ts +11 -0
- package/dist/classes/services/constants.js +12 -0
- package/dist/classes/services/index.d.ts +3 -0
- package/dist/classes/services/index.js +5 -0
- package/dist/util/env/index.d.ts +1 -0
- package/dist/util/env/index.js +5 -0
- package/dist/util/http/caching.d.ts +0 -1
- package/dist/util/http/caching.js +34 -14
- package/dist/util/http/http-request.js +13 -3
- package/dist/widgets/game-box/GameBox.svelte +2 -2
- package/package.json +2 -1
- package/dist/classes/cache/PersistentResponseCache.d.ts +0 -46
- /package/dist/classes/cache/{PersistentResponseCache.js → PersistentResponseCache.js__} +0 -0
@@ -0,0 +1,11 @@
|
|
1
|
+
export const CREATED: "created";
|
2
|
+
export const INITIALIZING: "initializing";
|
3
|
+
export const INITIALIZED: "initialized";
|
4
|
+
export const STARTING: "starting";
|
5
|
+
export const RUNNING: "running";
|
6
|
+
export const STOPPING: "stopping";
|
7
|
+
export const STOPPED: "stopped";
|
8
|
+
export const DESTROYING: "destroying";
|
9
|
+
export const DESTROYED: "destroyed";
|
10
|
+
export const ERROR: "error";
|
11
|
+
export const RECOVERING: "recovering";
|
@@ -0,0 +1,12 @@
|
|
1
|
+
|
2
|
+
export const CREATED = 'created';
|
3
|
+
export const INITIALIZING = 'initializing';
|
4
|
+
export const INITIALIZED = 'initialized';
|
5
|
+
export const STARTING = 'starting';
|
6
|
+
export const RUNNING = 'running';
|
7
|
+
export const STOPPING = 'stopping';
|
8
|
+
export const STOPPED = 'stopped';
|
9
|
+
export const DESTROYING = 'destroying';
|
10
|
+
export const DESTROYED = 'destroyed';
|
11
|
+
export const ERROR = 'error';
|
12
|
+
export const RECOVERING = 'recovering';
|
@@ -0,0 +1 @@
|
|
1
|
+
export const isTestMode: boolean;
|
@@ -1,12 +1,31 @@
|
|
1
1
|
import {
|
2
2
|
MemoryResponseCache,
|
3
|
-
|
3
|
+
IndexedDbCache
|
4
4
|
} from '../../classes/cache';
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
import { browser } from '$app/environment';
|
7
|
+
|
8
|
+
let defaultCacheStorage = null;
|
9
|
+
|
10
|
+
function getCacheStorage()
|
11
|
+
{
|
12
|
+
if( !defaultCacheStorage )
|
13
|
+
{
|
14
|
+
let type;
|
15
|
+
|
16
|
+
if( !browser || process.env.NODE_ENV === 'test' )
|
17
|
+
{
|
18
|
+
type = 'memory';
|
19
|
+
}
|
20
|
+
else {
|
21
|
+
type = 'indexed-db';
|
22
|
+
}
|
23
|
+
|
24
|
+
defaultCacheStorage = createCacheStorage( type);
|
25
|
+
}
|
26
|
+
|
27
|
+
return defaultCacheStorage
|
28
|
+
}
|
10
29
|
|
11
30
|
/**
|
12
31
|
* Store a response in the cache
|
@@ -50,7 +69,7 @@ export async function storeResponseInCache(cacheKeyParams, response, metadata) {
|
|
50
69
|
};
|
51
70
|
|
52
71
|
// Store in cache
|
53
|
-
await
|
72
|
+
await getCacheStorage().set(cacheKey, response, enhancedMetadata);
|
54
73
|
} catch (error) {
|
55
74
|
console.error('Cache storage error:', error);
|
56
75
|
}
|
@@ -75,7 +94,7 @@ export async function getCachedResponse(cacheKeyParams) {
|
|
75
94
|
const cacheKey = generateCacheKey(url, headers);
|
76
95
|
|
77
96
|
// Get cached entry
|
78
|
-
const cachedEntry = await
|
97
|
+
const cachedEntry = await getCacheStorage().get(cacheKey);
|
79
98
|
|
80
99
|
if (!cachedEntry) {
|
81
100
|
return null;
|
@@ -113,18 +132,19 @@ export async function getCachedResponse(cacheKeyParams) {
|
|
113
132
|
|
114
133
|
/**
|
115
134
|
* Create a cache storage adapter
|
116
|
-
* @param {string} type Type of storage ('
|
135
|
+
* @param {string} type Type of storage ('indexed-db', 'memory')
|
117
136
|
* @param {Object} options Options for the storage adapter
|
118
137
|
*
|
119
138
|
* @returns {import('../../classes/cache').CacheStorage}
|
120
139
|
*/
|
121
|
-
function createCacheStorage(type = '
|
140
|
+
function createCacheStorage(type = 'indexed-db', options = {}) {
|
122
141
|
switch (type) {
|
123
|
-
case '
|
124
|
-
return new
|
125
|
-
|
126
|
-
|
127
|
-
|
142
|
+
case 'indexed-db':
|
143
|
+
return new IndexedDbCache(
|
144
|
+
{
|
145
|
+
dbName: 'http-cache',
|
146
|
+
storeName: 'responses'
|
147
|
+
} );
|
128
148
|
|
129
149
|
case 'memory':
|
130
150
|
return new MemoryResponseCache();
|
@@ -13,6 +13,8 @@ import { waitForAndCheckResponse } from './response.js';
|
|
13
13
|
|
14
14
|
import { getCachedResponse, storeResponseInCache } from './caching.js';
|
15
15
|
|
16
|
+
import { isTestMode } from '../env';
|
17
|
+
|
16
18
|
/**
|
17
19
|
* Default configuration for HTTP requests
|
18
20
|
*
|
@@ -169,6 +171,8 @@ export async function httpRequest(options) {
|
|
169
171
|
|
170
172
|
const url = toURL(rawUrl);
|
171
173
|
|
174
|
+
// console.debug(`http:load [${url.pathname}]`);
|
175
|
+
|
172
176
|
// Only consider caching for GET requests
|
173
177
|
const shouldAttemptCache = cacheEnabled && method === METHOD_GET;
|
174
178
|
|
@@ -177,9 +181,15 @@ export async function httpRequest(options) {
|
|
177
181
|
const cacheKeyParams = { url, ...headers };
|
178
182
|
const cachedResponse = await getCachedResponse(cacheKeyParams);
|
179
183
|
|
180
|
-
if
|
181
|
-
|
182
|
-
|
184
|
+
if( !isTestMode )
|
185
|
+
{
|
186
|
+
if (cachedResponse) {
|
187
|
+
console.debug(`http:cache-hit [${url.pathname}]`);
|
188
|
+
return cachedResponse;
|
189
|
+
}
|
190
|
+
else {
|
191
|
+
console.debug(`http:cache-miss [${url.pathname}]`);
|
192
|
+
}
|
183
193
|
}
|
184
194
|
}
|
185
195
|
|
@@ -6,8 +6,8 @@
|
|
6
6
|
getGameWidthOnPortrait
|
7
7
|
} from './gamebox.util.js';
|
8
8
|
|
9
|
-
|
10
|
-
import { enableContainerScaling } from '@hkdigital/lib-sveltekit/util/design-system/index.js';
|
9
|
+
import { enableContainerScaling } from '../../util/design-system/index.js';
|
10
|
+
// import { enableContainerScaling } from '@hkdigital/lib-sveltekit/util/design-system/index.js';
|
11
11
|
|
12
12
|
/**
|
13
13
|
* @typedef {{
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@hkdigital/lib-sveltekit",
|
3
|
-
"version": "0.1.
|
3
|
+
"version": "0.1.71",
|
4
4
|
"author": {
|
5
5
|
"name": "HKdigital",
|
6
6
|
"url": "https://hkdigital.nl"
|
@@ -81,6 +81,7 @@
|
|
81
81
|
"eslint": "^9.21.0",
|
82
82
|
"eslint-config-prettier": "^10.0.2",
|
83
83
|
"eslint-plugin-svelte": "^3.0.2",
|
84
|
+
"fake-indexeddb": "^6.0.0",
|
84
85
|
"globals": "^16.0.0",
|
85
86
|
"jsdom": "^26.0.0",
|
86
87
|
"pino": "^9.6.0",
|
@@ -1,46 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* ReponseCache
|
3
|
-
* Using IndexedDB for persistent storage
|
4
|
-
*/
|
5
|
-
export default class ResponseCache {
|
6
|
-
/**
|
7
|
-
* Create a new IndexedDB cache storage
|
8
|
-
* @param {string} dbName Database name
|
9
|
-
* @param {string} storeName Store name
|
10
|
-
*/
|
11
|
-
constructor(dbName?: string, storeName?: string);
|
12
|
-
dbName: string;
|
13
|
-
storeName: string;
|
14
|
-
dbPromise: Promise<IDBDatabase>;
|
15
|
-
/**
|
16
|
-
* Open the IndexedDB database
|
17
|
-
* @private
|
18
|
-
* @returns {Promise<IDBDatabase>}
|
19
|
-
*/
|
20
|
-
private _openDatabase;
|
21
|
-
/**
|
22
|
-
* Get a cached response
|
23
|
-
* @param {string} key Cache key
|
24
|
-
* @returns {Promise<import('./typedef').CacheEntry|null>}
|
25
|
-
*/
|
26
|
-
get(key: string): Promise<import("./typedef").CacheEntry | null>;
|
27
|
-
/**
|
28
|
-
* Store a response in the cache
|
29
|
-
* @param {string} key Cache key
|
30
|
-
* @param {Response} response Response to cache
|
31
|
-
* @param {Object} metadata Cache metadata
|
32
|
-
* @returns {Promise<void>}
|
33
|
-
*/
|
34
|
-
set(key: string, response: Response, metadata: any): Promise<void>;
|
35
|
-
/**
|
36
|
-
* Delete a cached response
|
37
|
-
* @param {string} key Cache key
|
38
|
-
* @returns {Promise<boolean>}
|
39
|
-
*/
|
40
|
-
delete(key: string): Promise<boolean>;
|
41
|
-
/**
|
42
|
-
* Clear all cached responses
|
43
|
-
* @returns {Promise<void>}
|
44
|
-
*/
|
45
|
-
clear(): Promise<void>;
|
46
|
-
}
|
File without changes
|