@fjell/cache 4.6.5 → 4.6.10
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/Cache.cjs.js +41 -2
- package/dist/Cache.es.js +41 -2
- package/dist/CacheMap.cjs.js +65 -3
- package/dist/CacheMap.es.js +65 -3
- package/dist/Instance.cjs.js +27 -0
- package/dist/Instance.d.ts +20 -0
- package/dist/Instance.es.js +22 -0
- package/dist/InstanceFactory.cjs.js +23 -0
- package/dist/InstanceFactory.d.ts +8 -0
- package/dist/InstanceFactory.es.js +19 -0
- package/dist/Registry.cjs.js +36 -0
- package/dist/Registry.d.ts +15 -0
- package/dist/Registry.es.js +31 -0
- package/dist/index.cjs +224 -119
- package/dist/index.cjs.js +9 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.es.js +4 -2
- package/examples/README.md +307 -0
- package/examples/aggregator-example.ts +334 -0
- package/examples/basic-cache-example.ts +273 -0
- package/examples/cache-map-example.ts +265 -0
- package/package.json +13 -12
- package/vitest.config.ts +2 -2
- package/dist/CacheRegistry.cjs.js +0 -66
- package/dist/CacheRegistry.d.ts +0 -10
- package/dist/CacheRegistry.es.js +0 -62
package/dist/Cache.cjs.js
CHANGED
|
@@ -8,6 +8,45 @@ 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
|
+
// Normalize a key value to string for consistent comparison
|
|
12
|
+
const normalizeKeyValue = (value)=>{
|
|
13
|
+
return String(value);
|
|
14
|
+
};
|
|
15
|
+
// Normalized key comparison function that handles string/number differences
|
|
16
|
+
const isItemKeyEqualNormalized = (a, b)=>{
|
|
17
|
+
// For now, just normalize the keys to strings and use the original comparison
|
|
18
|
+
const normalizedA = normalizeKey(a);
|
|
19
|
+
const normalizedB = normalizeKey(b);
|
|
20
|
+
return core.isItemKeyEqual(normalizedA, normalizedB);
|
|
21
|
+
};
|
|
22
|
+
// Helper function to normalize a key
|
|
23
|
+
const normalizeKey = (key)=>{
|
|
24
|
+
if (typeof key === 'object' && key !== null) {
|
|
25
|
+
const normalizedKey = JSON.parse(JSON.stringify(key));
|
|
26
|
+
// Normalize pk values
|
|
27
|
+
if ('pk' in normalizedKey && normalizedKey.pk !== null) {
|
|
28
|
+
normalizedKey.pk = normalizeKeyValue(normalizedKey.pk);
|
|
29
|
+
}
|
|
30
|
+
// Normalize lk values
|
|
31
|
+
if ('lk' in normalizedKey && normalizedKey.lk !== null) {
|
|
32
|
+
normalizedKey.lk = normalizeKeyValue(normalizedKey.lk);
|
|
33
|
+
}
|
|
34
|
+
// Normalize loc array lk values
|
|
35
|
+
if ('loc' in normalizedKey && Array.isArray(normalizedKey.loc)) {
|
|
36
|
+
normalizedKey.loc = normalizedKey.loc.map((locItem)=>{
|
|
37
|
+
if (locItem && 'lk' in locItem && locItem.lk !== null) {
|
|
38
|
+
return {
|
|
39
|
+
...locItem,
|
|
40
|
+
lk: normalizeKeyValue(locItem.lk)
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
return locItem;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return normalizedKey;
|
|
47
|
+
}
|
|
48
|
+
return key;
|
|
49
|
+
};
|
|
11
50
|
const createCache = async (api, pkType, parentCache)=>{
|
|
12
51
|
let pkTypes = [
|
|
13
52
|
pkType
|
|
@@ -284,7 +323,7 @@ const createCache = async (api, pkType, parentCache)=>{
|
|
|
284
323
|
}
|
|
285
324
|
// TODO: This could be merged with the isValidItemKey check, later.
|
|
286
325
|
core.validatePK(v, pkType);
|
|
287
|
-
if (!
|
|
326
|
+
if (!isItemKeyEqualNormalized(key, v.key)) {
|
|
288
327
|
logger.error('Key does not match item key: %j != %j', key, v.key);
|
|
289
328
|
throw new Error('Key does not match item key');
|
|
290
329
|
}
|
|
@@ -316,4 +355,4 @@ const createCache = async (api, pkType, parentCache)=>{
|
|
|
316
355
|
};
|
|
317
356
|
|
|
318
357
|
exports.createCache = createCache;
|
|
319
|
-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,
|
|
358
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ2FjaGUuY2pzLmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
|
package/dist/Cache.es.js
CHANGED
|
@@ -4,6 +4,45 @@ import LibLogger from './logger.es.js';
|
|
|
4
4
|
import { NotFoundError } from '@fjell/http-api';
|
|
5
5
|
|
|
6
6
|
const logger = LibLogger.get('Cache');
|
|
7
|
+
// Normalize a key value to string for consistent comparison
|
|
8
|
+
const normalizeKeyValue = (value)=>{
|
|
9
|
+
return String(value);
|
|
10
|
+
};
|
|
11
|
+
// Normalized key comparison function that handles string/number differences
|
|
12
|
+
const isItemKeyEqualNormalized = (a, b)=>{
|
|
13
|
+
// For now, just normalize the keys to strings and use the original comparison
|
|
14
|
+
const normalizedA = normalizeKey(a);
|
|
15
|
+
const normalizedB = normalizeKey(b);
|
|
16
|
+
return isItemKeyEqual(normalizedA, normalizedB);
|
|
17
|
+
};
|
|
18
|
+
// Helper function to normalize a key
|
|
19
|
+
const normalizeKey = (key)=>{
|
|
20
|
+
if (typeof key === 'object' && key !== null) {
|
|
21
|
+
const normalizedKey = JSON.parse(JSON.stringify(key));
|
|
22
|
+
// Normalize pk values
|
|
23
|
+
if ('pk' in normalizedKey && normalizedKey.pk !== null) {
|
|
24
|
+
normalizedKey.pk = normalizeKeyValue(normalizedKey.pk);
|
|
25
|
+
}
|
|
26
|
+
// Normalize lk values
|
|
27
|
+
if ('lk' in normalizedKey && normalizedKey.lk !== null) {
|
|
28
|
+
normalizedKey.lk = normalizeKeyValue(normalizedKey.lk);
|
|
29
|
+
}
|
|
30
|
+
// Normalize loc array lk values
|
|
31
|
+
if ('loc' in normalizedKey && Array.isArray(normalizedKey.loc)) {
|
|
32
|
+
normalizedKey.loc = normalizedKey.loc.map((locItem)=>{
|
|
33
|
+
if (locItem && 'lk' in locItem && locItem.lk !== null) {
|
|
34
|
+
return {
|
|
35
|
+
...locItem,
|
|
36
|
+
lk: normalizeKeyValue(locItem.lk)
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return locItem;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return normalizedKey;
|
|
43
|
+
}
|
|
44
|
+
return key;
|
|
45
|
+
};
|
|
7
46
|
const createCache = async (api, pkType, parentCache)=>{
|
|
8
47
|
let pkTypes = [
|
|
9
48
|
pkType
|
|
@@ -280,7 +319,7 @@ const createCache = async (api, pkType, parentCache)=>{
|
|
|
280
319
|
}
|
|
281
320
|
// TODO: This could be merged with the isValidItemKey check, later.
|
|
282
321
|
validatePK(v, pkType);
|
|
283
|
-
if (!
|
|
322
|
+
if (!isItemKeyEqualNormalized(key, v.key)) {
|
|
284
323
|
logger.error('Key does not match item key: %j != %j', key, v.key);
|
|
285
324
|
throw new Error('Key does not match item key');
|
|
286
325
|
}
|
|
@@ -312,4 +351,4 @@ const createCache = async (api, pkType, parentCache)=>{
|
|
|
312
351
|
};
|
|
313
352
|
|
|
314
353
|
export { createCache };
|
|
315
|
-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,
|
|
354
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ2FjaGUuZXMuanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0=
|
package/dist/CacheMap.cjs.js
CHANGED
|
@@ -19,6 +19,68 @@ function _define_property(obj, key, value) {
|
|
|
19
19
|
return obj;
|
|
20
20
|
}
|
|
21
21
|
const logger = logger$1.default.get("CacheMap");
|
|
22
|
+
// Normalize a key value to string for consistent comparison and hashing
|
|
23
|
+
const normalizeKeyValue = (value)=>{
|
|
24
|
+
return String(value);
|
|
25
|
+
};
|
|
26
|
+
// Normalized hash function for Dictionary that converts pk/lk values to strings
|
|
27
|
+
const createNormalizedHashFunction = ()=>{
|
|
28
|
+
return (key)=>{
|
|
29
|
+
if (typeof key === 'object' && key !== null) {
|
|
30
|
+
// Create a normalized version of the key with string values
|
|
31
|
+
const normalizedKey = JSON.parse(JSON.stringify(key));
|
|
32
|
+
// Normalize pk values
|
|
33
|
+
if ('pk' in normalizedKey && normalizedKey.pk !== null) {
|
|
34
|
+
normalizedKey.pk = normalizeKeyValue(normalizedKey.pk);
|
|
35
|
+
}
|
|
36
|
+
// Normalize lk values
|
|
37
|
+
if ('lk' in normalizedKey && normalizedKey.lk !== null) {
|
|
38
|
+
normalizedKey.lk = normalizeKeyValue(normalizedKey.lk);
|
|
39
|
+
}
|
|
40
|
+
// Normalize loc array lk values
|
|
41
|
+
if ('loc' in normalizedKey && Array.isArray(normalizedKey.loc)) {
|
|
42
|
+
normalizedKey.loc = normalizedKey.loc.map((locItem)=>{
|
|
43
|
+
if (locItem && 'lk' in locItem && locItem.lk !== null) {
|
|
44
|
+
return {
|
|
45
|
+
...locItem,
|
|
46
|
+
lk: normalizeKeyValue(locItem.lk)
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return locItem;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return JSON.stringify(normalizedKey);
|
|
53
|
+
}
|
|
54
|
+
return JSON.stringify(key);
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
// Helper function to normalize and compare location key arrays
|
|
58
|
+
const isLocKeyArrayEqual = (a, b)=>{
|
|
59
|
+
if (a.length !== b.length) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
for(let i = 0; i < a.length; i++){
|
|
63
|
+
const normalizedA = normalizeLocKeyItem(a[i]);
|
|
64
|
+
const normalizedB = normalizeLocKeyItem(b[i]);
|
|
65
|
+
if (JSON.stringify(normalizedA) !== JSON.stringify(normalizedB)) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return true;
|
|
70
|
+
};
|
|
71
|
+
// Helper function to normalize a location key item
|
|
72
|
+
const normalizeLocKeyItem = (item)=>{
|
|
73
|
+
if (typeof item === 'object' && item !== null) {
|
|
74
|
+
const normalized = {
|
|
75
|
+
...item
|
|
76
|
+
};
|
|
77
|
+
if ('lk' in normalized && normalized.lk !== null) {
|
|
78
|
+
normalized.lk = normalizeKeyValue(normalized.lk);
|
|
79
|
+
}
|
|
80
|
+
return normalized;
|
|
81
|
+
}
|
|
82
|
+
return item;
|
|
83
|
+
};
|
|
22
84
|
// const isObj = (x: any) => typeof x === "object" && x !== null;
|
|
23
85
|
// const intersection = (a: object, b: object): object => {
|
|
24
86
|
// const result: { [key: string]: any } = {}
|
|
@@ -73,7 +135,7 @@ class CacheMap extends core.Dictionary {
|
|
|
73
135
|
locKeys,
|
|
74
136
|
ComKey
|
|
75
137
|
});
|
|
76
|
-
return
|
|
138
|
+
return isLocKeyArrayEqual(locKeys, ComKey.loc);
|
|
77
139
|
}).map((key)=>this.get(key));
|
|
78
140
|
}
|
|
79
141
|
}
|
|
@@ -99,10 +161,10 @@ class CacheMap extends core.Dictionary {
|
|
|
99
161
|
return clone;
|
|
100
162
|
}
|
|
101
163
|
constructor(types, map){
|
|
102
|
-
super(map), _define_property(this, "types", void 0);
|
|
164
|
+
super(map, createNormalizedHashFunction()), _define_property(this, "types", void 0);
|
|
103
165
|
this.types = types;
|
|
104
166
|
}
|
|
105
167
|
}
|
|
106
168
|
|
|
107
169
|
exports.CacheMap = CacheMap;
|
|
108
|
-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,
|
|
170
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ2FjaGVNYXAuY2pzLmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0=
|
package/dist/CacheMap.es.js
CHANGED
|
@@ -15,6 +15,68 @@ function _define_property(obj, key, value) {
|
|
|
15
15
|
return obj;
|
|
16
16
|
}
|
|
17
17
|
const logger = LibLogger.get("CacheMap");
|
|
18
|
+
// Normalize a key value to string for consistent comparison and hashing
|
|
19
|
+
const normalizeKeyValue = (value)=>{
|
|
20
|
+
return String(value);
|
|
21
|
+
};
|
|
22
|
+
// Normalized hash function for Dictionary that converts pk/lk values to strings
|
|
23
|
+
const createNormalizedHashFunction = ()=>{
|
|
24
|
+
return (key)=>{
|
|
25
|
+
if (typeof key === 'object' && key !== null) {
|
|
26
|
+
// Create a normalized version of the key with string values
|
|
27
|
+
const normalizedKey = JSON.parse(JSON.stringify(key));
|
|
28
|
+
// Normalize pk values
|
|
29
|
+
if ('pk' in normalizedKey && normalizedKey.pk !== null) {
|
|
30
|
+
normalizedKey.pk = normalizeKeyValue(normalizedKey.pk);
|
|
31
|
+
}
|
|
32
|
+
// Normalize lk values
|
|
33
|
+
if ('lk' in normalizedKey && normalizedKey.lk !== null) {
|
|
34
|
+
normalizedKey.lk = normalizeKeyValue(normalizedKey.lk);
|
|
35
|
+
}
|
|
36
|
+
// Normalize loc array lk values
|
|
37
|
+
if ('loc' in normalizedKey && Array.isArray(normalizedKey.loc)) {
|
|
38
|
+
normalizedKey.loc = normalizedKey.loc.map((locItem)=>{
|
|
39
|
+
if (locItem && 'lk' in locItem && locItem.lk !== null) {
|
|
40
|
+
return {
|
|
41
|
+
...locItem,
|
|
42
|
+
lk: normalizeKeyValue(locItem.lk)
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return locItem;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return JSON.stringify(normalizedKey);
|
|
49
|
+
}
|
|
50
|
+
return JSON.stringify(key);
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
// Helper function to normalize and compare location key arrays
|
|
54
|
+
const isLocKeyArrayEqual = (a, b)=>{
|
|
55
|
+
if (a.length !== b.length) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
for(let i = 0; i < a.length; i++){
|
|
59
|
+
const normalizedA = normalizeLocKeyItem(a[i]);
|
|
60
|
+
const normalizedB = normalizeLocKeyItem(b[i]);
|
|
61
|
+
if (JSON.stringify(normalizedA) !== JSON.stringify(normalizedB)) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return true;
|
|
66
|
+
};
|
|
67
|
+
// Helper function to normalize a location key item
|
|
68
|
+
const normalizeLocKeyItem = (item)=>{
|
|
69
|
+
if (typeof item === 'object' && item !== null) {
|
|
70
|
+
const normalized = {
|
|
71
|
+
...item
|
|
72
|
+
};
|
|
73
|
+
if ('lk' in normalized && normalized.lk !== null) {
|
|
74
|
+
normalized.lk = normalizeKeyValue(normalized.lk);
|
|
75
|
+
}
|
|
76
|
+
return normalized;
|
|
77
|
+
}
|
|
78
|
+
return item;
|
|
79
|
+
};
|
|
18
80
|
// const isObj = (x: any) => typeof x === "object" && x !== null;
|
|
19
81
|
// const intersection = (a: object, b: object): object => {
|
|
20
82
|
// const result: { [key: string]: any } = {}
|
|
@@ -69,7 +131,7 @@ class CacheMap extends Dictionary {
|
|
|
69
131
|
locKeys,
|
|
70
132
|
ComKey
|
|
71
133
|
});
|
|
72
|
-
return
|
|
134
|
+
return isLocKeyArrayEqual(locKeys, ComKey.loc);
|
|
73
135
|
}).map((key)=>this.get(key));
|
|
74
136
|
}
|
|
75
137
|
}
|
|
@@ -95,10 +157,10 @@ class CacheMap extends Dictionary {
|
|
|
95
157
|
return clone;
|
|
96
158
|
}
|
|
97
159
|
constructor(types, map){
|
|
98
|
-
super(map), _define_property(this, "types", void 0);
|
|
160
|
+
super(map, createNormalizedHashFunction()), _define_property(this, "types", void 0);
|
|
99
161
|
this.types = types;
|
|
100
162
|
}
|
|
101
163
|
}
|
|
102
164
|
|
|
103
165
|
export { CacheMap };
|
|
104
|
-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,
|
|
166
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ2FjaGVNYXAuZXMuanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
|
|
5
|
+
const logger$1 = require('./logger.cjs.js');
|
|
6
|
+
const registry = require('@fjell/registry');
|
|
7
|
+
|
|
8
|
+
const logger = logger$1.default.get("Instance");
|
|
9
|
+
const createInstance = (registry$1, coordinate, cache)=>{
|
|
10
|
+
logger.debug("createInstance", {
|
|
11
|
+
coordinate,
|
|
12
|
+
cache,
|
|
13
|
+
registry: registry$1
|
|
14
|
+
});
|
|
15
|
+
const baseInstance = registry.createInstance(registry$1, coordinate);
|
|
16
|
+
return {
|
|
17
|
+
...baseInstance,
|
|
18
|
+
cache
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
const isInstance = (instance)=>{
|
|
22
|
+
return instance !== null && instance !== undefined && instance.coordinate !== undefined && instance.cache !== undefined && instance.registry !== undefined;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
exports.createInstance = createInstance;
|
|
26
|
+
exports.isInstance = isInstance;
|
|
27
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiSW5zdGFuY2UuY2pzLmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Item } from '@fjell/core';
|
|
2
|
+
import { Instance as BaseInstance, Coordinate, Registry } from '@fjell/registry';
|
|
3
|
+
import { Cache } from './Cache';
|
|
4
|
+
/**
|
|
5
|
+
* The Cache Instance interface represents a cache model instance that extends the base Instance
|
|
6
|
+
* from @fjell/registry and adds cache operations for interacting with cached data.
|
|
7
|
+
*
|
|
8
|
+
* The interface extends the base Instance (which provides coordinate and registry) with:
|
|
9
|
+
* - cache: Provides methods for interacting with cached data (get, set, all, etc.)
|
|
10
|
+
*
|
|
11
|
+
* @template V - The type of the data model item, extending Item
|
|
12
|
+
* @template S - The string literal type representing the model's key type
|
|
13
|
+
* @template L1-L5 - Optional string literal types for location hierarchy levels
|
|
14
|
+
*/
|
|
15
|
+
export interface Instance<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 BaseInstance<S, L1, L2, L3, L4, L5> {
|
|
16
|
+
/** The cache object that provides methods for interacting with cached data */
|
|
17
|
+
cache: Cache<V, S, L1, L2, L3, L4, L5>;
|
|
18
|
+
}
|
|
19
|
+
export declare const createInstance: <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>(registry: Registry, coordinate: Coordinate<S, L1, L2, L3, L4, L5>, cache: Cache<V, S, L1, L2, L3, L4, L5>) => Instance<V, S, L1, L2, L3, L4, L5>;
|
|
20
|
+
export declare const isInstance: (instance: any) => instance is Instance<any, any, any, any, any, any, any>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import LibLogger from './logger.es.js';
|
|
2
|
+
import { createInstance as createInstance$1 } from '@fjell/registry';
|
|
3
|
+
|
|
4
|
+
const logger = LibLogger.get("Instance");
|
|
5
|
+
const createInstance = (registry, coordinate, cache)=>{
|
|
6
|
+
logger.debug("createInstance", {
|
|
7
|
+
coordinate,
|
|
8
|
+
cache,
|
|
9
|
+
registry
|
|
10
|
+
});
|
|
11
|
+
const baseInstance = createInstance$1(registry, coordinate);
|
|
12
|
+
return {
|
|
13
|
+
...baseInstance,
|
|
14
|
+
cache
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
const isInstance = (instance)=>{
|
|
18
|
+
return instance !== null && instance !== undefined && instance.coordinate !== undefined && instance.cache !== undefined && instance.registry !== undefined;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export { createInstance, isInstance };
|
|
22
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiSW5zdGFuY2UuZXMuanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
|
|
5
|
+
const Instance = require('./Instance.cjs.js');
|
|
6
|
+
const logger$1 = require('./logger.cjs.js');
|
|
7
|
+
|
|
8
|
+
const logger = logger$1.default.get("InstanceFactory");
|
|
9
|
+
/**
|
|
10
|
+
* Factory function for creating cache instances
|
|
11
|
+
*/ const createInstanceFactory = (cache)=>{
|
|
12
|
+
return (coordinate, context)=>{
|
|
13
|
+
logger.debug("Creating cache instance", {
|
|
14
|
+
coordinate,
|
|
15
|
+
registry: context.registry,
|
|
16
|
+
cache
|
|
17
|
+
});
|
|
18
|
+
return Instance.createInstance(context.registry, coordinate, cache);
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
exports.createInstanceFactory = createInstanceFactory;
|
|
23
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiSW5zdGFuY2VGYWN0b3J5LmNqcy5qcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Item } from '@fjell/core';
|
|
2
|
+
import { Cache } from './Cache';
|
|
3
|
+
import { InstanceFactory as BaseInstanceFactory } from '@fjell/registry';
|
|
4
|
+
export type InstanceFactory<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>) => BaseInstanceFactory<S, L1, L2, L3, L4, L5>;
|
|
5
|
+
/**
|
|
6
|
+
* Factory function for creating cache instances
|
|
7
|
+
*/
|
|
8
|
+
export declare const createInstanceFactory: <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>) => BaseInstanceFactory<S, L1, L2, L3, L4, L5>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createInstance } from './Instance.es.js';
|
|
2
|
+
import LibLogger from './logger.es.js';
|
|
3
|
+
|
|
4
|
+
const logger = LibLogger.get("InstanceFactory");
|
|
5
|
+
/**
|
|
6
|
+
* Factory function for creating cache instances
|
|
7
|
+
*/ const createInstanceFactory = (cache)=>{
|
|
8
|
+
return (coordinate, context)=>{
|
|
9
|
+
logger.debug("Creating cache instance", {
|
|
10
|
+
coordinate,
|
|
11
|
+
registry: context.registry,
|
|
12
|
+
cache
|
|
13
|
+
});
|
|
14
|
+
return createInstance(context.registry, coordinate, cache);
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { createInstanceFactory };
|
|
19
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiSW5zdGFuY2VGYWN0b3J5LmVzLmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
|
|
5
|
+
const logger$1 = require('./logger.cjs.js');
|
|
6
|
+
const registry = require('@fjell/registry');
|
|
7
|
+
|
|
8
|
+
const logger = logger$1.default.get("Registry");
|
|
9
|
+
/**
|
|
10
|
+
* Factory function for creating cache registries
|
|
11
|
+
*/ const createRegistryFactory = ()=>{
|
|
12
|
+
return (type, registryHub)=>{
|
|
13
|
+
if (type !== 'cache') {
|
|
14
|
+
throw new Error(`Cache registry factory can only create 'cache' type registries, got: ${type}`);
|
|
15
|
+
}
|
|
16
|
+
logger.debug("Creating cache registry", {
|
|
17
|
+
type,
|
|
18
|
+
registryHub
|
|
19
|
+
});
|
|
20
|
+
const baseRegistry = registry.createRegistry(type, registryHub);
|
|
21
|
+
// Cast to Registry for type safety
|
|
22
|
+
return baseRegistry;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new cache registry instance
|
|
27
|
+
*/ const createRegistry = (registryHub)=>{
|
|
28
|
+
const baseRegistry = registry.createRegistry('cache', registryHub);
|
|
29
|
+
return {
|
|
30
|
+
...baseRegistry
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
exports.createRegistry = createRegistry;
|
|
35
|
+
exports.createRegistryFactory = createRegistryFactory;
|
|
36
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiUmVnaXN0cnkuY2pzLmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Registry as BaseRegistry, RegistryFactory, RegistryHub } from '@fjell/registry';
|
|
2
|
+
/**
|
|
3
|
+
* Extended Registry interface for cache-specific functionality
|
|
4
|
+
*/
|
|
5
|
+
export interface Registry extends BaseRegistry {
|
|
6
|
+
type: 'cache';
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Factory function for creating cache registries
|
|
10
|
+
*/
|
|
11
|
+
export declare const createRegistryFactory: () => RegistryFactory;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new cache registry instance
|
|
14
|
+
*/
|
|
15
|
+
export declare const createRegistry: (registryHub?: RegistryHub) => Registry;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import LibLogger from './logger.es.js';
|
|
2
|
+
import { createRegistry as createRegistry$1 } from '@fjell/registry';
|
|
3
|
+
|
|
4
|
+
const logger = LibLogger.get("Registry");
|
|
5
|
+
/**
|
|
6
|
+
* Factory function for creating cache registries
|
|
7
|
+
*/ const createRegistryFactory = ()=>{
|
|
8
|
+
return (type, registryHub)=>{
|
|
9
|
+
if (type !== 'cache') {
|
|
10
|
+
throw new Error(`Cache registry factory can only create 'cache' type registries, got: ${type}`);
|
|
11
|
+
}
|
|
12
|
+
logger.debug("Creating cache registry", {
|
|
13
|
+
type,
|
|
14
|
+
registryHub
|
|
15
|
+
});
|
|
16
|
+
const baseRegistry = createRegistry$1(type, registryHub);
|
|
17
|
+
// Cast to Registry for type safety
|
|
18
|
+
return baseRegistry;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Creates a new cache registry instance
|
|
23
|
+
*/ const createRegistry = (registryHub)=>{
|
|
24
|
+
const baseRegistry = createRegistry$1('cache', registryHub);
|
|
25
|
+
return {
|
|
26
|
+
...baseRegistry
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export { createRegistry, createRegistryFactory };
|
|
31
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiUmVnaXN0cnkuZXMuanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
|