@fjell/cache 4.6.5 → 4.6.7
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/index.cjs +104 -3
- package/dist/index.cjs.map +1 -1
- package/package.json +12 -12
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
|
package/dist/index.cjs
CHANGED
|
@@ -329,6 +329,68 @@ function _define_property$1(obj, key, value) {
|
|
|
329
329
|
return obj;
|
|
330
330
|
}
|
|
331
331
|
const logger$2 = LibLogger.get("CacheMap");
|
|
332
|
+
// Normalize a key value to string for consistent comparison and hashing
|
|
333
|
+
const normalizeKeyValue$1 = (value)=>{
|
|
334
|
+
return String(value);
|
|
335
|
+
};
|
|
336
|
+
// Normalized hash function for Dictionary that converts pk/lk values to strings
|
|
337
|
+
const createNormalizedHashFunction = ()=>{
|
|
338
|
+
return (key)=>{
|
|
339
|
+
if (typeof key === 'object' && key !== null) {
|
|
340
|
+
// Create a normalized version of the key with string values
|
|
341
|
+
const normalizedKey = JSON.parse(JSON.stringify(key));
|
|
342
|
+
// Normalize pk values
|
|
343
|
+
if ('pk' in normalizedKey && normalizedKey.pk !== null) {
|
|
344
|
+
normalizedKey.pk = normalizeKeyValue$1(normalizedKey.pk);
|
|
345
|
+
}
|
|
346
|
+
// Normalize lk values
|
|
347
|
+
if ('lk' in normalizedKey && normalizedKey.lk !== null) {
|
|
348
|
+
normalizedKey.lk = normalizeKeyValue$1(normalizedKey.lk);
|
|
349
|
+
}
|
|
350
|
+
// Normalize loc array lk values
|
|
351
|
+
if ('loc' in normalizedKey && Array.isArray(normalizedKey.loc)) {
|
|
352
|
+
normalizedKey.loc = normalizedKey.loc.map((locItem)=>{
|
|
353
|
+
if (locItem && 'lk' in locItem && locItem.lk !== null) {
|
|
354
|
+
return {
|
|
355
|
+
...locItem,
|
|
356
|
+
lk: normalizeKeyValue$1(locItem.lk)
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
return locItem;
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
return JSON.stringify(normalizedKey);
|
|
363
|
+
}
|
|
364
|
+
return JSON.stringify(key);
|
|
365
|
+
};
|
|
366
|
+
};
|
|
367
|
+
// Helper function to normalize and compare location key arrays
|
|
368
|
+
const isLocKeyArrayEqual = (a, b)=>{
|
|
369
|
+
if (a.length !== b.length) {
|
|
370
|
+
return false;
|
|
371
|
+
}
|
|
372
|
+
for(let i = 0; i < a.length; i++){
|
|
373
|
+
const normalizedA = normalizeLocKeyItem(a[i]);
|
|
374
|
+
const normalizedB = normalizeLocKeyItem(b[i]);
|
|
375
|
+
if (JSON.stringify(normalizedA) !== JSON.stringify(normalizedB)) {
|
|
376
|
+
return false;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
return true;
|
|
380
|
+
};
|
|
381
|
+
// Helper function to normalize a location key item
|
|
382
|
+
const normalizeLocKeyItem = (item)=>{
|
|
383
|
+
if (typeof item === 'object' && item !== null) {
|
|
384
|
+
const normalized = {
|
|
385
|
+
...item
|
|
386
|
+
};
|
|
387
|
+
if ('lk' in normalized && normalized.lk !== null) {
|
|
388
|
+
normalized.lk = normalizeKeyValue$1(normalized.lk);
|
|
389
|
+
}
|
|
390
|
+
return normalized;
|
|
391
|
+
}
|
|
392
|
+
return item;
|
|
393
|
+
};
|
|
332
394
|
// const isObj = (x: any) => typeof x === "object" && x !== null;
|
|
333
395
|
// const intersection = (a: object, b: object): object => {
|
|
334
396
|
// const result: { [key: string]: any } = {}
|
|
@@ -383,7 +445,7 @@ class CacheMap extends core.Dictionary {
|
|
|
383
445
|
locKeys,
|
|
384
446
|
ComKey
|
|
385
447
|
});
|
|
386
|
-
return
|
|
448
|
+
return isLocKeyArrayEqual(locKeys, ComKey.loc);
|
|
387
449
|
}).map((key)=>this.get(key));
|
|
388
450
|
}
|
|
389
451
|
}
|
|
@@ -409,12 +471,51 @@ class CacheMap extends core.Dictionary {
|
|
|
409
471
|
return clone;
|
|
410
472
|
}
|
|
411
473
|
constructor(types, map){
|
|
412
|
-
super(map), _define_property$1(this, "types", void 0);
|
|
474
|
+
super(map, createNormalizedHashFunction()), _define_property$1(this, "types", void 0);
|
|
413
475
|
this.types = types;
|
|
414
476
|
}
|
|
415
477
|
}
|
|
416
478
|
|
|
417
479
|
const logger$1 = LibLogger.get('Cache');
|
|
480
|
+
// Normalize a key value to string for consistent comparison
|
|
481
|
+
const normalizeKeyValue = (value)=>{
|
|
482
|
+
return String(value);
|
|
483
|
+
};
|
|
484
|
+
// Normalized key comparison function that handles string/number differences
|
|
485
|
+
const isItemKeyEqualNormalized = (a, b)=>{
|
|
486
|
+
// For now, just normalize the keys to strings and use the original comparison
|
|
487
|
+
const normalizedA = normalizeKey(a);
|
|
488
|
+
const normalizedB = normalizeKey(b);
|
|
489
|
+
return core.isItemKeyEqual(normalizedA, normalizedB);
|
|
490
|
+
};
|
|
491
|
+
// Helper function to normalize a key
|
|
492
|
+
const normalizeKey = (key)=>{
|
|
493
|
+
if (typeof key === 'object' && key !== null) {
|
|
494
|
+
const normalizedKey = JSON.parse(JSON.stringify(key));
|
|
495
|
+
// Normalize pk values
|
|
496
|
+
if ('pk' in normalizedKey && normalizedKey.pk !== null) {
|
|
497
|
+
normalizedKey.pk = normalizeKeyValue(normalizedKey.pk);
|
|
498
|
+
}
|
|
499
|
+
// Normalize lk values
|
|
500
|
+
if ('lk' in normalizedKey && normalizedKey.lk !== null) {
|
|
501
|
+
normalizedKey.lk = normalizeKeyValue(normalizedKey.lk);
|
|
502
|
+
}
|
|
503
|
+
// Normalize loc array lk values
|
|
504
|
+
if ('loc' in normalizedKey && Array.isArray(normalizedKey.loc)) {
|
|
505
|
+
normalizedKey.loc = normalizedKey.loc.map((locItem)=>{
|
|
506
|
+
if (locItem && 'lk' in locItem && locItem.lk !== null) {
|
|
507
|
+
return {
|
|
508
|
+
...locItem,
|
|
509
|
+
lk: normalizeKeyValue(locItem.lk)
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
return locItem;
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
return normalizedKey;
|
|
516
|
+
}
|
|
517
|
+
return key;
|
|
518
|
+
};
|
|
418
519
|
const createCache = async (api, pkType, parentCache)=>{
|
|
419
520
|
let pkTypes = [
|
|
420
521
|
pkType
|
|
@@ -691,7 +792,7 @@ const createCache = async (api, pkType, parentCache)=>{
|
|
|
691
792
|
}
|
|
692
793
|
// TODO: This could be merged with the isValidItemKey check, later.
|
|
693
794
|
core.validatePK(v, pkType);
|
|
694
|
-
if (!
|
|
795
|
+
if (!isItemKeyEqualNormalized(key, v.key)) {
|
|
695
796
|
logger$1.error('Key does not match item key: %j != %j', key, v.key);
|
|
696
797
|
throw new Error('Key does not match item key');
|
|
697
798
|
}
|
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/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.7",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cache",
|
|
7
7
|
"fjell"
|
|
@@ -19,30 +19,30 @@
|
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@fjell/client-api": "^4.4.
|
|
23
|
-
"@fjell/core": "^4.4.
|
|
24
|
-
"@fjell/http-api": "^4.4.
|
|
25
|
-
"@fjell/logging": "^4.4.
|
|
22
|
+
"@fjell/client-api": "^4.4.6",
|
|
23
|
+
"@fjell/core": "^4.4.7",
|
|
24
|
+
"@fjell/http-api": "^4.4.5",
|
|
25
|
+
"@fjell/logging": "^4.4.7"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@eslint/eslintrc": "^3.3.1",
|
|
29
|
-
"@eslint/js": "^9.
|
|
30
|
-
"@swc/core": "^1.12.
|
|
29
|
+
"@eslint/js": "^9.31.0",
|
|
30
|
+
"@swc/core": "^1.12.14",
|
|
31
31
|
"@tsconfig/recommended": "^1.0.10",
|
|
32
32
|
"@types/multer": "^2.0.0",
|
|
33
|
-
"@types/node": "^24.0.
|
|
34
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
35
|
-
"@typescript-eslint/parser": "^8.
|
|
33
|
+
"@types/node": "^24.0.13",
|
|
34
|
+
"@typescript-eslint/eslint-plugin": "^8.37.0",
|
|
35
|
+
"@typescript-eslint/parser": "^8.37.0",
|
|
36
36
|
"@vitest/coverage-v8": "^3.2.4",
|
|
37
37
|
"@vitest/ui": "^3.2.4",
|
|
38
38
|
"concurrently": "^9.2.0",
|
|
39
|
-
"eslint": "^9.
|
|
39
|
+
"eslint": "^9.31.0",
|
|
40
40
|
"nodemon": "^3.1.10",
|
|
41
41
|
"rimraf": "^6.0.1",
|
|
42
42
|
"ts-node": "^10.9.2",
|
|
43
43
|
"tsc-alias": "^1.8.16",
|
|
44
44
|
"typescript": "^5.8.3",
|
|
45
|
-
"vite": "^7.0.
|
|
45
|
+
"vite": "^7.0.4",
|
|
46
46
|
"vite-plugin-dts": "^4.5.4",
|
|
47
47
|
"vite-plugin-node": "^7.0.0",
|
|
48
48
|
"vitest": "^3.2.4"
|