@hkdigital/lib-sveltekit 0.1.70 → 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.js +22 -12
- package/dist/util/http/http-request.js +12 -7
- 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,18 +1,27 @@
|
|
1
1
|
import {
|
2
2
|
MemoryResponseCache,
|
3
|
-
|
3
|
+
IndexedDbCache
|
4
4
|
} from '../../classes/cache';
|
5
5
|
|
6
|
+
import { browser } from '$app/environment';
|
7
|
+
|
6
8
|
let defaultCacheStorage = null;
|
7
9
|
|
8
10
|
function getCacheStorage()
|
9
11
|
{
|
10
12
|
if( !defaultCacheStorage )
|
11
13
|
{
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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);
|
16
25
|
}
|
17
26
|
|
18
27
|
return defaultCacheStorage
|
@@ -123,18 +132,19 @@ export async function getCachedResponse(cacheKeyParams) {
|
|
123
132
|
|
124
133
|
/**
|
125
134
|
* Create a cache storage adapter
|
126
|
-
* @param {string} type Type of storage ('
|
135
|
+
* @param {string} type Type of storage ('indexed-db', 'memory')
|
127
136
|
* @param {Object} options Options for the storage adapter
|
128
137
|
*
|
129
138
|
* @returns {import('../../classes/cache').CacheStorage}
|
130
139
|
*/
|
131
|
-
function createCacheStorage(type = '
|
140
|
+
function createCacheStorage(type = 'indexed-db', options = {}) {
|
132
141
|
switch (type) {
|
133
|
-
case '
|
134
|
-
return new
|
135
|
-
|
136
|
-
|
137
|
-
|
142
|
+
case 'indexed-db':
|
143
|
+
return new IndexedDbCache(
|
144
|
+
{
|
145
|
+
dbName: 'http-cache',
|
146
|
+
storeName: 'responses'
|
147
|
+
} );
|
138
148
|
|
139
149
|
case 'memory':
|
140
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,7 +171,7 @@ export async function httpRequest(options) {
|
|
169
171
|
|
170
172
|
const url = toURL(rawUrl);
|
171
173
|
|
172
|
-
console.debug(`
|
174
|
+
// console.debug(`http:load [${url.pathname}]`);
|
173
175
|
|
174
176
|
// Only consider caching for GET requests
|
175
177
|
const shouldAttemptCache = cacheEnabled && method === METHOD_GET;
|
@@ -179,12 +181,15 @@ export async function httpRequest(options) {
|
|
179
181
|
const cacheKeyParams = { url, ...headers };
|
180
182
|
const cachedResponse = await getCachedResponse(cacheKeyParams);
|
181
183
|
|
182
|
-
if
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
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
|
+
}
|
188
193
|
}
|
189
194
|
}
|
190
195
|
|
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
|