@hkdigital/lib-sveltekit 0.1.70 → 0.1.72
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 +9 -0
- package/dist/util/http/caching.js +24 -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 isTestEnv: boolean;
|
@@ -0,0 +1,9 @@
|
|
1
|
+
|
2
|
+
export const isTestEnv = (
|
3
|
+
// For Vite environments
|
4
|
+
(typeof import.meta !== 'undefined' && import.meta.env?.MODE === 'test') ||
|
5
|
+
// For Node environments, safely check process
|
6
|
+
(typeof process !== 'undefined' && process?.env?.NODE_ENV === 'test') ||
|
7
|
+
// For Vitest specific check
|
8
|
+
(typeof process !== 'undefined' && process?.env?.VITEST !== undefined)
|
9
|
+
);
|
@@ -1,18 +1,29 @@
|
|
1
1
|
import {
|
2
2
|
MemoryResponseCache,
|
3
|
-
|
3
|
+
IndexedDbCache
|
4
4
|
} from '../../classes/cache';
|
5
5
|
|
6
|
+
import { browser } from '$app/environment';
|
7
|
+
|
8
|
+
import { isTestEnv } from '../env';
|
9
|
+
|
6
10
|
let defaultCacheStorage = null;
|
7
11
|
|
8
12
|
function getCacheStorage()
|
9
13
|
{
|
10
14
|
if( !defaultCacheStorage )
|
11
15
|
{
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
+
let type;
|
17
|
+
|
18
|
+
if( !browser || isTestEnv )
|
19
|
+
{
|
20
|
+
type = 'memory';
|
21
|
+
}
|
22
|
+
else {
|
23
|
+
type = 'indexed-db';
|
24
|
+
}
|
25
|
+
|
26
|
+
defaultCacheStorage = createCacheStorage( type);
|
16
27
|
}
|
17
28
|
|
18
29
|
return defaultCacheStorage
|
@@ -123,18 +134,19 @@ export async function getCachedResponse(cacheKeyParams) {
|
|
123
134
|
|
124
135
|
/**
|
125
136
|
* Create a cache storage adapter
|
126
|
-
* @param {string} type Type of storage ('
|
137
|
+
* @param {string} type Type of storage ('indexed-db', 'memory')
|
127
138
|
* @param {Object} options Options for the storage adapter
|
128
139
|
*
|
129
140
|
* @returns {import('../../classes/cache').CacheStorage}
|
130
141
|
*/
|
131
|
-
function createCacheStorage(type = '
|
142
|
+
function createCacheStorage(type = 'indexed-db', options = {}) {
|
132
143
|
switch (type) {
|
133
|
-
case '
|
134
|
-
return new
|
135
|
-
|
136
|
-
|
137
|
-
|
144
|
+
case 'indexed-db':
|
145
|
+
return new IndexedDbCache(
|
146
|
+
{
|
147
|
+
dbName: 'http-cache',
|
148
|
+
storeName: 'responses'
|
149
|
+
} );
|
138
150
|
|
139
151
|
case 'memory':
|
140
152
|
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 { isTestEnv } 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( !isTestEnv )
|
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.72",
|
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
|