@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.
Files changed (31) hide show
  1. package/dist/classes/cache/IndexedDbCache.d.ts +212 -0
  2. package/dist/classes/cache/IndexedDbCache.js +673 -0
  3. package/dist/classes/cache/MemoryResponseCache.d.ts +101 -14
  4. package/dist/classes/cache/MemoryResponseCache.js +97 -12
  5. package/dist/classes/cache/index.d.ts +1 -1
  6. package/dist/classes/cache/index.js +2 -1
  7. package/dist/classes/events/EventEmitter.d.ts +142 -0
  8. package/dist/classes/events/EventEmitter.js +275 -0
  9. package/dist/classes/events/index.d.ts +1 -0
  10. package/dist/classes/events/index.js +2 -0
  11. package/dist/classes/logging/Logger.d.ts +74 -0
  12. package/dist/classes/logging/Logger.js +158 -0
  13. package/dist/classes/logging/constants.d.ts +14 -0
  14. package/dist/classes/logging/constants.js +18 -0
  15. package/dist/classes/logging/index.d.ts +2 -0
  16. package/dist/classes/logging/index.js +4 -0
  17. package/dist/classes/services/ServiceBase.d.ts +153 -0
  18. package/dist/classes/services/ServiceBase.js +409 -0
  19. package/dist/classes/services/ServiceManager.d.ts +350 -0
  20. package/dist/classes/services/ServiceManager.js +1114 -0
  21. package/dist/classes/services/constants.d.ts +11 -0
  22. package/dist/classes/services/constants.js +12 -0
  23. package/dist/classes/services/index.d.ts +3 -0
  24. package/dist/classes/services/index.js +5 -0
  25. package/dist/util/env/index.d.ts +1 -0
  26. package/dist/util/env/index.js +9 -0
  27. package/dist/util/http/caching.js +24 -12
  28. package/dist/util/http/http-request.js +12 -7
  29. package/package.json +2 -1
  30. package/dist/classes/cache/PersistentResponseCache.d.ts +0 -46
  31. /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,3 @@
1
+ export { default as ServiceBase } from "./ServiceBase.js";
2
+ export { default as ServiceManager } from "./ServiceManager.js";
3
+ export * from "./constants.js";
@@ -0,0 +1,5 @@
1
+
2
+ export { default as ServiceBase } from './ServiceBase.js';
3
+ export { default as ServiceManager } from './ServiceManager.js';
4
+
5
+ export * from './constants.js';
@@ -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
- PersistentResponseCache
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
- defaultCacheStorage =
13
- createCacheStorage(
14
- process.env.NODE_ENV === 'test' ? 'memory' : 'persistent'
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 ('persistent', 'memory')
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 = 'persistent', options = {}) {
142
+ function createCacheStorage(type = 'indexed-db', options = {}) {
132
143
  switch (type) {
133
- case 'persistent':
134
- return new PersistentResponseCache(
135
- options.dbName || 'http-cache',
136
- options.storeName || 'responses'
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(`httpRequest:load [${url.pathname}]`);
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 (cachedResponse) {
183
- console.debug(`httpRequest:cache-hit [${url.pathname}]`);
184
- return cachedResponse;
185
- }
186
- else {
187
- console.debug(`httpRequest:cache-miss [${url.pathname}]`);
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.70",
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
- }