@fjell/cache 4.5.2 → 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 +276 -0
- package/dist/{src/Aggregator.d.ts → Aggregator.d.ts} +3 -3
- package/dist/Aggregator.es.js +271 -0
- package/dist/Cache.cjs.js +279 -0
- package/dist/{src/Cache.d.ts → Cache.d.ts} +4 -4
- package/dist/{src/Cache.js → Cache.es.js} +129 -77
- package/dist/CacheMap.cjs.js +108 -0
- package/dist/{src/CacheMap.d.ts → CacheMap.d.ts} +1 -1
- package/dist/{src/CacheMap.js → CacheMap.es.js} +42 -23
- package/dist/CacheRegistry.cjs.js +66 -0
- package/dist/{src/CacheRegistry.d.ts → CacheRegistry.d.ts} +4 -7
- package/dist/CacheRegistry.es.js +62 -0
- package/dist/index.cjs +708 -0
- package/dist/index.cjs.js +17 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.es.js +5 -0
- package/dist/logger.cjs.js +10 -0
- package/dist/logger.d.ts +2 -0
- package/dist/logger.es.js +6 -0
- package/package.json +31 -18
- package/src/Aggregator.ts +12 -4
- package/src/Cache.ts +5 -5
- package/src/CacheRegistry.ts +37 -25
- package/src/index.ts +4 -0
- package/src/logger.ts +1 -1
- package/vitest.config.ts +34 -0
- package/dist/src/Aggregator.js +0 -182
- package/dist/src/Aggregator.js.map +0 -1
- package/dist/src/Cache.js.map +0 -1
- package/dist/src/CacheMap.js.map +0 -1
- package/dist/src/CacheRegistry.js +0 -34
- package/dist/src/CacheRegistry.js.map +0 -1
- package/dist/src/logger.d.ts +0 -2
- package/dist/src/logger.js +0 -4
- package/dist/src/logger.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/eslint.config.mjs +0 -70
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
|
|
5
|
+
const core = require('@fjell/core');
|
|
6
|
+
const logger$1 = require('./logger.cjs.js');
|
|
7
|
+
|
|
8
|
+
function _define_property(obj, key, value) {
|
|
9
|
+
if (key in obj) {
|
|
10
|
+
Object.defineProperty(obj, key, {
|
|
11
|
+
value: value,
|
|
12
|
+
enumerable: true,
|
|
13
|
+
configurable: true,
|
|
14
|
+
writable: true
|
|
15
|
+
});
|
|
16
|
+
} else {
|
|
17
|
+
obj[key] = value;
|
|
18
|
+
}
|
|
19
|
+
return obj;
|
|
20
|
+
}
|
|
21
|
+
const logger = logger$1.default.get("CacheMap");
|
|
22
|
+
// const isObj = (x: any) => typeof x === "object" && x !== null;
|
|
23
|
+
// const intersection = (a: object, b: object): object => {
|
|
24
|
+
// const result: { [key: string]: any } = {}
|
|
25
|
+
// if (([a, b]).every(isObj)) {
|
|
26
|
+
// Object.keys(a).forEach((key) => {
|
|
27
|
+
// // @ts-ignore
|
|
28
|
+
// const value = a[key]
|
|
29
|
+
// // @ts-ignore
|
|
30
|
+
// const other = b[key]
|
|
31
|
+
// if (isObj(value)) {
|
|
32
|
+
// result[key] = intersection(value, other)
|
|
33
|
+
// } else if (value === other) {
|
|
34
|
+
// result[key] = value
|
|
35
|
+
// }
|
|
36
|
+
// })
|
|
37
|
+
// }
|
|
38
|
+
// return result
|
|
39
|
+
// }
|
|
40
|
+
// const removeEmptyObjects = (obj: object): object => {
|
|
41
|
+
// const result: { [key: string]: any } = {}
|
|
42
|
+
// Object.keys(obj).forEach((key) => {
|
|
43
|
+
// // @ts-ignore
|
|
44
|
+
// const value = obj[key];
|
|
45
|
+
// if (isObj(value)) {
|
|
46
|
+
// const nested = removeEmptyObjects(value);
|
|
47
|
+
// if (Object.keys(nested).length > 0) {
|
|
48
|
+
// result[key] = nested
|
|
49
|
+
// }
|
|
50
|
+
// } else if (value !== null) {
|
|
51
|
+
// result[key] = value
|
|
52
|
+
// }
|
|
53
|
+
// });
|
|
54
|
+
// return result;
|
|
55
|
+
// }
|
|
56
|
+
class CacheMap extends core.Dictionary {
|
|
57
|
+
get(key) {
|
|
58
|
+
return super.get(key);
|
|
59
|
+
}
|
|
60
|
+
allIn(locations) {
|
|
61
|
+
if (locations.length === 0) {
|
|
62
|
+
logger.debug('Returning all items, LocKeys is empty');
|
|
63
|
+
return this.values();
|
|
64
|
+
} else {
|
|
65
|
+
const locKeys = locations;
|
|
66
|
+
logger.debug('allIn', {
|
|
67
|
+
locKeys,
|
|
68
|
+
keys: this.keys().length
|
|
69
|
+
});
|
|
70
|
+
return this.keys().filter((key)=>key && core.isComKey(key)).filter((key)=>{
|
|
71
|
+
const ComKey = key;
|
|
72
|
+
logger.debug('Comparing Location Keys', {
|
|
73
|
+
locKeys,
|
|
74
|
+
ComKey
|
|
75
|
+
});
|
|
76
|
+
return JSON.stringify(locKeys) === JSON.stringify(ComKey.loc);
|
|
77
|
+
}).map((key)=>this.get(key));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// TODO: Can we do case insensitive matching?
|
|
81
|
+
contains(query, locations) {
|
|
82
|
+
logger.debug('contains', {
|
|
83
|
+
query,
|
|
84
|
+
locations
|
|
85
|
+
});
|
|
86
|
+
const items = this.allIn(locations);
|
|
87
|
+
return items.some((item)=>core.isQueryMatch(item, query));
|
|
88
|
+
}
|
|
89
|
+
queryIn(query, locations = []) {
|
|
90
|
+
logger.debug('queryIn', {
|
|
91
|
+
query,
|
|
92
|
+
locations
|
|
93
|
+
});
|
|
94
|
+
const items = this.allIn(locations);
|
|
95
|
+
return items.filter((item)=>core.isQueryMatch(item, query));
|
|
96
|
+
}
|
|
97
|
+
clone() {
|
|
98
|
+
const clone = new CacheMap(this.types, this.map);
|
|
99
|
+
return clone;
|
|
100
|
+
}
|
|
101
|
+
constructor(types, map){
|
|
102
|
+
super(map), _define_property(this, "types", void 0);
|
|
103
|
+
this.types = types;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
exports.CacheMap = CacheMap;
|
|
108
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ2FjaGVNYXAuY2pzLmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AllItemTypeArrays, ComKey, Dictionary, Item, ItemQuery, LocKeyArray, PriKey } from
|
|
1
|
+
import { AllItemTypeArrays, ComKey, Dictionary, Item, ItemQuery, LocKeyArray, PriKey } from '@fjell/core';
|
|
2
2
|
export declare class CacheMap<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> extends Dictionary<ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>, V> {
|
|
3
3
|
private types;
|
|
4
4
|
constructor(types: AllItemTypeArrays<S, L1, L2, L3, L4, L5>, map?: {
|
|
@@ -1,5 +1,19 @@
|
|
|
1
|
-
import { Dictionary, isComKey, isQueryMatch } from
|
|
2
|
-
import LibLogger from
|
|
1
|
+
import { Dictionary, isComKey, isQueryMatch } from '@fjell/core';
|
|
2
|
+
import LibLogger from './logger.es.js';
|
|
3
|
+
|
|
4
|
+
function _define_property(obj, key, value) {
|
|
5
|
+
if (key in obj) {
|
|
6
|
+
Object.defineProperty(obj, key, {
|
|
7
|
+
value: value,
|
|
8
|
+
enumerable: true,
|
|
9
|
+
configurable: true,
|
|
10
|
+
writable: true
|
|
11
|
+
});
|
|
12
|
+
} else {
|
|
13
|
+
obj[key] = value;
|
|
14
|
+
}
|
|
15
|
+
return obj;
|
|
16
|
+
}
|
|
3
17
|
const logger = LibLogger.get("CacheMap");
|
|
4
18
|
// const isObj = (x: any) => typeof x === "object" && x !== null;
|
|
5
19
|
// const intersection = (a: object, b: object): object => {
|
|
@@ -35,12 +49,7 @@ const logger = LibLogger.get("CacheMap");
|
|
|
35
49
|
// });
|
|
36
50
|
// return result;
|
|
37
51
|
// }
|
|
38
|
-
|
|
39
|
-
types;
|
|
40
|
-
constructor(types, map) {
|
|
41
|
-
super(map);
|
|
42
|
-
this.types = types;
|
|
43
|
-
}
|
|
52
|
+
class CacheMap extends Dictionary {
|
|
44
53
|
get(key) {
|
|
45
54
|
return super.get(key);
|
|
46
55
|
}
|
|
@@ -48,38 +57,48 @@ export class CacheMap extends Dictionary {
|
|
|
48
57
|
if (locations.length === 0) {
|
|
49
58
|
logger.debug('Returning all items, LocKeys is empty');
|
|
50
59
|
return this.values();
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
60
|
+
} else {
|
|
53
61
|
const locKeys = locations;
|
|
54
|
-
logger.debug('allIn', {
|
|
55
|
-
|
|
56
|
-
.
|
|
57
|
-
|
|
62
|
+
logger.debug('allIn', {
|
|
63
|
+
locKeys,
|
|
64
|
+
keys: this.keys().length
|
|
65
|
+
});
|
|
66
|
+
return this.keys().filter((key)=>key && isComKey(key)).filter((key)=>{
|
|
58
67
|
const ComKey = key;
|
|
59
68
|
logger.debug('Comparing Location Keys', {
|
|
60
69
|
locKeys,
|
|
61
|
-
ComKey
|
|
70
|
+
ComKey
|
|
62
71
|
});
|
|
63
72
|
return JSON.stringify(locKeys) === JSON.stringify(ComKey.loc);
|
|
64
|
-
})
|
|
65
|
-
.map((key) => this.get(key));
|
|
73
|
+
}).map((key)=>this.get(key));
|
|
66
74
|
}
|
|
67
75
|
}
|
|
68
76
|
// TODO: Can we do case insensitive matching?
|
|
69
77
|
contains(query, locations) {
|
|
70
|
-
logger.debug('contains', {
|
|
78
|
+
logger.debug('contains', {
|
|
79
|
+
query,
|
|
80
|
+
locations
|
|
81
|
+
});
|
|
71
82
|
const items = this.allIn(locations);
|
|
72
|
-
return items.some((item)
|
|
83
|
+
return items.some((item)=>isQueryMatch(item, query));
|
|
73
84
|
}
|
|
74
85
|
queryIn(query, locations = []) {
|
|
75
|
-
logger.debug('queryIn', {
|
|
86
|
+
logger.debug('queryIn', {
|
|
87
|
+
query,
|
|
88
|
+
locations
|
|
89
|
+
});
|
|
76
90
|
const items = this.allIn(locations);
|
|
77
|
-
return items.filter((item)
|
|
91
|
+
return items.filter((item)=>isQueryMatch(item, query));
|
|
78
92
|
}
|
|
79
93
|
clone() {
|
|
80
94
|
const clone = new CacheMap(this.types, this.map);
|
|
81
95
|
return clone;
|
|
82
96
|
}
|
|
97
|
+
constructor(types, map){
|
|
98
|
+
super(map), _define_property(this, "types", void 0);
|
|
99
|
+
this.types = types;
|
|
100
|
+
}
|
|
83
101
|
}
|
|
84
|
-
|
|
85
|
-
|
|
102
|
+
|
|
103
|
+
export { CacheMap };
|
|
104
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ2FjaGVNYXAuZXMuanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
|
|
5
|
+
const logger$1 = require('./logger.cjs.js');
|
|
6
|
+
|
|
7
|
+
function _define_property(obj, key, value) {
|
|
8
|
+
if (key in obj) {
|
|
9
|
+
Object.defineProperty(obj, key, {
|
|
10
|
+
value: value,
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
writable: true
|
|
14
|
+
});
|
|
15
|
+
} else {
|
|
16
|
+
obj[key] = value;
|
|
17
|
+
}
|
|
18
|
+
return obj;
|
|
19
|
+
}
|
|
20
|
+
const logger = logger$1.default.get('CacheRegistry');
|
|
21
|
+
class CacheRegistry {
|
|
22
|
+
constructor(){
|
|
23
|
+
// TODO: My use of Generics has Boxed me into a corner where I can't reference AbstractCache without the types
|
|
24
|
+
_define_property(this, "cacheMap", {});
|
|
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
|
+
}
|
|
38
|
+
});
|
|
39
|
+
_define_property(this, "getCache", (kts)=>{
|
|
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');
|
|
55
|
+
}
|
|
56
|
+
Object.entries(this.cacheMap).forEach(([keyTypes])=>{
|
|
57
|
+
logger.debug(`Cache with key types: ${keyTypes}`);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
logger.debug('CacheRegistry instance created');
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
_define_property(CacheRegistry, "instance", void 0);
|
|
64
|
+
|
|
65
|
+
exports.CacheRegistry = CacheRegistry;
|
|
66
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ2FjaGVSZWdpc3RyeS5janMuanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0=
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import { Item } from
|
|
2
|
-
import { Cache } from
|
|
1
|
+
import { Item } from '@fjell/core';
|
|
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
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import LibLogger from './logger.es.js';
|
|
2
|
+
|
|
3
|
+
function _define_property(obj, key, value) {
|
|
4
|
+
if (key in obj) {
|
|
5
|
+
Object.defineProperty(obj, key, {
|
|
6
|
+
value: value,
|
|
7
|
+
enumerable: true,
|
|
8
|
+
configurable: true,
|
|
9
|
+
writable: true
|
|
10
|
+
});
|
|
11
|
+
} else {
|
|
12
|
+
obj[key] = value;
|
|
13
|
+
}
|
|
14
|
+
return obj;
|
|
15
|
+
}
|
|
16
|
+
const logger = LibLogger.get('CacheRegistry');
|
|
17
|
+
class CacheRegistry {
|
|
18
|
+
constructor(){
|
|
19
|
+
// TODO: My use of Generics has Boxed me into a corner where I can't reference AbstractCache without the types
|
|
20
|
+
_define_property(this, "cacheMap", {});
|
|
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
|
+
}
|
|
34
|
+
});
|
|
35
|
+
_define_property(this, "getCache", (kts)=>{
|
|
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');
|
|
51
|
+
}
|
|
52
|
+
Object.entries(this.cacheMap).forEach(([keyTypes])=>{
|
|
53
|
+
logger.debug(`Cache with key types: ${keyTypes}`);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
logger.debug('CacheRegistry instance created');
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
_define_property(CacheRegistry, "instance", void 0);
|
|
60
|
+
|
|
61
|
+
export { CacheRegistry };
|
|
62
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ2FjaGVSZWdpc3RyeS5lcy5qcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
|