@fjell/cache 4.6.0 → 4.6.1
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/.kodrdriv/config.yaml +10 -0
- package/.kodrdriv/context/content.md +1 -0
- package/dist/Aggregator.cjs.js +1 -1
- package/dist/Aggregator.d.ts +1 -1
- package/dist/Aggregator.es.js +1 -1
- package/dist/Cache.cjs.js +1 -1
- package/dist/Cache.d.ts +1 -1
- package/dist/Cache.es.js +1 -1
- package/dist/CacheRegistry.cjs.js +33 -21
- package/dist/CacheRegistry.d.ts +2 -5
- package/dist/CacheRegistry.es.js +33 -21
- package/dist/index.cjs +35 -23
- package/dist/index.cjs.map +1 -1
- package/dist/logger.cjs.js +1 -1
- package/dist/logger.es.js +1 -1
- package/package.json +3 -2
- package/src/Aggregator.ts +4 -4
- package/src/Cache.ts +5 -5
- package/src/CacheRegistry.ts +37 -25
- package/src/logger.ts +1 -1
- package/vitest.config.ts +34 -0
- package/eslint.config.mjs +0 -70
- package/vite.config.ts +0 -91
|
@@ -0,0 +1 @@
|
|
|
1
|
+
This is the Fjell Library for Client-side Caches
|
package/dist/Aggregator.cjs.js
CHANGED
|
@@ -17,7 +17,7 @@ const toCacheConfig = (config)=>{
|
|
|
17
17
|
}
|
|
18
18
|
return cacheConfig;
|
|
19
19
|
};
|
|
20
|
-
const createAggregator = (cache, { aggregates = {}, events = {} })=>{
|
|
20
|
+
const createAggregator = async (cache, { aggregates = {}, events = {} })=>{
|
|
21
21
|
const populate = async (item)=>{
|
|
22
22
|
logger.default('populate', {
|
|
23
23
|
item
|
package/dist/Aggregator.d.ts
CHANGED
|
@@ -16,4 +16,4 @@ export declare const toCacheConfig: <V extends Item<S, L1, L2, L3, L4, L5>, S ex
|
|
|
16
16
|
export declare const createAggregator: <V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(cache: Cache<V, S, L1, L2, L3, L4, L5>, { aggregates, events }: {
|
|
17
17
|
aggregates?: AggregateConfig;
|
|
18
18
|
events?: AggregateConfig;
|
|
19
|
-
}) => Aggregator<V, S, L1, L2, L3, L4, L5
|
|
19
|
+
}) => Promise<Aggregator<V, S, L1, L2, L3, L4, L5>>;
|
package/dist/Aggregator.es.js
CHANGED
|
@@ -13,7 +13,7 @@ const toCacheConfig = (config)=>{
|
|
|
13
13
|
}
|
|
14
14
|
return cacheConfig;
|
|
15
15
|
};
|
|
16
|
-
const createAggregator = (cache, { aggregates = {}, events = {} })=>{
|
|
16
|
+
const createAggregator = async (cache, { aggregates = {}, events = {} })=>{
|
|
17
17
|
const populate = async (item)=>{
|
|
18
18
|
logger.default('populate', {
|
|
19
19
|
item
|
package/dist/Cache.cjs.js
CHANGED
|
@@ -8,7 +8,7 @@ const logger$1 = require('./logger.cjs.js');
|
|
|
8
8
|
const httpApi = require('@fjell/http-api');
|
|
9
9
|
|
|
10
10
|
const logger = logger$1.default.get('Cache');
|
|
11
|
-
const createCache = (api, pkType, parentCache)=>{
|
|
11
|
+
const createCache = async (api, pkType, parentCache)=>{
|
|
12
12
|
let pkTypes = [
|
|
13
13
|
pkType
|
|
14
14
|
];
|
package/dist/Cache.d.ts
CHANGED
|
@@ -17,4 +17,4 @@ export interface Cache<V extends Item<S, L1, L2, L3, L4, L5>, S extends string,
|
|
|
17
17
|
pkTypes: AllItemTypeArrays<S, L1, L2, L3, L4, L5>;
|
|
18
18
|
cacheMap: CacheMap<V, S, L1, L2, L3, L4, L5>;
|
|
19
19
|
}
|
|
20
|
-
export declare const createCache: <V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(api: ClientApi<V, S, L1, L2, L3, L4, L5>, pkType: S, parentCache?: Cache<Item<L1, L2, L3, L4, L5>, L1, L2, L3, L4, L5>) => Cache<V, S, L1, L2, L3, L4, L5
|
|
20
|
+
export declare const createCache: <V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(api: ClientApi<V, S, L1, L2, L3, L4, L5>, pkType: S, parentCache?: Cache<Item<L1, L2, L3, L4, L5>, L1, L2, L3, L4, L5>) => Promise<Cache<V, S, L1, L2, L3, L4, L5>>;
|
package/dist/Cache.es.js
CHANGED
|
@@ -4,7 +4,7 @@ import LibLogger from './logger.es.js';
|
|
|
4
4
|
import { NotFoundError } from '@fjell/http-api';
|
|
5
5
|
|
|
6
6
|
const logger = LibLogger.get('Cache');
|
|
7
|
-
const createCache = (api, pkType, parentCache)=>{
|
|
7
|
+
const createCache = async (api, pkType, parentCache)=>{
|
|
8
8
|
let pkTypes = [
|
|
9
9
|
pkType
|
|
10
10
|
];
|
|
@@ -19,36 +19,48 @@ function _define_property(obj, key, value) {
|
|
|
19
19
|
}
|
|
20
20
|
const logger = logger$1.default.get('CacheRegistry');
|
|
21
21
|
class CacheRegistry {
|
|
22
|
-
static getInstance() {
|
|
23
|
-
if (!CacheRegistry.instance) {
|
|
24
|
-
CacheRegistry.instance = new CacheRegistry();
|
|
25
|
-
}
|
|
26
|
-
return CacheRegistry.instance;
|
|
27
|
-
}
|
|
28
22
|
constructor(){
|
|
29
|
-
_define_property(this, "configured", false);
|
|
30
23
|
// TODO: My use of Generics has Boxed me into a corner where I can't reference AbstractCache without the types
|
|
31
24
|
_define_property(this, "cacheMap", {});
|
|
32
|
-
_define_property(this, "registerCache", (cache)=>{
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
25
|
+
_define_property(this, "registerCache", async (cache)=>{
|
|
26
|
+
try {
|
|
27
|
+
logger.debug('Attempting to register cache with pkTypes:', cache.pkTypes);
|
|
28
|
+
const key = JSON.stringify(cache.pkTypes);
|
|
29
|
+
if (this.cacheMap[key]) {
|
|
30
|
+
logger.debug(`Cache with pkTypes ${key} already exists, will be overwritten`);
|
|
31
|
+
}
|
|
32
|
+
this.cacheMap[key] = cache;
|
|
33
|
+
logger.debug('Cache registered successfully with key:', key);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
logger.error('Failed to register cache:', error);
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
40
38
|
});
|
|
41
39
|
_define_property(this, "getCache", (kts)=>{
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
logger.debug('Attempting to get cache for key types:', kts);
|
|
41
|
+
const key = JSON.stringify(kts);
|
|
42
|
+
logger.debug('Looking up cache with key:', key);
|
|
43
|
+
const cache = this.cacheMap[key];
|
|
44
|
+
if (!cache) {
|
|
45
|
+
logger.warning(`No cache found for key types: ${key}`);
|
|
46
|
+
}
|
|
47
|
+
return cache;
|
|
48
|
+
});
|
|
49
|
+
_define_property(this, "printRegisteredCaches", ()=>{
|
|
50
|
+
logger.debug('Printing all registered caches:');
|
|
51
|
+
const cacheCount = Object.keys(this.cacheMap).length;
|
|
52
|
+
logger.debug(`Total number of registered caches: ${cacheCount}`);
|
|
53
|
+
if (cacheCount === 0) {
|
|
54
|
+
logger.debug('No caches are currently registered');
|
|
45
55
|
}
|
|
46
|
-
|
|
56
|
+
Object.entries(this.cacheMap).forEach(([keyTypes])=>{
|
|
57
|
+
logger.debug(`Cache with key types: ${keyTypes}`);
|
|
58
|
+
});
|
|
47
59
|
});
|
|
48
|
-
logger.debug('CacheRegistry created');
|
|
60
|
+
logger.debug('CacheRegistry instance created');
|
|
49
61
|
}
|
|
50
62
|
}
|
|
51
63
|
_define_property(CacheRegistry, "instance", void 0);
|
|
52
64
|
|
|
53
65
|
exports.CacheRegistry = CacheRegistry;
|
|
54
|
-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,
|
|
66
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ2FjaGVSZWdpc3RyeS5janMuanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0=
|
package/dist/CacheRegistry.d.ts
CHANGED
|
@@ -2,12 +2,9 @@ import { Item } from '@fjell/core';
|
|
|
2
2
|
import { Cache } from './Cache';
|
|
3
3
|
export declare class CacheRegistry {
|
|
4
4
|
private static instance;
|
|
5
|
-
private configured;
|
|
6
5
|
constructor();
|
|
7
|
-
static getInstance(): CacheRegistry;
|
|
8
6
|
private cacheMap;
|
|
9
|
-
registerCache: <S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(cache: Cache<Item<S, L1, L2, L3, L4, L5>, S, L1, L2, L3, L4, L5>) => void
|
|
10
|
-
isConfigured: () => boolean;
|
|
11
|
-
markConfigured: () => void;
|
|
7
|
+
registerCache: <S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(cache: Cache<Item<S, L1, L2, L3, L4, L5>, S, L1, L2, L3, L4, L5>) => Promise<void>;
|
|
12
8
|
getCache: (kts: string[]) => any;
|
|
9
|
+
printRegisteredCaches: () => void;
|
|
13
10
|
}
|
package/dist/CacheRegistry.es.js
CHANGED
|
@@ -15,36 +15,48 @@ function _define_property(obj, key, value) {
|
|
|
15
15
|
}
|
|
16
16
|
const logger = LibLogger.get('CacheRegistry');
|
|
17
17
|
class CacheRegistry {
|
|
18
|
-
static getInstance() {
|
|
19
|
-
if (!CacheRegistry.instance) {
|
|
20
|
-
CacheRegistry.instance = new CacheRegistry();
|
|
21
|
-
}
|
|
22
|
-
return CacheRegistry.instance;
|
|
23
|
-
}
|
|
24
18
|
constructor(){
|
|
25
|
-
_define_property(this, "configured", false);
|
|
26
19
|
// TODO: My use of Generics has Boxed me into a corner where I can't reference AbstractCache without the types
|
|
27
20
|
_define_property(this, "cacheMap", {});
|
|
28
|
-
_define_property(this, "registerCache", (cache)=>{
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
21
|
+
_define_property(this, "registerCache", async (cache)=>{
|
|
22
|
+
try {
|
|
23
|
+
logger.debug('Attempting to register cache with pkTypes:', cache.pkTypes);
|
|
24
|
+
const key = JSON.stringify(cache.pkTypes);
|
|
25
|
+
if (this.cacheMap[key]) {
|
|
26
|
+
logger.debug(`Cache with pkTypes ${key} already exists, will be overwritten`);
|
|
27
|
+
}
|
|
28
|
+
this.cacheMap[key] = cache;
|
|
29
|
+
logger.debug('Cache registered successfully with key:', key);
|
|
30
|
+
} catch (error) {
|
|
31
|
+
logger.error('Failed to register cache:', error);
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
36
34
|
});
|
|
37
35
|
_define_property(this, "getCache", (kts)=>{
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
logger.debug('Attempting to get cache for key types:', kts);
|
|
37
|
+
const key = JSON.stringify(kts);
|
|
38
|
+
logger.debug('Looking up cache with key:', key);
|
|
39
|
+
const cache = this.cacheMap[key];
|
|
40
|
+
if (!cache) {
|
|
41
|
+
logger.warning(`No cache found for key types: ${key}`);
|
|
42
|
+
}
|
|
43
|
+
return cache;
|
|
44
|
+
});
|
|
45
|
+
_define_property(this, "printRegisteredCaches", ()=>{
|
|
46
|
+
logger.debug('Printing all registered caches:');
|
|
47
|
+
const cacheCount = Object.keys(this.cacheMap).length;
|
|
48
|
+
logger.debug(`Total number of registered caches: ${cacheCount}`);
|
|
49
|
+
if (cacheCount === 0) {
|
|
50
|
+
logger.debug('No caches are currently registered');
|
|
41
51
|
}
|
|
42
|
-
|
|
52
|
+
Object.entries(this.cacheMap).forEach(([keyTypes])=>{
|
|
53
|
+
logger.debug(`Cache with key types: ${keyTypes}`);
|
|
54
|
+
});
|
|
43
55
|
});
|
|
44
|
-
logger.debug('CacheRegistry created');
|
|
56
|
+
logger.debug('CacheRegistry instance created');
|
|
45
57
|
}
|
|
46
58
|
}
|
|
47
59
|
_define_property(CacheRegistry, "instance", void 0);
|
|
48
60
|
|
|
49
61
|
export { CacheRegistry };
|
|
50
|
-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,
|
|
62
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ2FjaGVSZWdpc3RyeS5lcy5qcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
|
package/dist/index.cjs
CHANGED
|
@@ -6,7 +6,7 @@ const Logging = require('@fjell/logging');
|
|
|
6
6
|
const core = require('@fjell/core');
|
|
7
7
|
const httpApi = require('@fjell/http-api');
|
|
8
8
|
|
|
9
|
-
const LibLogger = Logging.getLogger('@
|
|
9
|
+
const LibLogger = Logging.getLogger('@fjell/cache');
|
|
10
10
|
|
|
11
11
|
const logger$3 = LibLogger.get('ItemAggregator');
|
|
12
12
|
const toCacheConfig = (config)=>{
|
|
@@ -21,7 +21,7 @@ const toCacheConfig = (config)=>{
|
|
|
21
21
|
}
|
|
22
22
|
return cacheConfig;
|
|
23
23
|
};
|
|
24
|
-
const createAggregator = (cache, { aggregates = {}, events = {} })=>{
|
|
24
|
+
const createAggregator = async (cache, { aggregates = {}, events = {} })=>{
|
|
25
25
|
const populate = async (item)=>{
|
|
26
26
|
logger$3.default('populate', {
|
|
27
27
|
item
|
|
@@ -375,7 +375,7 @@ class CacheMap extends core.Dictionary {
|
|
|
375
375
|
}
|
|
376
376
|
|
|
377
377
|
const logger$1 = LibLogger.get('Cache');
|
|
378
|
-
const createCache = (api, pkType, parentCache)=>{
|
|
378
|
+
const createCache = async (api, pkType, parentCache)=>{
|
|
379
379
|
let pkTypes = [
|
|
380
380
|
pkType
|
|
381
381
|
];
|
|
@@ -657,33 +657,45 @@ function _define_property(obj, key, value) {
|
|
|
657
657
|
}
|
|
658
658
|
const logger = LibLogger.get('CacheRegistry');
|
|
659
659
|
class CacheRegistry {
|
|
660
|
-
static getInstance() {
|
|
661
|
-
if (!CacheRegistry.instance) {
|
|
662
|
-
CacheRegistry.instance = new CacheRegistry();
|
|
663
|
-
}
|
|
664
|
-
return CacheRegistry.instance;
|
|
665
|
-
}
|
|
666
660
|
constructor(){
|
|
667
|
-
_define_property(this, "configured", false);
|
|
668
661
|
// TODO: My use of Generics has Boxed me into a corner where I can't reference AbstractCache without the types
|
|
669
662
|
_define_property(this, "cacheMap", {});
|
|
670
|
-
_define_property(this, "registerCache", (cache)=>{
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
663
|
+
_define_property(this, "registerCache", async (cache)=>{
|
|
664
|
+
try {
|
|
665
|
+
logger.debug('Attempting to register cache with pkTypes:', cache.pkTypes);
|
|
666
|
+
const key = JSON.stringify(cache.pkTypes);
|
|
667
|
+
if (this.cacheMap[key]) {
|
|
668
|
+
logger.debug(`Cache with pkTypes ${key} already exists, will be overwritten`);
|
|
669
|
+
}
|
|
670
|
+
this.cacheMap[key] = cache;
|
|
671
|
+
logger.debug('Cache registered successfully with key:', key);
|
|
672
|
+
} catch (error) {
|
|
673
|
+
logger.error('Failed to register cache:', error);
|
|
674
|
+
throw error;
|
|
675
|
+
}
|
|
678
676
|
});
|
|
679
677
|
_define_property(this, "getCache", (kts)=>{
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
678
|
+
logger.debug('Attempting to get cache for key types:', kts);
|
|
679
|
+
const key = JSON.stringify(kts);
|
|
680
|
+
logger.debug('Looking up cache with key:', key);
|
|
681
|
+
const cache = this.cacheMap[key];
|
|
682
|
+
if (!cache) {
|
|
683
|
+
logger.warning(`No cache found for key types: ${key}`);
|
|
683
684
|
}
|
|
684
|
-
return
|
|
685
|
+
return cache;
|
|
686
|
+
});
|
|
687
|
+
_define_property(this, "printRegisteredCaches", ()=>{
|
|
688
|
+
logger.debug('Printing all registered caches:');
|
|
689
|
+
const cacheCount = Object.keys(this.cacheMap).length;
|
|
690
|
+
logger.debug(`Total number of registered caches: ${cacheCount}`);
|
|
691
|
+
if (cacheCount === 0) {
|
|
692
|
+
logger.debug('No caches are currently registered');
|
|
693
|
+
}
|
|
694
|
+
Object.entries(this.cacheMap).forEach(([keyTypes])=>{
|
|
695
|
+
logger.debug(`Cache with key types: ${keyTypes}`);
|
|
696
|
+
});
|
|
685
697
|
});
|
|
686
|
-
logger.debug('CacheRegistry created');
|
|
698
|
+
logger.debug('CacheRegistry instance created');
|
|
687
699
|
}
|
|
688
700
|
}
|
|
689
701
|
_define_property(CacheRegistry, "instance", void 0);
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/logger.cjs.js
CHANGED
|
@@ -4,7 +4,7 @@ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toString
|
|
|
4
4
|
|
|
5
5
|
const Logging = require('@fjell/logging');
|
|
6
6
|
|
|
7
|
-
const LibLogger = Logging.getLogger('@
|
|
7
|
+
const LibLogger = Logging.getLogger('@fjell/cache');
|
|
8
8
|
|
|
9
9
|
exports.default = LibLogger;
|
|
10
10
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibG9nZ2VyLmNqcy5qcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7In0=
|
package/dist/logger.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Logging from '@fjell/logging';
|
|
2
2
|
|
|
3
|
-
const LibLogger = Logging.getLogger('@
|
|
3
|
+
const LibLogger = Logging.getLogger('@fjell/cache');
|
|
4
4
|
|
|
5
5
|
export { LibLogger as default };
|
|
6
6
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibG9nZ2VyLmVzLmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7OyJ9
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fjell/cache",
|
|
3
3
|
"description": "Cache for Fjell",
|
|
4
|
-
"version": "4.6.
|
|
4
|
+
"version": "4.6.1",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.cjs.js",
|
|
@@ -55,7 +55,8 @@
|
|
|
55
55
|
"url": "git+https://github.com/getfjell/cache.git"
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|
|
58
|
-
"
|
|
58
|
+
"dev": "concurrently \"tsc --noEmit --watch\" \"vite build --watch\"",
|
|
59
|
+
"build": "pnpm run lint && tsc --noEmit && vite build",
|
|
59
60
|
"lint": "eslint . --ext .ts --fix",
|
|
60
61
|
"clean": "rimraf dist",
|
|
61
62
|
"test": "pnpm run lint && vitest run --coverage"
|
package/src/Aggregator.ts
CHANGED
|
@@ -49,7 +49,7 @@ export const toCacheConfig = <
|
|
|
49
49
|
return cacheConfig;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
export const createAggregator = <
|
|
52
|
+
export const createAggregator = async <
|
|
53
53
|
V extends Item<S, L1, L2, L3, L4, L5>,
|
|
54
54
|
S extends string,
|
|
55
55
|
L1 extends string = never,
|
|
@@ -58,13 +58,13 @@ export const createAggregator = <
|
|
|
58
58
|
L4 extends string = never,
|
|
59
59
|
L5 extends string = never
|
|
60
60
|
>(
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
cache: Cache<V, S, L1, L2, L3, L4, L5>,
|
|
62
|
+
{ aggregates = {}, events = {} }:
|
|
63
63
|
{
|
|
64
64
|
aggregates?: AggregateConfig,
|
|
65
65
|
events?: AggregateConfig
|
|
66
66
|
}
|
|
67
|
-
|
|
67
|
+
): Promise<Aggregator<V, S, L1, L2, L3, L4, L5>> => {
|
|
68
68
|
|
|
69
69
|
const populate = async (item: V): Promise<V> => {
|
|
70
70
|
logger.default('populate', { item });
|
package/src/Cache.ts
CHANGED
|
@@ -91,7 +91,7 @@ export interface Cache<
|
|
|
91
91
|
cacheMap: CacheMap<V, S, L1, L2, L3, L4, L5>;
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
export const createCache = <
|
|
94
|
+
export const createCache = async <
|
|
95
95
|
V extends Item<S, L1, L2, L3, L4, L5>,
|
|
96
96
|
S extends string,
|
|
97
97
|
L1 extends string = never,
|
|
@@ -100,10 +100,10 @@ export const createCache = <
|
|
|
100
100
|
L4 extends string = never,
|
|
101
101
|
L5 extends string = never
|
|
102
102
|
>(
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
103
|
+
api: ClientApi<V, S, L1, L2, L3, L4, L5>,
|
|
104
|
+
pkType: S,
|
|
105
|
+
parentCache?: Cache<Item<L1, L2, L3, L4, L5>, L1, L2, L3, L4, L5>
|
|
106
|
+
): Promise<Cache<V, S, L1, L2, L3, L4, L5>> => {
|
|
107
107
|
|
|
108
108
|
let pkTypes: AllItemTypeArrays<S, L1, L2, L3, L4, L5> = [ pkType ];
|
|
109
109
|
if( parentCache ) {
|
package/src/CacheRegistry.ts
CHANGED
|
@@ -7,48 +7,60 @@ const logger = LibLogger.get('CacheRegistry');
|
|
|
7
7
|
export class CacheRegistry {
|
|
8
8
|
|
|
9
9
|
private static instance: CacheRegistry;
|
|
10
|
-
private configured: boolean = false;
|
|
11
10
|
|
|
12
11
|
public constructor() {
|
|
13
|
-
logger.debug('CacheRegistry created');
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
public static getInstance(
|
|
17
|
-
): CacheRegistry {
|
|
18
|
-
if (!CacheRegistry.instance) {
|
|
19
|
-
CacheRegistry.instance = new CacheRegistry();
|
|
20
|
-
}
|
|
21
|
-
return CacheRegistry.instance;
|
|
12
|
+
logger.debug('CacheRegistry instance created');
|
|
22
13
|
}
|
|
23
14
|
|
|
24
15
|
// TODO: My use of Generics has Boxed me into a corner where I can't reference AbstractCache without the types
|
|
25
16
|
private cacheMap: { [kt: string]: any } = {};
|
|
26
17
|
|
|
27
|
-
public registerCache = <
|
|
18
|
+
public registerCache = async <
|
|
28
19
|
S extends string,
|
|
29
20
|
L1 extends string = never,
|
|
30
21
|
L2 extends string = never,
|
|
31
22
|
L3 extends string = never,
|
|
32
23
|
L4 extends string = never,
|
|
33
24
|
L5 extends string = never
|
|
34
|
-
>(cache: Cache<Item<S, L1, L2, L3, L4, L5>, S, L1, L2, L3, L4, L5>): void => {
|
|
35
|
-
|
|
25
|
+
>(cache: Cache<Item<S, L1, L2, L3, L4, L5>, S, L1, L2, L3, L4, L5>): Promise<void> => {
|
|
26
|
+
try {
|
|
27
|
+
logger.debug('Attempting to register cache with pkTypes:', cache.pkTypes);
|
|
28
|
+
const key = JSON.stringify(cache.pkTypes);
|
|
29
|
+
if (this.cacheMap[key]) {
|
|
30
|
+
logger.debug(`Cache with pkTypes ${key} already exists, will be overwritten`);
|
|
31
|
+
}
|
|
32
|
+
this.cacheMap[key] = cache;
|
|
33
|
+
logger.debug('Cache registered successfully with key:', key);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
logger.error('Failed to register cache:', error);
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
36
38
|
};
|
|
37
39
|
|
|
38
|
-
public isConfigured = (): boolean => {
|
|
39
|
-
return this.configured;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
public markConfigured = (): void => {
|
|
43
|
-
this.configured = true;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
40
|
public getCache = (kts: string[]): any => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
41
|
+
logger.debug('Attempting to get cache for key types:', kts);
|
|
42
|
+
|
|
43
|
+
const key = JSON.stringify(kts);
|
|
44
|
+
logger.debug('Looking up cache with key:', key);
|
|
45
|
+
|
|
46
|
+
const cache = this.cacheMap[key];
|
|
47
|
+
if (!cache) {
|
|
48
|
+
logger.warning(`No cache found for key types: ${key}`);
|
|
50
49
|
}
|
|
51
|
-
return
|
|
50
|
+
return cache;
|
|
52
51
|
};
|
|
53
52
|
|
|
53
|
+
public printRegisteredCaches = (): void => {
|
|
54
|
+
logger.debug('Printing all registered caches:');
|
|
55
|
+
const cacheCount = Object.keys(this.cacheMap).length;
|
|
56
|
+
logger.debug(`Total number of registered caches: ${cacheCount}`);
|
|
57
|
+
|
|
58
|
+
if (cacheCount === 0) {
|
|
59
|
+
logger.debug('No caches are currently registered');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
Object.entries(this.cacheMap).forEach(([keyTypes]) => {
|
|
63
|
+
logger.debug(`Cache with key types: ${keyTypes}`);
|
|
64
|
+
});
|
|
65
|
+
};
|
|
54
66
|
}
|
package/src/logger.ts
CHANGED
package/vitest.config.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { defineConfig } from 'vitest/config'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
test: {
|
|
6
|
+
globals: true,
|
|
7
|
+
environment: 'node',
|
|
8
|
+
include: ['tests/**/*.test.ts'],
|
|
9
|
+
coverage: {
|
|
10
|
+
provider: 'v8',
|
|
11
|
+
reporter: ['text', 'json', 'html'],
|
|
12
|
+
exclude: [
|
|
13
|
+
'node_modules/',
|
|
14
|
+
'tests/',
|
|
15
|
+
'src/index.ts',
|
|
16
|
+
],
|
|
17
|
+
},
|
|
18
|
+
setupFiles: ['./tests/setup.ts'],
|
|
19
|
+
deps: {
|
|
20
|
+
inline: [/@fjell/],
|
|
21
|
+
},
|
|
22
|
+
testTimeout: 10000,
|
|
23
|
+
hookTimeout: 10000,
|
|
24
|
+
teardownTimeout: 10000,
|
|
25
|
+
},
|
|
26
|
+
resolve: {
|
|
27
|
+
alias: {
|
|
28
|
+
'@': path.resolve(__dirname, './src'),
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
build: {
|
|
32
|
+
sourcemap: true,
|
|
33
|
+
},
|
|
34
|
+
})
|
package/eslint.config.mjs
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import typescriptEslint from "@typescript-eslint/eslint-plugin";
|
|
2
|
-
import tsParser from "@typescript-eslint/parser";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { fileURLToPath } from "node:url";
|
|
5
|
-
import js from "@eslint/js";
|
|
6
|
-
import { FlatCompat } from "@eslint/eslintrc";
|
|
7
|
-
|
|
8
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
-
const __dirname = path.dirname(__filename);
|
|
10
|
-
const compat = new FlatCompat({
|
|
11
|
-
baseDirectory: __dirname,
|
|
12
|
-
recommendedConfig: js.configs.recommended,
|
|
13
|
-
allConfig: js.configs.all
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
export default [{
|
|
17
|
-
ignores: ["**/dist", "**/node_modules"],
|
|
18
|
-
}, ...compat.extends("plugin:@typescript-eslint/recommended"), {
|
|
19
|
-
plugins: {
|
|
20
|
-
"@typescript-eslint": typescriptEslint,
|
|
21
|
-
},
|
|
22
|
-
|
|
23
|
-
languageOptions: {
|
|
24
|
-
parser: tsParser,
|
|
25
|
-
},
|
|
26
|
-
|
|
27
|
-
rules: {
|
|
28
|
-
"@typescript-eslint/no-unused-expressions": "off",
|
|
29
|
-
"no-console": 0,
|
|
30
|
-
"no-unused-vars": "off",
|
|
31
|
-
|
|
32
|
-
"max-len": ["error", {
|
|
33
|
-
code: 120,
|
|
34
|
-
}],
|
|
35
|
-
|
|
36
|
-
"max-depth": ["error", 4],
|
|
37
|
-
"max-params": ["error", 4],
|
|
38
|
-
"max-lines": ["error", 500],
|
|
39
|
-
|
|
40
|
-
"no-multiple-empty-lines": ["error", {
|
|
41
|
-
max: 1,
|
|
42
|
-
maxEOF: 1,
|
|
43
|
-
}],
|
|
44
|
-
|
|
45
|
-
"no-trailing-spaces": ["error", {
|
|
46
|
-
skipBlankLines: true,
|
|
47
|
-
}],
|
|
48
|
-
|
|
49
|
-
indent: ["error", 2, {
|
|
50
|
-
SwitchCase: 1,
|
|
51
|
-
}],
|
|
52
|
-
|
|
53
|
-
"sort-imports": ["error", {
|
|
54
|
-
ignoreCase: true,
|
|
55
|
-
ignoreDeclarationSort: true,
|
|
56
|
-
ignoreMemberSort: false,
|
|
57
|
-
memberSyntaxSortOrder: ["none", "all", "multiple", "single"],
|
|
58
|
-
}],
|
|
59
|
-
|
|
60
|
-
"no-var": "error",
|
|
61
|
-
"no-undefined": "error",
|
|
62
|
-
"@typescript-eslint/no-unused-vars": "error",
|
|
63
|
-
"@typescript-eslint/ban-ts-comment": "off",
|
|
64
|
-
"@typescript-eslint/no-explicit-any": "off",
|
|
65
|
-
|
|
66
|
-
"no-restricted-imports": ["error", {
|
|
67
|
-
patterns: ["..*", "src/*"],
|
|
68
|
-
}],
|
|
69
|
-
},
|
|
70
|
-
}];
|
package/vite.config.ts
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
// import { defineConfig } from 'vite';
|
|
2
|
-
import { defineConfig as defineVitestConfig } from 'vitest/config';
|
|
3
|
-
import { VitePluginNode } from 'vite-plugin-node';
|
|
4
|
-
import dts from 'vite-plugin-dts';
|
|
5
|
-
import path from 'path';
|
|
6
|
-
|
|
7
|
-
export default defineVitestConfig({
|
|
8
|
-
server: {
|
|
9
|
-
port: 3000
|
|
10
|
-
},
|
|
11
|
-
plugins: [
|
|
12
|
-
...VitePluginNode({
|
|
13
|
-
adapter: 'express',
|
|
14
|
-
appPath: './src/index.ts',
|
|
15
|
-
exportName: 'viteNodeApp',
|
|
16
|
-
tsCompiler: 'swc',
|
|
17
|
-
}),
|
|
18
|
-
// visualizer({
|
|
19
|
-
// template: 'network',
|
|
20
|
-
// filename: 'network.html',
|
|
21
|
-
// projectRoot: process.cwd(),
|
|
22
|
-
// }),
|
|
23
|
-
dts({
|
|
24
|
-
entryRoot: 'src',
|
|
25
|
-
outDir: 'dist',
|
|
26
|
-
exclude: ['./tests/**/*.ts'],
|
|
27
|
-
include: ['./src/**/*.ts'],
|
|
28
|
-
}),
|
|
29
|
-
],
|
|
30
|
-
resolve: {
|
|
31
|
-
alias: {
|
|
32
|
-
'@': path.resolve(__dirname, './src'),
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
build: {
|
|
36
|
-
target: 'esnext',
|
|
37
|
-
outDir: 'dist',
|
|
38
|
-
lib: {
|
|
39
|
-
entry: './src/index.ts',
|
|
40
|
-
formats: ['es', 'cjs'],
|
|
41
|
-
},
|
|
42
|
-
rollupOptions: {
|
|
43
|
-
input: 'src/index.ts',
|
|
44
|
-
output: [
|
|
45
|
-
{
|
|
46
|
-
format: 'esm',
|
|
47
|
-
entryFileNames: '[name].es.js',
|
|
48
|
-
preserveModules: true,
|
|
49
|
-
exports: 'named',
|
|
50
|
-
sourcemap: 'inline',
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
format: 'cjs',
|
|
54
|
-
entryFileNames: '[name].cjs.js',
|
|
55
|
-
preserveModules: true,
|
|
56
|
-
exports: 'named',
|
|
57
|
-
sourcemap: 'inline',
|
|
58
|
-
},
|
|
59
|
-
],
|
|
60
|
-
},
|
|
61
|
-
// Make sure Vite generates ESM-compatible code
|
|
62
|
-
modulePreload: false,
|
|
63
|
-
minify: false,
|
|
64
|
-
sourcemap: true
|
|
65
|
-
},
|
|
66
|
-
test: {
|
|
67
|
-
include: [
|
|
68
|
-
'tests/**/*.test.ts',
|
|
69
|
-
'tests/**/*.spec.ts',
|
|
70
|
-
],
|
|
71
|
-
coverage: {
|
|
72
|
-
provider: 'v8',
|
|
73
|
-
reporter: ['text', 'html', 'lcov'],
|
|
74
|
-
reportsDirectory: './coverage',
|
|
75
|
-
exclude: [
|
|
76
|
-
'node_modules/',
|
|
77
|
-
'tests/',
|
|
78
|
-
'src/index.ts',
|
|
79
|
-
],
|
|
80
|
-
thresholds: {
|
|
81
|
-
global: {
|
|
82
|
-
branches: 75,
|
|
83
|
-
functions: 89,
|
|
84
|
-
lines: 89,
|
|
85
|
-
statements: 89,
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
|
-
},
|
|
89
|
-
environment: 'node',
|
|
90
|
-
},
|
|
91
|
-
});
|