@fjell/cache 4.7.29 → 4.7.30
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/CacheContext.d.ts +4 -2
- package/dist/CacheContext.d.ts.map +1 -1
- package/dist/index.js +438 -384
- package/dist/ops/all.d.ts.map +1 -1
- package/dist/ops/allAction.d.ts.map +1 -1
- package/dist/ops/allFacet.d.ts.map +1 -1
- package/dist/ops/create.d.ts.map +1 -1
- package/dist/ops/find.d.ts.map +1 -1
- package/dist/ops/findOne.d.ts.map +1 -1
- package/dist/ops/one.d.ts.map +1 -1
- package/dist/validation/LocationKeyValidator.d.ts +13 -0
- package/dist/validation/LocationKeyValidator.d.ts.map +1 -0
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/CacheContext.ts
|
|
2
|
-
var createCacheContext = (api, cacheMap, pkType, options, eventEmitter, ttlManager, evictionManager, statsManager, registry) => {
|
|
2
|
+
var createCacheContext = (api, cacheMap, pkType, options, eventEmitter, ttlManager, evictionManager, statsManager, registry, coordinate) => {
|
|
3
3
|
return {
|
|
4
4
|
api,
|
|
5
5
|
cacheMap,
|
|
@@ -9,7 +9,8 @@ var createCacheContext = (api, cacheMap, pkType, options, eventEmitter, ttlManag
|
|
|
9
9
|
ttlManager,
|
|
10
10
|
evictionManager,
|
|
11
11
|
statsManager,
|
|
12
|
-
registry
|
|
12
|
+
registry,
|
|
13
|
+
coordinate
|
|
13
14
|
};
|
|
14
15
|
};
|
|
15
16
|
|
|
@@ -313,27 +314,74 @@ import Logging from "@fjell/logging";
|
|
|
313
314
|
var LibLogger = Logging.getLogger("@fjell/cache");
|
|
314
315
|
var logger_default = LibLogger;
|
|
315
316
|
|
|
317
|
+
// src/validation/LocationKeyValidator.ts
|
|
318
|
+
var logger = logger_default.get("LocationKeyValidator");
|
|
319
|
+
var validateLocations = (locations, coordinate, operation) => {
|
|
320
|
+
if (!locations || locations.length === 0) {
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
const keyTypeArray = coordinate.kta;
|
|
324
|
+
const expectedLocationTypes = keyTypeArray.slice(1);
|
|
325
|
+
const actualLocationTypes = locations.map((loc) => loc.kt);
|
|
326
|
+
logger.debug(`Validating locations for ${operation}`, {
|
|
327
|
+
expected: expectedLocationTypes,
|
|
328
|
+
actual: actualLocationTypes,
|
|
329
|
+
coordinate: keyTypeArray
|
|
330
|
+
});
|
|
331
|
+
if (actualLocationTypes.length > expectedLocationTypes.length) {
|
|
332
|
+
logger.error("Location key array has too many elements", {
|
|
333
|
+
expected: expectedLocationTypes.length,
|
|
334
|
+
actual: actualLocationTypes.length,
|
|
335
|
+
expectedTypes: expectedLocationTypes,
|
|
336
|
+
actualTypes: actualLocationTypes,
|
|
337
|
+
coordinate,
|
|
338
|
+
operation
|
|
339
|
+
});
|
|
340
|
+
throw new Error(
|
|
341
|
+
`Invalid location key array for ${operation}: Expected at most ${expectedLocationTypes.length} location keys (hierarchy: [${expectedLocationTypes.join(", ")}]), but received ${actualLocationTypes.length} (types: [${actualLocationTypes.join(", ")}])`
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
for (let i = 0; i < actualLocationTypes.length; i++) {
|
|
345
|
+
if (expectedLocationTypes[i] !== actualLocationTypes[i]) {
|
|
346
|
+
logger.error("Location key array order mismatch", {
|
|
347
|
+
position: i,
|
|
348
|
+
expected: expectedLocationTypes[i],
|
|
349
|
+
actual: actualLocationTypes[i],
|
|
350
|
+
expectedHierarchy: expectedLocationTypes,
|
|
351
|
+
actualOrder: actualLocationTypes,
|
|
352
|
+
coordinate,
|
|
353
|
+
operation
|
|
354
|
+
});
|
|
355
|
+
throw new Error(
|
|
356
|
+
`Invalid location key array order for ${operation}: At position ${i}, expected key type "${expectedLocationTypes[i]}" but received "${actualLocationTypes[i]}". Location keys must be ordered according to the hierarchy: [${expectedLocationTypes.join(", ")}]. Received order: [${actualLocationTypes.join(", ")}]`
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
logger.debug(`Location key array validation passed for ${operation}`, { locations });
|
|
361
|
+
};
|
|
362
|
+
|
|
316
363
|
// src/ops/all.ts
|
|
317
|
-
var
|
|
364
|
+
var logger2 = logger_default.get("all");
|
|
318
365
|
var all = async (query = {}, locations = [], context) => {
|
|
319
|
-
const { api, cacheMap, pkType, ttlManager } = context;
|
|
320
|
-
|
|
366
|
+
const { api, cacheMap, pkType, ttlManager, coordinate } = context;
|
|
367
|
+
logger2.default("all", { query, locations });
|
|
368
|
+
validateLocations(locations, coordinate, "all");
|
|
321
369
|
if (context.options?.bypassCache) {
|
|
322
|
-
|
|
370
|
+
logger2.debug("Cache bypass enabled, fetching directly from API", { query, locations });
|
|
323
371
|
try {
|
|
324
372
|
const ret2 = await api.all(query, locations);
|
|
325
|
-
|
|
373
|
+
logger2.debug("API response received (not cached due to bypass)", { query, locations, itemCount: ret2.length });
|
|
326
374
|
return [context, validatePK(ret2, pkType)];
|
|
327
375
|
} catch (error) {
|
|
328
|
-
|
|
376
|
+
logger2.error("API request failed", { query, locations, error });
|
|
329
377
|
throw error;
|
|
330
378
|
}
|
|
331
379
|
}
|
|
332
380
|
const queryHash = createQueryHash(pkType, query, locations);
|
|
333
|
-
|
|
381
|
+
logger2.debug("Generated query hash for all", { queryHash });
|
|
334
382
|
const cachedItemKeys = await cacheMap.getQueryResult(queryHash);
|
|
335
383
|
if (cachedItemKeys) {
|
|
336
|
-
|
|
384
|
+
logger2.debug("Using cached query results", { cachedKeyCount: cachedItemKeys.length });
|
|
337
385
|
const cachedItems = [];
|
|
338
386
|
let allItemsAvailable = true;
|
|
339
387
|
for (const itemKey of cachedItemKeys) {
|
|
@@ -348,21 +396,21 @@ var all = async (query = {}, locations = [], context) => {
|
|
|
348
396
|
if (allItemsAvailable) {
|
|
349
397
|
return [context, validatePK(cachedItems, pkType)];
|
|
350
398
|
} else {
|
|
351
|
-
|
|
399
|
+
logger2.debug("Some cached items missing, invalidating query cache");
|
|
352
400
|
cacheMap.deleteQueryResult(queryHash);
|
|
353
401
|
}
|
|
354
402
|
}
|
|
355
403
|
try {
|
|
356
404
|
const directCachedItems = await cacheMap.queryIn(query, locations);
|
|
357
405
|
if (directCachedItems && directCachedItems.length > 0) {
|
|
358
|
-
|
|
406
|
+
logger2.debug("Found items directly in cache, skipping API call", { itemCount: directCachedItems.length });
|
|
359
407
|
const itemKeys = directCachedItems.map((item) => item.key);
|
|
360
408
|
await cacheMap.setQueryResult(queryHash, itemKeys);
|
|
361
|
-
|
|
409
|
+
logger2.debug("Cached query result from direct cache hit", { queryHash, itemKeyCount: itemKeys.length });
|
|
362
410
|
return [context, validatePK(directCachedItems, pkType)];
|
|
363
411
|
}
|
|
364
412
|
} catch (error) {
|
|
365
|
-
|
|
413
|
+
logger2.debug("Error querying cache directly, proceeding to API", { error });
|
|
366
414
|
}
|
|
367
415
|
let ret = [];
|
|
368
416
|
try {
|
|
@@ -379,13 +427,13 @@ var all = async (query = {}, locations = [], context) => {
|
|
|
379
427
|
}
|
|
380
428
|
const itemKeys = ret.map((item) => item.key);
|
|
381
429
|
cacheMap.setQueryResult(queryHash, itemKeys);
|
|
382
|
-
|
|
430
|
+
logger2.debug("Cached query result", { queryHash, itemKeyCount: itemKeys.length });
|
|
383
431
|
const event = CacheEventFactory.createQueryEvent(query, locations, ret);
|
|
384
432
|
context.eventEmitter.emit(event);
|
|
385
433
|
} catch (e) {
|
|
386
434
|
if (e instanceof NotFoundError) {
|
|
387
435
|
cacheMap.setQueryResult(queryHash, []);
|
|
388
|
-
|
|
436
|
+
logger2.debug("Cached empty query result for not found", { queryHash });
|
|
389
437
|
} else {
|
|
390
438
|
throw e;
|
|
391
439
|
}
|
|
@@ -560,31 +608,32 @@ function validateSizeConfig(config) {
|
|
|
560
608
|
}
|
|
561
609
|
|
|
562
610
|
// src/ops/one.ts
|
|
563
|
-
var
|
|
611
|
+
var logger3 = logger_default.get("one");
|
|
564
612
|
var one = async (query = {}, locations = [], context) => {
|
|
565
|
-
const { api, cacheMap, pkType, ttlManager } = context;
|
|
566
|
-
|
|
613
|
+
const { api, cacheMap, pkType, ttlManager, coordinate } = context;
|
|
614
|
+
logger3.default("one", { query, locations });
|
|
615
|
+
validateLocations(locations, coordinate, "one");
|
|
567
616
|
if (context.options?.bypassCache) {
|
|
568
|
-
|
|
617
|
+
logger3.debug("Cache bypass enabled, fetching directly from API", { query, locations });
|
|
569
618
|
try {
|
|
570
619
|
const retItem2 = await api.one(query, locations);
|
|
571
620
|
if (retItem2) {
|
|
572
|
-
|
|
621
|
+
logger3.debug("API response received (not cached due to bypass)", { query, locations });
|
|
573
622
|
return [context, validatePK2(retItem2, pkType)];
|
|
574
623
|
} else {
|
|
575
|
-
|
|
624
|
+
logger3.debug("API returned null", { query, locations });
|
|
576
625
|
return [context, null];
|
|
577
626
|
}
|
|
578
627
|
} catch (error) {
|
|
579
|
-
|
|
628
|
+
logger3.error("API request failed", { query, locations, error });
|
|
580
629
|
throw error;
|
|
581
630
|
}
|
|
582
631
|
}
|
|
583
632
|
const queryHash = createQueryHash(pkType, query, locations);
|
|
584
|
-
|
|
633
|
+
logger3.debug("Generated query hash for one", { queryHash });
|
|
585
634
|
const cachedItemKeys = await cacheMap.getQueryResult(queryHash);
|
|
586
635
|
if (cachedItemKeys) {
|
|
587
|
-
|
|
636
|
+
logger3.debug("Using cached query results", { cachedKeyCount: cachedItemKeys.length });
|
|
588
637
|
if (cachedItemKeys.length === 0) {
|
|
589
638
|
return [context, null];
|
|
590
639
|
}
|
|
@@ -592,21 +641,21 @@ var one = async (query = {}, locations = [], context) => {
|
|
|
592
641
|
if (item) {
|
|
593
642
|
return [context, validatePK2(item, pkType)];
|
|
594
643
|
} else {
|
|
595
|
-
|
|
644
|
+
logger3.debug("Cached item missing, invalidating query cache");
|
|
596
645
|
cacheMap.deleteQueryResult(queryHash);
|
|
597
646
|
}
|
|
598
647
|
}
|
|
599
648
|
try {
|
|
600
649
|
const directCachedItems = await cacheMap.queryIn(query, locations);
|
|
601
650
|
if (directCachedItems && directCachedItems.length > 0) {
|
|
602
|
-
|
|
651
|
+
logger3.debug("Found item directly in cache, skipping API call");
|
|
603
652
|
const foundItem = directCachedItems[0];
|
|
604
653
|
await cacheMap.setQueryResult(queryHash, [foundItem.key]);
|
|
605
|
-
|
|
654
|
+
logger3.debug("Cached query result from direct cache hit", { queryHash, itemKey: foundItem.key });
|
|
606
655
|
return [context, validatePK2(foundItem, pkType)];
|
|
607
656
|
}
|
|
608
657
|
} catch (error) {
|
|
609
|
-
|
|
658
|
+
logger3.debug("Error querying cache directly, proceeding to API", { error });
|
|
610
659
|
}
|
|
611
660
|
let retItem = null;
|
|
612
661
|
try {
|
|
@@ -633,15 +682,15 @@ var one = async (query = {}, locations = [], context) => {
|
|
|
633
682
|
await cacheMap.delete(parsedKey);
|
|
634
683
|
}
|
|
635
684
|
await cacheMap.setQueryResult(queryHash, [retItem.key]);
|
|
636
|
-
|
|
685
|
+
logger3.debug("Cached query result", { queryHash, itemKey: retItem.key });
|
|
637
686
|
} else {
|
|
638
687
|
await cacheMap.setQueryResult(queryHash, []);
|
|
639
|
-
|
|
688
|
+
logger3.debug("Cached empty query result", { queryHash });
|
|
640
689
|
}
|
|
641
690
|
} catch (e) {
|
|
642
691
|
if (e instanceof NotFoundError2) {
|
|
643
692
|
cacheMap.setQueryResult(queryHash, []);
|
|
644
|
-
|
|
693
|
+
logger3.debug("Cached empty query result for not found", { queryHash });
|
|
645
694
|
} else {
|
|
646
695
|
throw e;
|
|
647
696
|
}
|
|
@@ -656,10 +705,11 @@ var one = async (query = {}, locations = [], context) => {
|
|
|
656
705
|
import {
|
|
657
706
|
validatePK as validatePK3
|
|
658
707
|
} from "@fjell/core";
|
|
659
|
-
var
|
|
708
|
+
var logger4 = logger_default.get("create");
|
|
660
709
|
var create = async (v, locations = [], context) => {
|
|
661
|
-
const { api, cacheMap, pkType, eventEmitter, ttlManager, evictionManager } = context;
|
|
662
|
-
|
|
710
|
+
const { api, cacheMap, pkType, eventEmitter, ttlManager, evictionManager, coordinate } = context;
|
|
711
|
+
logger4.default("create", { v, locations });
|
|
712
|
+
validateLocations(locations, coordinate, "create");
|
|
663
713
|
const created = await api.create(v, locations);
|
|
664
714
|
cacheMap.set(created.key, created);
|
|
665
715
|
const keyStr = JSON.stringify(created.key);
|
|
@@ -687,7 +737,7 @@ import {
|
|
|
687
737
|
isValidItemKey,
|
|
688
738
|
validatePK as validatePK4
|
|
689
739
|
} from "@fjell/core";
|
|
690
|
-
var
|
|
740
|
+
var logger5 = logger_default.get("get");
|
|
691
741
|
var inFlightRequests = /* @__PURE__ */ new Map();
|
|
692
742
|
var CLEANUP_TIMEOUT = 5 * 60 * 1e3;
|
|
693
743
|
var cleanupStaleRequests = () => {
|
|
@@ -699,7 +749,7 @@ var cleanupStaleRequests = () => {
|
|
|
699
749
|
}
|
|
700
750
|
});
|
|
701
751
|
keysToDelete.forEach((key) => {
|
|
702
|
-
|
|
752
|
+
logger5.debug("Cleaning up stale in-flight request", { key });
|
|
703
753
|
inFlightRequests.delete(key);
|
|
704
754
|
});
|
|
705
755
|
};
|
|
@@ -707,26 +757,26 @@ var cleanupInterval = setInterval(cleanupStaleRequests, 60 * 1e3);
|
|
|
707
757
|
var keyToString = createNormalizedHashFunction();
|
|
708
758
|
var get = async (key, context) => {
|
|
709
759
|
const { api, cacheMap, pkType, ttlManager, statsManager } = context;
|
|
710
|
-
|
|
760
|
+
logger5.default("get", { key, defaultTTL: ttlManager.getDefaultTTL() });
|
|
711
761
|
statsManager.incrementRequests();
|
|
712
762
|
if (!isValidItemKey(key)) {
|
|
713
|
-
|
|
763
|
+
logger5.error("Key for Get is not a valid ItemKey: %j", key);
|
|
714
764
|
throw new Error("Key for Get is not a valid ItemKey");
|
|
715
765
|
}
|
|
716
766
|
if (context.options?.bypassCache) {
|
|
717
|
-
|
|
767
|
+
logger5.debug("Cache bypass enabled, fetching directly from API", { key });
|
|
718
768
|
statsManager.incrementMisses();
|
|
719
769
|
try {
|
|
720
770
|
const ret2 = await api.get(key);
|
|
721
771
|
if (ret2) {
|
|
722
|
-
|
|
772
|
+
logger5.debug("API response received (not cached due to bypass)", { key });
|
|
723
773
|
return [context, validatePK4(ret2, pkType)];
|
|
724
774
|
} else {
|
|
725
|
-
|
|
775
|
+
logger5.debug("API returned null", { key });
|
|
726
776
|
return [context, null];
|
|
727
777
|
}
|
|
728
778
|
} catch (error) {
|
|
729
|
-
|
|
779
|
+
logger5.error("API request failed", { key, error });
|
|
730
780
|
throw error;
|
|
731
781
|
}
|
|
732
782
|
}
|
|
@@ -736,22 +786,22 @@ var get = async (key, context) => {
|
|
|
736
786
|
if (cachedItem) {
|
|
737
787
|
const isValid = await ttlManager.validateItem(keyStr2, cacheMap);
|
|
738
788
|
if (isValid) {
|
|
739
|
-
|
|
789
|
+
logger5.debug("Cache hit with valid TTL", { key, defaultTTL: ttlManager.getDefaultTTL() });
|
|
740
790
|
statsManager.incrementHits();
|
|
741
791
|
return [context, validatePK4(cachedItem, pkType)];
|
|
742
792
|
} else {
|
|
743
|
-
|
|
793
|
+
logger5.debug("Cache item expired, removing", { key });
|
|
744
794
|
cacheMap.delete(key);
|
|
745
795
|
statsManager.incrementMisses();
|
|
746
796
|
}
|
|
747
797
|
} else {
|
|
748
798
|
statsManager.incrementMisses();
|
|
749
799
|
}
|
|
750
|
-
|
|
800
|
+
logger5.debug("Cache miss or expired", { key, defaultTTL: ttlManager.getDefaultTTL() });
|
|
751
801
|
} else {
|
|
752
802
|
const cachedItem = await cacheMap.get(key);
|
|
753
803
|
if (cachedItem) {
|
|
754
|
-
|
|
804
|
+
logger5.debug("Cache hit (TTL disabled)", { key });
|
|
755
805
|
statsManager.incrementHits();
|
|
756
806
|
return [context, validatePK4(cachedItem, pkType)];
|
|
757
807
|
} else {
|
|
@@ -776,7 +826,7 @@ var get = async (key, context) => {
|
|
|
776
826
|
}
|
|
777
827
|
}
|
|
778
828
|
} else {
|
|
779
|
-
|
|
829
|
+
logger5.debug("Using in-flight request for key", { key });
|
|
780
830
|
apiRequest = requestEntry.promise;
|
|
781
831
|
}
|
|
782
832
|
ret = await apiRequest;
|
|
@@ -806,7 +856,7 @@ var get = async (key, context) => {
|
|
|
806
856
|
}
|
|
807
857
|
} catch (e) {
|
|
808
858
|
inFlightRequests.delete(keyStr);
|
|
809
|
-
|
|
859
|
+
logger5.error("Error getting item for key", { key, message: e.message, stack: e.stack });
|
|
810
860
|
throw e;
|
|
811
861
|
}
|
|
812
862
|
return [
|
|
@@ -820,30 +870,30 @@ import {
|
|
|
820
870
|
isValidItemKey as isValidItemKey2,
|
|
821
871
|
validatePK as validatePK5
|
|
822
872
|
} from "@fjell/core";
|
|
823
|
-
var
|
|
873
|
+
var logger6 = logger_default.get("retrieve");
|
|
824
874
|
var retrieve = async (key, context) => {
|
|
825
875
|
const { cacheMap, pkType, statsManager } = context;
|
|
826
|
-
|
|
876
|
+
logger6.default("retrieve", { key });
|
|
827
877
|
statsManager.incrementRequests();
|
|
828
878
|
if (!isValidItemKey2(key)) {
|
|
829
|
-
|
|
879
|
+
logger6.error("Key for Retrieve is not a valid ItemKey: %j", key);
|
|
830
880
|
throw new Error("Key for Retrieve is not a valid ItemKey");
|
|
831
881
|
}
|
|
832
882
|
if (context.options?.bypassCache) {
|
|
833
|
-
|
|
883
|
+
logger6.debug("Cache bypass enabled, fetching directly from API", { key });
|
|
834
884
|
statsManager.incrementMisses();
|
|
835
885
|
try {
|
|
836
886
|
const { api } = context;
|
|
837
887
|
const retrieved2 = await api.get(key);
|
|
838
888
|
if (retrieved2) {
|
|
839
|
-
|
|
889
|
+
logger6.debug("API response received (not cached due to bypass)", { key });
|
|
840
890
|
return [null, validatePK5(retrieved2, pkType)];
|
|
841
891
|
} else {
|
|
842
|
-
|
|
892
|
+
logger6.debug("API returned null", { key });
|
|
843
893
|
return [null, null];
|
|
844
894
|
}
|
|
845
895
|
} catch (error) {
|
|
846
|
-
|
|
896
|
+
logger6.error("API request failed", { key, error });
|
|
847
897
|
throw error;
|
|
848
898
|
}
|
|
849
899
|
}
|
|
@@ -851,12 +901,12 @@ var retrieve = async (key, context) => {
|
|
|
851
901
|
let retrieved;
|
|
852
902
|
let contextToReturn;
|
|
853
903
|
if (containsItemKey) {
|
|
854
|
-
|
|
904
|
+
logger6.default("Looking for Object in Cache", key);
|
|
855
905
|
retrieved = await cacheMap.get(key);
|
|
856
906
|
contextToReturn = null;
|
|
857
907
|
statsManager.incrementHits();
|
|
858
908
|
} else {
|
|
859
|
-
|
|
909
|
+
logger6.default("Object Not Found in Cache, Retrieving from Server API", { key });
|
|
860
910
|
statsManager.incrementMisses();
|
|
861
911
|
[contextToReturn, retrieved] = await get(key, context);
|
|
862
912
|
}
|
|
@@ -871,12 +921,12 @@ var retrieve = async (key, context) => {
|
|
|
871
921
|
import {
|
|
872
922
|
isValidItemKey as isValidItemKey3
|
|
873
923
|
} from "@fjell/core";
|
|
874
|
-
var
|
|
924
|
+
var logger7 = logger_default.get("remove");
|
|
875
925
|
var remove = async (key, context) => {
|
|
876
926
|
const { api, cacheMap } = context;
|
|
877
|
-
|
|
927
|
+
logger7.default("remove", { key });
|
|
878
928
|
if (!isValidItemKey3(key)) {
|
|
879
|
-
|
|
929
|
+
logger7.error("Key for Remove is not a valid ItemKey: %j", key);
|
|
880
930
|
throw new Error("Key for Remove is not a valid ItemKey");
|
|
881
931
|
}
|
|
882
932
|
try {
|
|
@@ -895,9 +945,9 @@ var remove = async (key, context) => {
|
|
|
895
945
|
{ source: "operation", context: { operation: "remove" } }
|
|
896
946
|
);
|
|
897
947
|
context.eventEmitter.emit(queryInvalidatedEvent);
|
|
898
|
-
|
|
948
|
+
logger7.debug("Successfully removed item from API and cache", { key });
|
|
899
949
|
} catch (e) {
|
|
900
|
-
|
|
950
|
+
logger7.error("Error deleting item", { error: e });
|
|
901
951
|
throw e;
|
|
902
952
|
}
|
|
903
953
|
return context;
|
|
@@ -908,21 +958,21 @@ import {
|
|
|
908
958
|
isValidItemKey as isValidItemKey4,
|
|
909
959
|
validatePK as validatePK6
|
|
910
960
|
} from "@fjell/core";
|
|
911
|
-
var
|
|
961
|
+
var logger8 = logger_default.get("update");
|
|
912
962
|
var update = async (key, v, context) => {
|
|
913
963
|
const { api, cacheMap, pkType } = context;
|
|
914
|
-
|
|
964
|
+
logger8.default("update", { key, v });
|
|
915
965
|
if (!isValidItemKey4(key)) {
|
|
916
|
-
|
|
966
|
+
logger8.error("Key for Update is not a valid ItemKey: %j", key);
|
|
917
967
|
throw new Error("Key for Update is not a valid ItemKey");
|
|
918
968
|
}
|
|
919
|
-
|
|
969
|
+
logger8.debug("Invalidating item key before update", { key });
|
|
920
970
|
cacheMap.invalidateItemKeys([key]);
|
|
921
971
|
await cacheMap.clearQueryResults();
|
|
922
972
|
try {
|
|
923
973
|
const previousItem = await cacheMap.get(key);
|
|
924
974
|
const updated = await api.update(key, v);
|
|
925
|
-
|
|
975
|
+
logger8.debug("Caching update result", { updatedKey: updated.key });
|
|
926
976
|
await cacheMap.set(updated.key, updated);
|
|
927
977
|
const cachedItem = await cacheMap.get(updated.key);
|
|
928
978
|
const keyStr = JSON.stringify(updated.key);
|
|
@@ -955,7 +1005,7 @@ var update = async (key, v, context) => {
|
|
|
955
1005
|
context.eventEmitter.emit(queryInvalidatedEvent);
|
|
956
1006
|
return [context, validatePK6(updated, pkType)];
|
|
957
1007
|
} catch (e) {
|
|
958
|
-
|
|
1008
|
+
logger8.error("Error updating item", { error: e });
|
|
959
1009
|
throw e;
|
|
960
1010
|
}
|
|
961
1011
|
};
|
|
@@ -968,7 +1018,7 @@ import {
|
|
|
968
1018
|
|
|
969
1019
|
// src/utils/cacheInvalidation.ts
|
|
970
1020
|
import { toKeyTypeArray } from "@fjell/core";
|
|
971
|
-
var
|
|
1021
|
+
var logger9 = logger_default.get("cache", "utils", "cacheInvalidation");
|
|
972
1022
|
var extractKeysAndKeyTypesFromActionResult = (affectedItems) => {
|
|
973
1023
|
const keys = [];
|
|
974
1024
|
const keyTypeArrays = [];
|
|
@@ -985,7 +1035,7 @@ var extractKeysAndKeyTypesFromActionResult = (affectedItems) => {
|
|
|
985
1035
|
return { keys, keyTypeArrays };
|
|
986
1036
|
};
|
|
987
1037
|
var invalidateCachesByKeysAndKeyTypes = async (registry, keys, keyTypeArrays) => {
|
|
988
|
-
|
|
1038
|
+
logger9.debug("Invalidating caches by keys and key types", {
|
|
989
1039
|
keysCount: keys.length,
|
|
990
1040
|
keyTypeArrays
|
|
991
1041
|
});
|
|
@@ -1003,22 +1053,22 @@ var invalidateCachesByKeysAndKeyTypes = async (registry, keys, keyTypeArrays) =>
|
|
|
1003
1053
|
try {
|
|
1004
1054
|
const cacheInstance = registry.get(keyTypes);
|
|
1005
1055
|
if (cacheInstance && isCache(cacheInstance)) {
|
|
1006
|
-
|
|
1056
|
+
logger9.debug("Found cache instance for targeted invalidation", {
|
|
1007
1057
|
keyTypes,
|
|
1008
1058
|
cacheType: cacheInstance.coordinate.kta,
|
|
1009
1059
|
keysToInvalidate: cacheKeys.length
|
|
1010
1060
|
});
|
|
1011
1061
|
await cacheInstance.cacheMap.invalidateItemKeys(cacheKeys);
|
|
1012
1062
|
await cacheInstance.cacheMap.clearQueryResults();
|
|
1013
|
-
|
|
1063
|
+
logger9.debug("Successfully invalidated specific items in cache", {
|
|
1014
1064
|
keyTypes,
|
|
1015
1065
|
invalidatedCount: cacheKeys.length
|
|
1016
1066
|
});
|
|
1017
1067
|
} else {
|
|
1018
|
-
|
|
1068
|
+
logger9.debug("No cache instance found for key types", { keyTypes });
|
|
1019
1069
|
}
|
|
1020
1070
|
} catch (error) {
|
|
1021
|
-
|
|
1071
|
+
logger9.warning("Failed to invalidate cache for key types", {
|
|
1022
1072
|
keyTypes,
|
|
1023
1073
|
error: error instanceof Error ? error.message : String(error)
|
|
1024
1074
|
});
|
|
@@ -1028,12 +1078,12 @@ var invalidateCachesByKeysAndKeyTypes = async (registry, keys, keyTypeArrays) =>
|
|
|
1028
1078
|
try {
|
|
1029
1079
|
const cacheInstance = registry.get(keyTypes);
|
|
1030
1080
|
if (cacheInstance && isCache(cacheInstance)) {
|
|
1031
|
-
|
|
1081
|
+
logger9.debug("Handling location-based invalidation", { keyTypes });
|
|
1032
1082
|
await cacheInstance.cacheMap.clearQueryResults();
|
|
1033
|
-
|
|
1083
|
+
logger9.debug("Successfully cleared query results for location", { keyTypes });
|
|
1034
1084
|
}
|
|
1035
1085
|
} catch (error) {
|
|
1036
|
-
|
|
1086
|
+
logger9.warning("Failed to handle location-based invalidation", {
|
|
1037
1087
|
keyTypes,
|
|
1038
1088
|
error: error instanceof Error ? error.message : String(error)
|
|
1039
1089
|
});
|
|
@@ -1044,7 +1094,7 @@ function isCache(instance) {
|
|
|
1044
1094
|
return instance !== null && typeof instance === "object" && "operations" in instance && "cacheMap" in instance && typeof instance.cacheMap.invalidateItemKeys === "function";
|
|
1045
1095
|
}
|
|
1046
1096
|
var handleActionCacheInvalidation = async (registry, affectedItems) => {
|
|
1047
|
-
|
|
1097
|
+
logger9.debug("Handling action cache invalidation", {
|
|
1048
1098
|
affectedItemsCount: affectedItems.length
|
|
1049
1099
|
});
|
|
1050
1100
|
const { keys, keyTypeArrays } = extractKeysAndKeyTypesFromActionResult(affectedItems);
|
|
@@ -1052,33 +1102,33 @@ var handleActionCacheInvalidation = async (registry, affectedItems) => {
|
|
|
1052
1102
|
};
|
|
1053
1103
|
|
|
1054
1104
|
// src/ops/action.ts
|
|
1055
|
-
var
|
|
1105
|
+
var logger10 = logger_default.get("action");
|
|
1056
1106
|
var action = async (key, action2, body = {}, context) => {
|
|
1057
1107
|
const { api, cacheMap, pkType, registry } = context;
|
|
1058
|
-
|
|
1108
|
+
logger10.default("action", { key, action: action2, body });
|
|
1059
1109
|
if (!isValidItemKey5(key)) {
|
|
1060
|
-
|
|
1110
|
+
logger10.error("Key for Action is not a valid ItemKey: %j", key);
|
|
1061
1111
|
throw new Error("Key for Action is not a valid ItemKey");
|
|
1062
1112
|
}
|
|
1063
|
-
|
|
1113
|
+
logger10.debug("Invalidating item key before action", { key });
|
|
1064
1114
|
cacheMap.invalidateItemKeys([key]);
|
|
1065
1115
|
const result = await api.action(key, action2, body);
|
|
1066
1116
|
const updated = result[0];
|
|
1067
1117
|
const affectedItems = result[1];
|
|
1068
1118
|
if (affectedItems && affectedItems.length > 0) {
|
|
1069
|
-
|
|
1119
|
+
logger10.debug("Handling cache invalidation for affected items", {
|
|
1070
1120
|
affectedItemsCount: affectedItems.length
|
|
1071
1121
|
});
|
|
1072
1122
|
try {
|
|
1073
1123
|
await handleActionCacheInvalidation(registry, affectedItems);
|
|
1074
1124
|
} catch (error) {
|
|
1075
|
-
|
|
1125
|
+
logger10.warning("Failed to handle cache invalidation for affected items", {
|
|
1076
1126
|
error: error instanceof Error ? error.message : String(error),
|
|
1077
1127
|
affectedItems
|
|
1078
1128
|
});
|
|
1079
1129
|
}
|
|
1080
1130
|
}
|
|
1081
|
-
|
|
1131
|
+
logger10.debug("Caching action result", { updatedKey: updated.key });
|
|
1082
1132
|
cacheMap.set(updated.key, updated);
|
|
1083
1133
|
const keyStr = JSON.stringify(updated.key);
|
|
1084
1134
|
context.ttlManager.onItemAdded(keyStr, cacheMap);
|
|
@@ -1088,19 +1138,19 @@ var action = async (key, action2, body = {}, context) => {
|
|
|
1088
1138
|
const parsedKey = JSON.parse(evictedKey);
|
|
1089
1139
|
await cacheMap.delete(parsedKey);
|
|
1090
1140
|
} catch (error) {
|
|
1091
|
-
|
|
1141
|
+
logger10.error("Failed to parse evicted key during deletion", {
|
|
1092
1142
|
evictedKey,
|
|
1093
1143
|
error: error instanceof Error ? error.message : String(error)
|
|
1094
1144
|
});
|
|
1095
1145
|
}
|
|
1096
1146
|
}
|
|
1097
|
-
|
|
1147
|
+
logger10.debug("Emitting itemUpdated event after action", {
|
|
1098
1148
|
key: updated.key,
|
|
1099
1149
|
action: action2
|
|
1100
1150
|
});
|
|
1101
1151
|
const itemEvent = CacheEventFactory.itemUpdated(updated.key, updated, null, "api");
|
|
1102
1152
|
context.eventEmitter.emit(itemEvent);
|
|
1103
|
-
|
|
1153
|
+
logger10.debug("Emitting queryInvalidatedEvent after action", {
|
|
1104
1154
|
eventType: "query_invalidated",
|
|
1105
1155
|
reason: "item_changed",
|
|
1106
1156
|
action: action2
|
|
@@ -1120,10 +1170,11 @@ import {
|
|
|
1120
1170
|
validatePK as validatePK8
|
|
1121
1171
|
} from "@fjell/core";
|
|
1122
1172
|
import { NotFoundError as NotFoundError3 } from "@fjell/http-api";
|
|
1123
|
-
var
|
|
1173
|
+
var logger11 = logger_default.get("allAction");
|
|
1124
1174
|
var allAction = async (action2, body = {}, locations = [], context) => {
|
|
1125
|
-
const { api, cacheMap, pkType, eventEmitter, registry } = context;
|
|
1126
|
-
|
|
1175
|
+
const { api, cacheMap, pkType, eventEmitter, registry, coordinate } = context;
|
|
1176
|
+
logger11.default("allAction", { action: action2, body, locations });
|
|
1177
|
+
validateLocations(locations, coordinate, "allAction");
|
|
1127
1178
|
const existingItems = [];
|
|
1128
1179
|
if (locations && locations.length > 0) {
|
|
1129
1180
|
try {
|
|
@@ -1132,10 +1183,10 @@ var allAction = async (action2, body = {}, locations = [], context) => {
|
|
|
1132
1183
|
existingItems.push(...cachedItems);
|
|
1133
1184
|
}
|
|
1134
1185
|
} catch (error) {
|
|
1135
|
-
|
|
1186
|
+
logger11.debug("Could not retrieve existing items for comparison", { error });
|
|
1136
1187
|
}
|
|
1137
1188
|
}
|
|
1138
|
-
|
|
1189
|
+
logger11.debug("Invalidating location before allAction", { locations });
|
|
1139
1190
|
await cacheMap.invalidateLocation(locations);
|
|
1140
1191
|
let ret = [];
|
|
1141
1192
|
let affectedItems = [];
|
|
@@ -1145,7 +1196,7 @@ var allAction = async (action2, body = {}, locations = [], context) => {
|
|
|
1145
1196
|
ret = result[0];
|
|
1146
1197
|
affectedItems = result[1];
|
|
1147
1198
|
} else {
|
|
1148
|
-
|
|
1199
|
+
logger11.warning("Unexpected result format from allAction", {
|
|
1149
1200
|
resultType: typeof result,
|
|
1150
1201
|
isArray: Array.isArray(result),
|
|
1151
1202
|
resultLength: Array.isArray(result) ? result.length : "not array"
|
|
@@ -1154,19 +1205,19 @@ var allAction = async (action2, body = {}, locations = [], context) => {
|
|
|
1154
1205
|
affectedItems = [];
|
|
1155
1206
|
}
|
|
1156
1207
|
if (affectedItems && affectedItems.length > 0) {
|
|
1157
|
-
|
|
1208
|
+
logger11.debug("Handling cache invalidation for affected items", {
|
|
1158
1209
|
affectedItemsCount: affectedItems.length
|
|
1159
1210
|
});
|
|
1160
1211
|
try {
|
|
1161
1212
|
await handleActionCacheInvalidation(registry, affectedItems);
|
|
1162
1213
|
} catch (error) {
|
|
1163
|
-
|
|
1214
|
+
logger11.warning("Failed to handle cache invalidation for affected items", {
|
|
1164
1215
|
error: error instanceof Error ? error.message : String(error),
|
|
1165
1216
|
affectedItems
|
|
1166
1217
|
});
|
|
1167
1218
|
}
|
|
1168
1219
|
}
|
|
1169
|
-
|
|
1220
|
+
logger11.debug("Caching allAction results", { resultCount: ret.length });
|
|
1170
1221
|
const modifiedItems = [];
|
|
1171
1222
|
const newItems = [];
|
|
1172
1223
|
for (const v of ret) {
|
|
@@ -1188,7 +1239,7 @@ var allAction = async (action2, body = {}, locations = [], context) => {
|
|
|
1188
1239
|
}
|
|
1189
1240
|
}
|
|
1190
1241
|
for (const item of modifiedItems) {
|
|
1191
|
-
|
|
1242
|
+
logger11.debug("Emitting item_updated event for modified item", { key: item.key });
|
|
1192
1243
|
const itemEvent = CacheEventFactory.itemUpdated(
|
|
1193
1244
|
item.key,
|
|
1194
1245
|
item,
|
|
@@ -1199,7 +1250,7 @@ var allAction = async (action2, body = {}, locations = [], context) => {
|
|
|
1199
1250
|
eventEmitter.emit(itemEvent);
|
|
1200
1251
|
}
|
|
1201
1252
|
for (const item of newItems) {
|
|
1202
|
-
|
|
1253
|
+
logger11.debug("Emitting item_created event for new item", { key: item.key });
|
|
1203
1254
|
const itemEvent = CacheEventFactory.itemCreated(
|
|
1204
1255
|
item.key,
|
|
1205
1256
|
item,
|
|
@@ -1209,14 +1260,14 @@ var allAction = async (action2, body = {}, locations = [], context) => {
|
|
|
1209
1260
|
}
|
|
1210
1261
|
if (modifiedItems.length > 0) {
|
|
1211
1262
|
const modifiedKeys = modifiedItems.map((item) => item.key);
|
|
1212
|
-
|
|
1263
|
+
logger11.debug("Invalidating individual item keys for modified items", {
|
|
1213
1264
|
keyCount: modifiedKeys.length,
|
|
1214
1265
|
keys: modifiedKeys
|
|
1215
1266
|
});
|
|
1216
1267
|
await cacheMap.invalidateItemKeys(modifiedKeys);
|
|
1217
1268
|
}
|
|
1218
1269
|
await cacheMap.clearQueryResults();
|
|
1219
|
-
|
|
1270
|
+
logger11.debug("Emitting query_invalidated event after allAction", {
|
|
1220
1271
|
eventType: "query_invalidated",
|
|
1221
1272
|
reason: "item_changed",
|
|
1222
1273
|
action: action2,
|
|
@@ -1246,19 +1297,20 @@ var allAction = async (action2, body = {}, locations = [], context) => {
|
|
|
1246
1297
|
};
|
|
1247
1298
|
|
|
1248
1299
|
// src/ops/facet.ts
|
|
1249
|
-
var
|
|
1300
|
+
var logger12 = logger_default.get("facet");
|
|
1250
1301
|
var facet = async (key, facet2, params = {}, context) => {
|
|
1251
1302
|
const { api } = context;
|
|
1252
|
-
|
|
1303
|
+
logger12.default("facet", { key, facet: facet2 });
|
|
1253
1304
|
const ret = await api.facet(key, facet2, params);
|
|
1254
1305
|
return ret;
|
|
1255
1306
|
};
|
|
1256
1307
|
|
|
1257
1308
|
// src/ops/allFacet.ts
|
|
1258
|
-
var
|
|
1309
|
+
var logger13 = logger_default.get("allFacet");
|
|
1259
1310
|
var allFacet = async (facet2, params = {}, locations = [], context) => {
|
|
1260
|
-
const { api } = context;
|
|
1261
|
-
|
|
1311
|
+
const { api, coordinate } = context;
|
|
1312
|
+
logger13.default("allFacet", { facet: facet2, params, locations });
|
|
1313
|
+
validateLocations(locations, coordinate, "allFacet");
|
|
1262
1314
|
const ret = await api.allFacet(facet2, params, locations);
|
|
1263
1315
|
return ret;
|
|
1264
1316
|
};
|
|
@@ -1267,26 +1319,27 @@ var allFacet = async (facet2, params = {}, locations = [], context) => {
|
|
|
1267
1319
|
import {
|
|
1268
1320
|
validatePK as validatePK9
|
|
1269
1321
|
} from "@fjell/core";
|
|
1270
|
-
var
|
|
1322
|
+
var logger14 = logger_default.get("find");
|
|
1271
1323
|
var find = async (finder, params = {}, locations = [], context) => {
|
|
1272
|
-
const { api, cacheMap, pkType, ttlManager, eventEmitter } = context;
|
|
1273
|
-
|
|
1324
|
+
const { api, cacheMap, pkType, ttlManager, eventEmitter, coordinate } = context;
|
|
1325
|
+
logger14.default("find", { finder, params, locations });
|
|
1326
|
+
validateLocations(locations, coordinate, "find");
|
|
1274
1327
|
if (context.options?.bypassCache) {
|
|
1275
|
-
|
|
1328
|
+
logger14.debug("Cache bypass enabled, fetching directly from API", { finder, params, locations });
|
|
1276
1329
|
try {
|
|
1277
1330
|
const ret2 = await api.find(finder, params, locations);
|
|
1278
|
-
|
|
1331
|
+
logger14.debug("API response received (not cached due to bypass)", { finder, params, locations, itemCount: ret2.length });
|
|
1279
1332
|
return [context, validatePK9(ret2, pkType)];
|
|
1280
1333
|
} catch (error) {
|
|
1281
|
-
|
|
1334
|
+
logger14.error("API request failed", { finder, params, locations, error });
|
|
1282
1335
|
throw error;
|
|
1283
1336
|
}
|
|
1284
1337
|
}
|
|
1285
1338
|
const queryHash = createFinderHash(finder, params, locations);
|
|
1286
|
-
|
|
1339
|
+
logger14.debug("Generated query hash for find", { queryHash, finder, params, locations });
|
|
1287
1340
|
const cachedItemKeys = await cacheMap.getQueryResult(queryHash);
|
|
1288
1341
|
if (cachedItemKeys) {
|
|
1289
|
-
|
|
1342
|
+
logger14.debug("Using cached query results", { cachedKeyCount: cachedItemKeys.length, queryHash });
|
|
1290
1343
|
const cachedItems = [];
|
|
1291
1344
|
let allItemsAvailable = true;
|
|
1292
1345
|
for (const itemKey of cachedItemKeys) {
|
|
@@ -1301,7 +1354,7 @@ var find = async (finder, params = {}, locations = [], context) => {
|
|
|
1301
1354
|
if (allItemsAvailable) {
|
|
1302
1355
|
return [context, validatePK9(cachedItems, pkType)];
|
|
1303
1356
|
} else {
|
|
1304
|
-
|
|
1357
|
+
logger14.debug("Some cached items missing, invalidating query cache");
|
|
1305
1358
|
cacheMap.deleteQueryResult(queryHash);
|
|
1306
1359
|
}
|
|
1307
1360
|
}
|
|
@@ -1318,7 +1371,7 @@ var find = async (finder, params = {}, locations = [], context) => {
|
|
|
1318
1371
|
}
|
|
1319
1372
|
const itemKeys = ret.map((item) => item.key);
|
|
1320
1373
|
cacheMap.setQueryResult(queryHash, itemKeys);
|
|
1321
|
-
|
|
1374
|
+
logger14.debug("Cached query result", { queryHash, itemKeyCount: itemKeys.length });
|
|
1322
1375
|
const event = CacheEventFactory.createQueryEvent(params, locations, ret);
|
|
1323
1376
|
eventEmitter.emit(event);
|
|
1324
1377
|
return [context, validatePK9(ret, pkType)];
|
|
@@ -1328,31 +1381,32 @@ var find = async (finder, params = {}, locations = [], context) => {
|
|
|
1328
1381
|
import {
|
|
1329
1382
|
validatePK as validatePK10
|
|
1330
1383
|
} from "@fjell/core";
|
|
1331
|
-
var
|
|
1384
|
+
var logger15 = logger_default.get("findOne");
|
|
1332
1385
|
var findOne = async (finder, finderParams = {}, locations = [], context) => {
|
|
1333
|
-
const { api, cacheMap, pkType, ttlManager, eventEmitter } = context;
|
|
1334
|
-
|
|
1386
|
+
const { api, cacheMap, pkType, ttlManager, eventEmitter, coordinate } = context;
|
|
1387
|
+
logger15.default("findOne", { finder, finderParams, locations });
|
|
1388
|
+
validateLocations(locations, coordinate, "findOne");
|
|
1335
1389
|
if (context.options?.bypassCache) {
|
|
1336
|
-
|
|
1390
|
+
logger15.debug("Cache bypass enabled, fetching directly from API", { finder, finderParams, locations });
|
|
1337
1391
|
try {
|
|
1338
1392
|
const ret2 = await api.findOne(finder, finderParams, locations);
|
|
1339
|
-
|
|
1393
|
+
logger15.debug("API response received (not cached due to bypass)", { finder, finderParams, locations });
|
|
1340
1394
|
return [context, validatePK10(ret2, pkType)];
|
|
1341
1395
|
} catch (error) {
|
|
1342
|
-
|
|
1396
|
+
logger15.error("API request failed", { finder, finderParams, locations, error });
|
|
1343
1397
|
throw error;
|
|
1344
1398
|
}
|
|
1345
1399
|
}
|
|
1346
1400
|
const queryHash = createFinderHash(finder, finderParams, locations);
|
|
1347
|
-
|
|
1401
|
+
logger15.debug("Generated query hash for findOne", { queryHash });
|
|
1348
1402
|
const cachedItemKeys = await cacheMap.getQueryResult(queryHash);
|
|
1349
1403
|
if (cachedItemKeys && cachedItemKeys.length > 0) {
|
|
1350
|
-
|
|
1404
|
+
logger15.debug("Using cached query results", { cachedKeyCount: cachedItemKeys.length });
|
|
1351
1405
|
const item = await cacheMap.get(cachedItemKeys[0]);
|
|
1352
1406
|
if (item) {
|
|
1353
1407
|
return [context, validatePK10(item, pkType)];
|
|
1354
1408
|
} else {
|
|
1355
|
-
|
|
1409
|
+
logger15.debug("Cached item missing, invalidating query cache");
|
|
1356
1410
|
cacheMap.deleteQueryResult(queryHash);
|
|
1357
1411
|
}
|
|
1358
1412
|
}
|
|
@@ -1366,7 +1420,7 @@ var findOne = async (finder, finderParams = {}, locations = [], context) => {
|
|
|
1366
1420
|
await cacheMap.delete(parsedKey);
|
|
1367
1421
|
}
|
|
1368
1422
|
cacheMap.setQueryResult(queryHash, [ret.key]);
|
|
1369
|
-
|
|
1423
|
+
logger15.debug("Cached query result", { queryHash, itemKey: ret.key });
|
|
1370
1424
|
const event = CacheEventFactory.createQueryEvent(finderParams, locations, [ret]);
|
|
1371
1425
|
eventEmitter.emit(event);
|
|
1372
1426
|
return [context, validatePK10(ret, pkType)];
|
|
@@ -1378,7 +1432,7 @@ import {
|
|
|
1378
1432
|
isValidItemKey as isValidItemKey6,
|
|
1379
1433
|
validatePK as validatePK11
|
|
1380
1434
|
} from "@fjell/core";
|
|
1381
|
-
var
|
|
1435
|
+
var logger16 = logger_default.get("set");
|
|
1382
1436
|
var normalizeKeyValue2 = (value) => {
|
|
1383
1437
|
return String(value);
|
|
1384
1438
|
};
|
|
@@ -1428,14 +1482,14 @@ var normalizeKey = (key) => {
|
|
|
1428
1482
|
};
|
|
1429
1483
|
var set = async (key, v, context) => {
|
|
1430
1484
|
const { cacheMap, pkType, ttlManager, evictionManager, eventEmitter } = context;
|
|
1431
|
-
|
|
1485
|
+
logger16.default("set", { key, v });
|
|
1432
1486
|
if (!isValidItemKey6(key)) {
|
|
1433
|
-
|
|
1487
|
+
logger16.error("Key for Set is not a valid ItemKey: %j", key);
|
|
1434
1488
|
throw new Error("Key for Set is not a valid ItemKey");
|
|
1435
1489
|
}
|
|
1436
1490
|
validatePK11(v, pkType);
|
|
1437
1491
|
if (!isItemKeyEqualNormalized(key, v.key)) {
|
|
1438
|
-
|
|
1492
|
+
logger16.error("Key does not match item key: %j != %j", key, v.key);
|
|
1439
1493
|
throw new Error("Key does not match item key");
|
|
1440
1494
|
}
|
|
1441
1495
|
const previousItem = await cacheMap.get(key);
|
|
@@ -1479,7 +1533,7 @@ var CacheMap = class {
|
|
|
1479
1533
|
};
|
|
1480
1534
|
|
|
1481
1535
|
// src/memory/MemoryCacheMap.ts
|
|
1482
|
-
var
|
|
1536
|
+
var logger17 = logger_default.get("MemoryCacheMap");
|
|
1483
1537
|
var MemoryCacheMap = class _MemoryCacheMap extends CacheMap {
|
|
1484
1538
|
implementationType = "memory/memory";
|
|
1485
1539
|
map = {};
|
|
@@ -1497,13 +1551,13 @@ var MemoryCacheMap = class _MemoryCacheMap extends CacheMap {
|
|
|
1497
1551
|
const key = JSON.parse(keyStr);
|
|
1498
1552
|
this.set(key, value);
|
|
1499
1553
|
} catch (error) {
|
|
1500
|
-
|
|
1554
|
+
logger17.error("Failed to parse initial data key", { keyStr, error });
|
|
1501
1555
|
}
|
|
1502
1556
|
}
|
|
1503
1557
|
}
|
|
1504
1558
|
}
|
|
1505
1559
|
async get(key) {
|
|
1506
|
-
|
|
1560
|
+
logger17.trace("get", { key });
|
|
1507
1561
|
const hashedKey = this.normalizedHashFunction(key);
|
|
1508
1562
|
const entry = this.map[hashedKey];
|
|
1509
1563
|
if (entry && this.normalizedHashFunction(entry.originalKey) === hashedKey) {
|
|
@@ -1518,7 +1572,7 @@ var MemoryCacheMap = class _MemoryCacheMap extends CacheMap {
|
|
|
1518
1572
|
return null;
|
|
1519
1573
|
}
|
|
1520
1574
|
async set(key, value) {
|
|
1521
|
-
|
|
1575
|
+
logger17.trace("set", { key, value });
|
|
1522
1576
|
const hashedKey = this.normalizedHashFunction(key);
|
|
1523
1577
|
const keyStr = JSON.stringify(key);
|
|
1524
1578
|
this.map[hashedKey] = { originalKey: key, value };
|
|
@@ -1545,7 +1599,7 @@ var MemoryCacheMap = class _MemoryCacheMap extends CacheMap {
|
|
|
1545
1599
|
return !!entry && this.normalizedHashFunction(entry.originalKey) === hashedKey;
|
|
1546
1600
|
}
|
|
1547
1601
|
async delete(key) {
|
|
1548
|
-
|
|
1602
|
+
logger17.trace("delete", { key });
|
|
1549
1603
|
const hashedKey = this.normalizedHashFunction(key);
|
|
1550
1604
|
const entry = this.map[hashedKey];
|
|
1551
1605
|
if (entry && this.normalizedHashFunction(entry.originalKey) === hashedKey) {
|
|
@@ -1574,10 +1628,10 @@ var MemoryCacheMap = class _MemoryCacheMap extends CacheMap {
|
|
|
1574
1628
|
async allIn(locations) {
|
|
1575
1629
|
const allValues = await this.values();
|
|
1576
1630
|
if (locations.length === 0) {
|
|
1577
|
-
|
|
1631
|
+
logger17.debug("Returning all items, LocKeys is empty");
|
|
1578
1632
|
return allValues;
|
|
1579
1633
|
} else {
|
|
1580
|
-
|
|
1634
|
+
logger17.debug("allIn", { locations, count: allValues.length });
|
|
1581
1635
|
return allValues.filter((item) => {
|
|
1582
1636
|
const key = item.key;
|
|
1583
1637
|
if (key && isComKey(key)) {
|
|
@@ -1589,12 +1643,12 @@ var MemoryCacheMap = class _MemoryCacheMap extends CacheMap {
|
|
|
1589
1643
|
}
|
|
1590
1644
|
}
|
|
1591
1645
|
async contains(query, locations) {
|
|
1592
|
-
|
|
1646
|
+
logger17.debug("contains", { query, locations });
|
|
1593
1647
|
const items = await this.allIn(locations);
|
|
1594
1648
|
return items.some((item) => isQueryMatch(item, query));
|
|
1595
1649
|
}
|
|
1596
1650
|
async queryIn(query, locations = []) {
|
|
1597
|
-
|
|
1651
|
+
logger17.debug("queryIn", { query, locations });
|
|
1598
1652
|
const items = await this.allIn(locations);
|
|
1599
1653
|
return items.filter((item) => isQueryMatch(item, query));
|
|
1600
1654
|
}
|
|
@@ -1617,7 +1671,7 @@ var MemoryCacheMap = class _MemoryCacheMap extends CacheMap {
|
|
|
1617
1671
|
}
|
|
1618
1672
|
// Query result caching methods implementation
|
|
1619
1673
|
async setQueryResult(queryHash, itemKeys) {
|
|
1620
|
-
|
|
1674
|
+
logger17.trace("setQueryResult", { queryHash, itemKeys });
|
|
1621
1675
|
const entry = {
|
|
1622
1676
|
itemKeys: [...itemKeys]
|
|
1623
1677
|
// Create a copy to avoid external mutations
|
|
@@ -1625,7 +1679,7 @@ var MemoryCacheMap = class _MemoryCacheMap extends CacheMap {
|
|
|
1625
1679
|
this.queryResultCache[queryHash] = entry;
|
|
1626
1680
|
}
|
|
1627
1681
|
async getQueryResult(queryHash) {
|
|
1628
|
-
|
|
1682
|
+
logger17.trace("getQueryResult", { queryHash });
|
|
1629
1683
|
const entry = this.queryResultCache[queryHash];
|
|
1630
1684
|
if (!entry) {
|
|
1631
1685
|
return null;
|
|
@@ -1637,11 +1691,11 @@ var MemoryCacheMap = class _MemoryCacheMap extends CacheMap {
|
|
|
1637
1691
|
return !!entry;
|
|
1638
1692
|
}
|
|
1639
1693
|
async deleteQueryResult(queryHash) {
|
|
1640
|
-
|
|
1694
|
+
logger17.trace("deleteQueryResult", { queryHash });
|
|
1641
1695
|
delete this.queryResultCache[queryHash];
|
|
1642
1696
|
}
|
|
1643
1697
|
async invalidateItemKeys(keys) {
|
|
1644
|
-
|
|
1698
|
+
logger17.debug("invalidateItemKeys", { keys });
|
|
1645
1699
|
if (keys.length === 0) {
|
|
1646
1700
|
return;
|
|
1647
1701
|
}
|
|
@@ -1672,14 +1726,14 @@ var MemoryCacheMap = class _MemoryCacheMap extends CacheMap {
|
|
|
1672
1726
|
queriesToRemove.forEach((queryHash) => {
|
|
1673
1727
|
this.deleteQueryResult(queryHash);
|
|
1674
1728
|
});
|
|
1675
|
-
|
|
1729
|
+
logger17.debug("Selectively invalidated queries referencing affected keys", {
|
|
1676
1730
|
affectedKeys: keys.length,
|
|
1677
1731
|
queriesRemoved: queriesToRemove.length,
|
|
1678
1732
|
totalQueries: Object.keys(this.queryResultCache).length
|
|
1679
1733
|
});
|
|
1680
1734
|
}
|
|
1681
1735
|
async invalidateLocation(locations) {
|
|
1682
|
-
|
|
1736
|
+
logger17.debug("invalidateLocation", { locations });
|
|
1683
1737
|
let keysToInvalidate = [];
|
|
1684
1738
|
if (locations.length === 0) {
|
|
1685
1739
|
const allKeys = await this.keys();
|
|
@@ -1692,7 +1746,7 @@ var MemoryCacheMap = class _MemoryCacheMap extends CacheMap {
|
|
|
1692
1746
|
await this.invalidateItemKeys(keysToInvalidate);
|
|
1693
1747
|
}
|
|
1694
1748
|
async clearQueryResults() {
|
|
1695
|
-
|
|
1749
|
+
logger17.trace("clearQueryResults");
|
|
1696
1750
|
this.queryResultCache = {};
|
|
1697
1751
|
}
|
|
1698
1752
|
// CacheMapMetadataProvider implementation
|
|
@@ -1734,7 +1788,7 @@ import {
|
|
|
1734
1788
|
isComKey as isComKey2,
|
|
1735
1789
|
isQueryMatch as isQueryMatch2
|
|
1736
1790
|
} from "@fjell/core";
|
|
1737
|
-
var
|
|
1791
|
+
var logger18 = logger_default.get("EnhancedMemoryCacheMap");
|
|
1738
1792
|
var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
1739
1793
|
implementationType = "memory/enhanced";
|
|
1740
1794
|
map = {};
|
|
@@ -1753,11 +1807,11 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
1753
1807
|
this.normalizedHashFunction = createNormalizedHashFunction();
|
|
1754
1808
|
if (sizeConfig?.maxSizeBytes) {
|
|
1755
1809
|
this.maxSizeBytes = parseSizeString(sizeConfig.maxSizeBytes);
|
|
1756
|
-
|
|
1810
|
+
logger18.debug("Cache size limit set", { maxSizeBytes: this.maxSizeBytes });
|
|
1757
1811
|
}
|
|
1758
1812
|
if (sizeConfig?.maxItems) {
|
|
1759
1813
|
this.maxItems = sizeConfig.maxItems;
|
|
1760
|
-
|
|
1814
|
+
logger18.debug("Cache item limit set", { maxItems: this.maxItems });
|
|
1761
1815
|
}
|
|
1762
1816
|
if (initialData) {
|
|
1763
1817
|
for (const [keyStr, value] of Object.entries(initialData)) {
|
|
@@ -1765,13 +1819,13 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
1765
1819
|
const key = JSON.parse(keyStr);
|
|
1766
1820
|
this.set(key, value);
|
|
1767
1821
|
} catch (error) {
|
|
1768
|
-
|
|
1822
|
+
logger18.error("Failed to parse initial data key", { keyStr, error });
|
|
1769
1823
|
}
|
|
1770
1824
|
}
|
|
1771
1825
|
}
|
|
1772
1826
|
}
|
|
1773
1827
|
async get(key) {
|
|
1774
|
-
|
|
1828
|
+
logger18.trace("get", { key });
|
|
1775
1829
|
const hashedKey = this.normalizedHashFunction(key);
|
|
1776
1830
|
const entry = this.map[hashedKey];
|
|
1777
1831
|
if (entry && this.normalizedHashFunction(entry.originalKey) === hashedKey && entry.value !== null) {
|
|
@@ -1780,7 +1834,7 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
1780
1834
|
return null;
|
|
1781
1835
|
}
|
|
1782
1836
|
async set(key, value) {
|
|
1783
|
-
|
|
1837
|
+
logger18.trace("set", { key, value });
|
|
1784
1838
|
const hashedKey = this.normalizedHashFunction(key);
|
|
1785
1839
|
const estimatedSize = estimateValueSize(value);
|
|
1786
1840
|
const existingEntry = this.map[hashedKey];
|
|
@@ -1791,7 +1845,7 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
1791
1845
|
const oldValue = existingEntry.value;
|
|
1792
1846
|
existingEntry.value = value;
|
|
1793
1847
|
existingEntry.metadata.estimatedSize = estimatedSize;
|
|
1794
|
-
|
|
1848
|
+
logger18.trace("Updated existing cache entry", {
|
|
1795
1849
|
key: hashedKey,
|
|
1796
1850
|
sizeDiff,
|
|
1797
1851
|
currentSize: this.currentSizeBytes,
|
|
@@ -1812,7 +1866,7 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
1812
1866
|
};
|
|
1813
1867
|
this.currentSizeBytes += estimatedSize;
|
|
1814
1868
|
this.currentItemCount++;
|
|
1815
|
-
|
|
1869
|
+
logger18.trace("Added new cache entry", {
|
|
1816
1870
|
key: hashedKey,
|
|
1817
1871
|
size: estimatedSize,
|
|
1818
1872
|
currentSize: this.currentSizeBytes,
|
|
@@ -1829,14 +1883,14 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
1829
1883
|
this.deleteInternal(key, true, "filter");
|
|
1830
1884
|
}
|
|
1831
1885
|
deleteInternal(key, invalidateQueries = false, invalidationMode = "remove") {
|
|
1832
|
-
|
|
1886
|
+
logger18.trace("delete", { key });
|
|
1833
1887
|
const hashedKey = this.normalizedHashFunction(key);
|
|
1834
1888
|
const entry = this.map[hashedKey];
|
|
1835
1889
|
if (entry && this.normalizedHashFunction(entry.originalKey) === hashedKey) {
|
|
1836
1890
|
this.currentSizeBytes -= entry.metadata.estimatedSize;
|
|
1837
1891
|
this.currentItemCount--;
|
|
1838
1892
|
delete this.map[hashedKey];
|
|
1839
|
-
|
|
1893
|
+
logger18.trace("Deleted cache entry", {
|
|
1840
1894
|
key: hashedKey,
|
|
1841
1895
|
freedSize: entry.metadata.estimatedSize,
|
|
1842
1896
|
currentSize: this.currentSizeBytes,
|
|
@@ -1858,7 +1912,7 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
1858
1912
|
return Object.values(this.map).filter((entry) => entry.value !== null).map((entry) => entry.value);
|
|
1859
1913
|
}
|
|
1860
1914
|
async clear() {
|
|
1861
|
-
|
|
1915
|
+
logger18.debug("Clearing cache", {
|
|
1862
1916
|
itemsCleared: this.currentItemCount,
|
|
1863
1917
|
bytesFreed: this.currentSizeBytes
|
|
1864
1918
|
});
|
|
@@ -1869,10 +1923,10 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
1869
1923
|
async allIn(locations) {
|
|
1870
1924
|
const allValues = await this.values();
|
|
1871
1925
|
if (locations.length === 0) {
|
|
1872
|
-
|
|
1926
|
+
logger18.debug("Returning all items, LocKeys is empty");
|
|
1873
1927
|
return allValues;
|
|
1874
1928
|
} else {
|
|
1875
|
-
|
|
1929
|
+
logger18.debug("allIn", { locations, count: allValues.length });
|
|
1876
1930
|
return allValues.filter((item) => {
|
|
1877
1931
|
const key = item.key;
|
|
1878
1932
|
if (key && isComKey2(key)) {
|
|
@@ -1883,12 +1937,12 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
1883
1937
|
}
|
|
1884
1938
|
}
|
|
1885
1939
|
async contains(query, locations) {
|
|
1886
|
-
|
|
1940
|
+
logger18.debug("contains", { query, locations });
|
|
1887
1941
|
const items = await this.allIn(locations);
|
|
1888
1942
|
return items.some((item) => isQueryMatch2(item, query));
|
|
1889
1943
|
}
|
|
1890
1944
|
async queryIn(query, locations = []) {
|
|
1891
|
-
|
|
1945
|
+
logger18.debug("queryIn", { query, locations });
|
|
1892
1946
|
const items = await this.allIn(locations);
|
|
1893
1947
|
return items.filter((item) => isQueryMatch2(item, query));
|
|
1894
1948
|
}
|
|
@@ -1934,7 +1988,7 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
1934
1988
|
}
|
|
1935
1989
|
// Query result caching methods
|
|
1936
1990
|
async setQueryResult(queryHash, itemKeys) {
|
|
1937
|
-
|
|
1991
|
+
logger18.trace("setQueryResult", { queryHash, itemKeys });
|
|
1938
1992
|
if (queryHash in this.queryResultCache) {
|
|
1939
1993
|
this.removeQueryResultFromSizeTracking(queryHash);
|
|
1940
1994
|
}
|
|
@@ -1946,7 +2000,7 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
1946
2000
|
this.addQueryResultToSizeTracking(queryHash, entry);
|
|
1947
2001
|
}
|
|
1948
2002
|
async getQueryResult(queryHash) {
|
|
1949
|
-
|
|
2003
|
+
logger18.trace("getQueryResult", { queryHash });
|
|
1950
2004
|
const entry = this.queryResultCache[queryHash];
|
|
1951
2005
|
if (!entry) {
|
|
1952
2006
|
return null;
|
|
@@ -1968,7 +2022,7 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
1968
2022
|
this.queryResultsCacheSize = 0;
|
|
1969
2023
|
}
|
|
1970
2024
|
async invalidateItemKeys(keys) {
|
|
1971
|
-
|
|
2025
|
+
logger18.debug("invalidateItemKeys", { keys });
|
|
1972
2026
|
if (keys.length === 0) {
|
|
1973
2027
|
return;
|
|
1974
2028
|
}
|
|
@@ -2018,7 +2072,7 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
2018
2072
|
});
|
|
2019
2073
|
}
|
|
2020
2074
|
async invalidateLocation(locations) {
|
|
2021
|
-
|
|
2075
|
+
logger18.debug("invalidateLocation", { locations });
|
|
2022
2076
|
let keysToInvalidate = [];
|
|
2023
2077
|
if (locations.length === 0) {
|
|
2024
2078
|
const allKeys = await this.keys();
|
|
@@ -2038,7 +2092,7 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
2038
2092
|
const itemKeysSize = estimateValueSize(entry.itemKeys);
|
|
2039
2093
|
const totalSize = hashSize + itemKeysSize;
|
|
2040
2094
|
this.queryResultsCacheSize += totalSize;
|
|
2041
|
-
|
|
2095
|
+
logger18.trace("Added query result to size tracking", {
|
|
2042
2096
|
queryHash,
|
|
2043
2097
|
estimatedSize: totalSize,
|
|
2044
2098
|
totalQueryCacheSize: this.queryResultsCacheSize
|
|
@@ -2054,7 +2108,7 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
2054
2108
|
const itemKeysSize = estimateValueSize(entry.itemKeys);
|
|
2055
2109
|
const totalSize = hashSize + itemKeysSize;
|
|
2056
2110
|
this.queryResultsCacheSize = Math.max(0, this.queryResultsCacheSize - totalSize);
|
|
2057
|
-
|
|
2111
|
+
logger18.trace("Removed query result from size tracking", {
|
|
2058
2112
|
queryHash,
|
|
2059
2113
|
estimatedSize: totalSize,
|
|
2060
2114
|
totalQueryCacheSize: this.queryResultsCacheSize
|
|
@@ -2139,7 +2193,7 @@ import {
|
|
|
2139
2193
|
isComKey as isComKey3,
|
|
2140
2194
|
isQueryMatch as isQueryMatch3
|
|
2141
2195
|
} from "@fjell/core";
|
|
2142
|
-
var
|
|
2196
|
+
var logger19 = logger_default.get("LocalStorageCacheMap");
|
|
2143
2197
|
var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
2144
2198
|
implementationType = "browser/localStorage";
|
|
2145
2199
|
keyPrefix;
|
|
@@ -2170,7 +2224,7 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2170
2224
|
}
|
|
2171
2225
|
return keys;
|
|
2172
2226
|
} catch (error) {
|
|
2173
|
-
|
|
2227
|
+
logger19.error("Error getting keys by prefix from localStorage", { prefix, error });
|
|
2174
2228
|
throw error;
|
|
2175
2229
|
}
|
|
2176
2230
|
}
|
|
@@ -2178,12 +2232,12 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2178
2232
|
try {
|
|
2179
2233
|
const allEntries = this.collectCacheEntries();
|
|
2180
2234
|
if (allEntries.length === 0) {
|
|
2181
|
-
|
|
2235
|
+
logger19.debug("No entries to clean up");
|
|
2182
2236
|
return false;
|
|
2183
2237
|
}
|
|
2184
2238
|
return this.removeOldestEntries(allEntries, aggressive);
|
|
2185
2239
|
} catch (error) {
|
|
2186
|
-
|
|
2240
|
+
logger19.error("Failed to cleanup old localStorage entries", { error });
|
|
2187
2241
|
return false;
|
|
2188
2242
|
}
|
|
2189
2243
|
}
|
|
@@ -2209,7 +2263,7 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2209
2263
|
}
|
|
2210
2264
|
}
|
|
2211
2265
|
} catch (error) {
|
|
2212
|
-
|
|
2266
|
+
logger19.debug("Found corrupted entry during cleanup", { key, error });
|
|
2213
2267
|
allEntries.push({ key, timestamp: 0, size: 0 });
|
|
2214
2268
|
}
|
|
2215
2269
|
}
|
|
@@ -2228,12 +2282,12 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2228
2282
|
removedCount++;
|
|
2229
2283
|
removedSize += allEntries[i].size;
|
|
2230
2284
|
} catch (error) {
|
|
2231
|
-
|
|
2285
|
+
logger19.error("Failed to remove entry during cleanup", { key: allEntries[i].key, error });
|
|
2232
2286
|
}
|
|
2233
2287
|
}
|
|
2234
2288
|
if (removedCount > 0) {
|
|
2235
2289
|
const cleanupType = aggressive ? "aggressive" : "normal";
|
|
2236
|
-
|
|
2290
|
+
logger19.info(`Cleaned up ${removedCount} old localStorage entries (${removedSize} bytes) using ${cleanupType} cleanup to free space`);
|
|
2237
2291
|
}
|
|
2238
2292
|
return removedCount > 0;
|
|
2239
2293
|
}
|
|
@@ -2241,7 +2295,7 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2241
2295
|
return this.getAllKeysStartingWith(`${this.keyPrefix}:`);
|
|
2242
2296
|
}
|
|
2243
2297
|
async get(key) {
|
|
2244
|
-
|
|
2298
|
+
logger19.trace("get", { key });
|
|
2245
2299
|
try {
|
|
2246
2300
|
const storageKey = this.getStorageKey(key);
|
|
2247
2301
|
let stored = localStorage.getItem(storageKey);
|
|
@@ -2256,18 +2310,18 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2256
2310
|
return parsed.value;
|
|
2257
2311
|
}
|
|
2258
2312
|
} catch (parseError) {
|
|
2259
|
-
|
|
2313
|
+
logger19.debug("Failed to parse stored value", { key, error: parseError });
|
|
2260
2314
|
return null;
|
|
2261
2315
|
}
|
|
2262
2316
|
}
|
|
2263
2317
|
return null;
|
|
2264
2318
|
} catch (error) {
|
|
2265
|
-
|
|
2319
|
+
logger19.error("Error retrieving from localStorage", { key, error });
|
|
2266
2320
|
return null;
|
|
2267
2321
|
}
|
|
2268
2322
|
}
|
|
2269
2323
|
async set(key, value) {
|
|
2270
|
-
|
|
2324
|
+
logger19.trace("set", { key, value });
|
|
2271
2325
|
for (let attempt = 0; attempt < this.MAX_RETRY_ATTEMPTS; attempt++) {
|
|
2272
2326
|
try {
|
|
2273
2327
|
const storageKey = this.getStorageKey(key);
|
|
@@ -2278,12 +2332,12 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2278
2332
|
};
|
|
2279
2333
|
localStorage.setItem(storageKey, JSON.stringify(toStore));
|
|
2280
2334
|
if (attempt > 0) {
|
|
2281
|
-
|
|
2335
|
+
logger19.info(`Successfully stored item after ${attempt} retries`);
|
|
2282
2336
|
}
|
|
2283
2337
|
return;
|
|
2284
2338
|
} catch (error) {
|
|
2285
2339
|
const isLastAttempt = attempt === this.MAX_RETRY_ATTEMPTS - 1;
|
|
2286
|
-
|
|
2340
|
+
logger19.error(`Error storing to localStorage (attempt ${attempt + 1}/${this.MAX_RETRY_ATTEMPTS})`, {
|
|
2287
2341
|
key,
|
|
2288
2342
|
value,
|
|
2289
2343
|
error,
|
|
@@ -2310,30 +2364,30 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2310
2364
|
const parsed = JSON.parse(stored);
|
|
2311
2365
|
return this.normalizedHashFunction(parsed.originalKey) === this.normalizedHashFunction(key);
|
|
2312
2366
|
} catch (parseError) {
|
|
2313
|
-
|
|
2367
|
+
logger19.debug("Failed to parse stored value in includesKey", { key, error: parseError });
|
|
2314
2368
|
return false;
|
|
2315
2369
|
}
|
|
2316
2370
|
}
|
|
2317
2371
|
return false;
|
|
2318
2372
|
} catch (error) {
|
|
2319
|
-
|
|
2373
|
+
logger19.error("Error checking key in localStorage", { key, error });
|
|
2320
2374
|
return false;
|
|
2321
2375
|
}
|
|
2322
2376
|
}
|
|
2323
2377
|
async delete(key) {
|
|
2324
|
-
|
|
2378
|
+
logger19.trace("delete", { key });
|
|
2325
2379
|
try {
|
|
2326
2380
|
const storageKey = this.getStorageKey(key);
|
|
2327
2381
|
localStorage.removeItem(storageKey);
|
|
2328
2382
|
} catch (error) {
|
|
2329
|
-
|
|
2383
|
+
logger19.error("Error deleting from localStorage", { key, error });
|
|
2330
2384
|
throw error;
|
|
2331
2385
|
}
|
|
2332
2386
|
}
|
|
2333
2387
|
async allIn(locations) {
|
|
2334
2388
|
const allKeys = this.keys();
|
|
2335
2389
|
if (locations.length === 0) {
|
|
2336
|
-
|
|
2390
|
+
logger19.debug("Returning all items, LocKeys is empty");
|
|
2337
2391
|
const items = [];
|
|
2338
2392
|
for (const key of await allKeys) {
|
|
2339
2393
|
const item = await this.get(key);
|
|
@@ -2345,10 +2399,10 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2345
2399
|
} else {
|
|
2346
2400
|
const locKeys = locations;
|
|
2347
2401
|
const resolvedKeys = await allKeys;
|
|
2348
|
-
|
|
2402
|
+
logger19.debug("allIn", { locKeys, keys: resolvedKeys.length });
|
|
2349
2403
|
const filteredKeys = resolvedKeys.filter((key) => key && isComKey3(key)).filter((key) => {
|
|
2350
2404
|
const ComKey15 = key;
|
|
2351
|
-
|
|
2405
|
+
logger19.debug("Comparing Location Keys", {
|
|
2352
2406
|
locKeys,
|
|
2353
2407
|
ComKey: ComKey15
|
|
2354
2408
|
});
|
|
@@ -2365,12 +2419,12 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2365
2419
|
}
|
|
2366
2420
|
}
|
|
2367
2421
|
async contains(query, locations) {
|
|
2368
|
-
|
|
2422
|
+
logger19.debug("contains", { query, locations });
|
|
2369
2423
|
const items = await this.allIn(locations);
|
|
2370
2424
|
return items.some((item) => isQueryMatch3(item, query));
|
|
2371
2425
|
}
|
|
2372
2426
|
async queryIn(query, locations = []) {
|
|
2373
|
-
|
|
2427
|
+
logger19.debug("queryIn", { query, locations });
|
|
2374
2428
|
const items = await this.allIn(locations);
|
|
2375
2429
|
return items.filter((item) => isQueryMatch3(item, query));
|
|
2376
2430
|
}
|
|
@@ -2384,7 +2438,7 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2384
2438
|
return JSON.parse(stored);
|
|
2385
2439
|
}
|
|
2386
2440
|
} catch (parseError) {
|
|
2387
|
-
|
|
2441
|
+
logger19.debug("Skipping corrupted localStorage entry", { storageKey, error: parseError });
|
|
2388
2442
|
}
|
|
2389
2443
|
return null;
|
|
2390
2444
|
}
|
|
@@ -2399,7 +2453,7 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2399
2453
|
}
|
|
2400
2454
|
}
|
|
2401
2455
|
} catch (error) {
|
|
2402
|
-
|
|
2456
|
+
logger19.error("Error getting keys from localStorage", { error });
|
|
2403
2457
|
}
|
|
2404
2458
|
return keys;
|
|
2405
2459
|
}
|
|
@@ -2414,25 +2468,25 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2414
2468
|
}
|
|
2415
2469
|
}
|
|
2416
2470
|
} catch (error) {
|
|
2417
|
-
|
|
2471
|
+
logger19.error("Error getting values from localStorage", { error });
|
|
2418
2472
|
}
|
|
2419
2473
|
return values;
|
|
2420
2474
|
}
|
|
2421
2475
|
async clear() {
|
|
2422
|
-
|
|
2476
|
+
logger19.debug("Clearing localStorage cache");
|
|
2423
2477
|
try {
|
|
2424
2478
|
const storageKeys = this.getAllStorageKeys();
|
|
2425
2479
|
for (const storageKey of storageKeys) {
|
|
2426
2480
|
localStorage.removeItem(storageKey);
|
|
2427
2481
|
}
|
|
2428
2482
|
} catch (error) {
|
|
2429
|
-
|
|
2483
|
+
logger19.error("Error clearing localStorage cache", { error });
|
|
2430
2484
|
throw error;
|
|
2431
2485
|
}
|
|
2432
2486
|
}
|
|
2433
2487
|
// Query result caching methods implementation
|
|
2434
2488
|
async setQueryResult(queryHash, itemKeys) {
|
|
2435
|
-
|
|
2489
|
+
logger19.trace("setQueryResult", { queryHash, itemKeys });
|
|
2436
2490
|
const queryKey = `${this.keyPrefix}:query:${queryHash}`;
|
|
2437
2491
|
const entry = {
|
|
2438
2492
|
itemKeys
|
|
@@ -2440,11 +2494,11 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2440
2494
|
try {
|
|
2441
2495
|
localStorage.setItem(queryKey, JSON.stringify(entry));
|
|
2442
2496
|
} catch (error) {
|
|
2443
|
-
|
|
2497
|
+
logger19.error("Failed to store query result in localStorage", { queryHash, error });
|
|
2444
2498
|
}
|
|
2445
2499
|
}
|
|
2446
2500
|
async getQueryResult(queryHash) {
|
|
2447
|
-
|
|
2501
|
+
logger19.trace("getQueryResult", { queryHash });
|
|
2448
2502
|
const queryKey = `${this.keyPrefix}:query:${queryHash}`;
|
|
2449
2503
|
try {
|
|
2450
2504
|
const data = localStorage.getItem(queryKey);
|
|
@@ -2457,7 +2511,7 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2457
2511
|
}
|
|
2458
2512
|
return entry.itemKeys || null;
|
|
2459
2513
|
} catch (error) {
|
|
2460
|
-
|
|
2514
|
+
logger19.error("Failed to retrieve query result from localStorage", { queryHash, error });
|
|
2461
2515
|
return null;
|
|
2462
2516
|
}
|
|
2463
2517
|
}
|
|
@@ -2466,21 +2520,21 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2466
2520
|
try {
|
|
2467
2521
|
return localStorage.getItem(queryKey) !== null;
|
|
2468
2522
|
} catch (error) {
|
|
2469
|
-
|
|
2523
|
+
logger19.error("Failed to check query result in localStorage", { queryHash, error });
|
|
2470
2524
|
return false;
|
|
2471
2525
|
}
|
|
2472
2526
|
}
|
|
2473
2527
|
async deleteQueryResult(queryHash) {
|
|
2474
|
-
|
|
2528
|
+
logger19.trace("deleteQueryResult", { queryHash });
|
|
2475
2529
|
const queryKey = `${this.keyPrefix}:query:${queryHash}`;
|
|
2476
2530
|
try {
|
|
2477
2531
|
localStorage.removeItem(queryKey);
|
|
2478
2532
|
} catch (error) {
|
|
2479
|
-
|
|
2533
|
+
logger19.error("Failed to delete query result from localStorage", { queryHash, error });
|
|
2480
2534
|
}
|
|
2481
2535
|
}
|
|
2482
2536
|
async invalidateItemKeys(keys) {
|
|
2483
|
-
|
|
2537
|
+
logger19.debug("invalidateItemKeys", { keys });
|
|
2484
2538
|
if (keys.length === 0) {
|
|
2485
2539
|
return;
|
|
2486
2540
|
}
|
|
@@ -2518,24 +2572,24 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2518
2572
|
}
|
|
2519
2573
|
}
|
|
2520
2574
|
} catch (error) {
|
|
2521
|
-
|
|
2575
|
+
logger19.debug("Failed to parse query result", { queryKey, error });
|
|
2522
2576
|
}
|
|
2523
2577
|
}
|
|
2524
2578
|
queriesToRemove.forEach((queryKey) => {
|
|
2525
2579
|
localStorage.removeItem(queryKey);
|
|
2526
2580
|
});
|
|
2527
|
-
|
|
2581
|
+
logger19.debug("Selectively invalidated queries referencing affected keys", {
|
|
2528
2582
|
affectedKeys: keys.length,
|
|
2529
2583
|
queriesRemoved: queriesToRemove.length,
|
|
2530
2584
|
totalQueries: queryKeys.length
|
|
2531
2585
|
});
|
|
2532
2586
|
} catch (error) {
|
|
2533
|
-
|
|
2587
|
+
logger19.error("Error during selective query invalidation, falling back to clearing all queries", { error });
|
|
2534
2588
|
await this.clearQueryResults();
|
|
2535
2589
|
}
|
|
2536
2590
|
}
|
|
2537
2591
|
async invalidateLocation(locations) {
|
|
2538
|
-
|
|
2592
|
+
logger19.debug("invalidateLocation", { locations });
|
|
2539
2593
|
let keysToInvalidate = [];
|
|
2540
2594
|
if (locations.length === 0) {
|
|
2541
2595
|
const allKeys = await this.keys();
|
|
@@ -2550,7 +2604,7 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2550
2604
|
}
|
|
2551
2605
|
}
|
|
2552
2606
|
async clearQueryResults() {
|
|
2553
|
-
|
|
2607
|
+
logger19.trace("clearQueryResults");
|
|
2554
2608
|
const queryPrefix = `${this.keyPrefix}:query:`;
|
|
2555
2609
|
try {
|
|
2556
2610
|
const keysToRemove = this.getAllKeysStartingWith(queryPrefix);
|
|
@@ -2558,11 +2612,11 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2558
2612
|
try {
|
|
2559
2613
|
localStorage.removeItem(key);
|
|
2560
2614
|
} catch (error) {
|
|
2561
|
-
|
|
2615
|
+
logger19.error("Failed to remove query result from localStorage", { key, error });
|
|
2562
2616
|
}
|
|
2563
2617
|
}
|
|
2564
2618
|
} catch (error) {
|
|
2565
|
-
|
|
2619
|
+
logger19.error("Failed to clear query results from localStorage", { error });
|
|
2566
2620
|
}
|
|
2567
2621
|
}
|
|
2568
2622
|
// CacheMapMetadataProvider implementation
|
|
@@ -2574,13 +2628,13 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2574
2628
|
try {
|
|
2575
2629
|
return JSON.parse(stored);
|
|
2576
2630
|
} catch (e) {
|
|
2577
|
-
|
|
2631
|
+
logger19.debug("Invalid metadata JSON, treating as null", { key, error: e });
|
|
2578
2632
|
return null;
|
|
2579
2633
|
}
|
|
2580
2634
|
}
|
|
2581
2635
|
return null;
|
|
2582
2636
|
} catch (error) {
|
|
2583
|
-
|
|
2637
|
+
logger19.error("Error getting metadata from localStorage", { key, error });
|
|
2584
2638
|
throw error;
|
|
2585
2639
|
}
|
|
2586
2640
|
}
|
|
@@ -2590,12 +2644,12 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2590
2644
|
const metadataKey = `${this.keyPrefix}:metadata:${key}`;
|
|
2591
2645
|
localStorage.setItem(metadataKey, JSON.stringify(metadata));
|
|
2592
2646
|
if (attempt > 0) {
|
|
2593
|
-
|
|
2647
|
+
logger19.info(`Successfully stored metadata after ${attempt} retries`);
|
|
2594
2648
|
}
|
|
2595
2649
|
return;
|
|
2596
2650
|
} catch (error) {
|
|
2597
2651
|
const isLastAttempt = attempt === this.MAX_RETRY_ATTEMPTS - 1;
|
|
2598
|
-
|
|
2652
|
+
logger19.error(`Error storing metadata to localStorage (attempt ${attempt + 1}/${this.MAX_RETRY_ATTEMPTS})`, {
|
|
2599
2653
|
key,
|
|
2600
2654
|
error,
|
|
2601
2655
|
isLastAttempt
|
|
@@ -2617,7 +2671,7 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2617
2671
|
const metadataKey = `${this.keyPrefix}:metadata:${key}`;
|
|
2618
2672
|
localStorage.removeItem(metadataKey);
|
|
2619
2673
|
} catch (error) {
|
|
2620
|
-
|
|
2674
|
+
logger19.error("Error deleting metadata from localStorage", { key, error });
|
|
2621
2675
|
throw error;
|
|
2622
2676
|
}
|
|
2623
2677
|
}
|
|
@@ -2636,11 +2690,11 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2636
2690
|
metadata.set(metadataKey, parsed);
|
|
2637
2691
|
}
|
|
2638
2692
|
} catch (error) {
|
|
2639
|
-
|
|
2693
|
+
logger19.debug("Skipping invalid metadata entry", { key, error });
|
|
2640
2694
|
}
|
|
2641
2695
|
}
|
|
2642
2696
|
} catch (error) {
|
|
2643
|
-
|
|
2697
|
+
logger19.error("Error getting metadata from localStorage", { error });
|
|
2644
2698
|
throw error;
|
|
2645
2699
|
}
|
|
2646
2700
|
return metadata;
|
|
@@ -2651,7 +2705,7 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2651
2705
|
const keysToDelete = this.getAllKeysStartingWith(metadataPrefix);
|
|
2652
2706
|
keysToDelete.forEach((key) => localStorage.removeItem(key));
|
|
2653
2707
|
} catch (error) {
|
|
2654
|
-
|
|
2708
|
+
logger19.error("Error clearing metadata from localStorage", { error });
|
|
2655
2709
|
throw error;
|
|
2656
2710
|
}
|
|
2657
2711
|
}
|
|
@@ -2678,16 +2732,16 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2678
2732
|
itemCount++;
|
|
2679
2733
|
}
|
|
2680
2734
|
} catch (error) {
|
|
2681
|
-
|
|
2735
|
+
logger19.debug("Invalid entry in getCurrentSize", { key, error });
|
|
2682
2736
|
}
|
|
2683
2737
|
}
|
|
2684
2738
|
} catch (error) {
|
|
2685
|
-
|
|
2739
|
+
logger19.debug("Size calculation failed, using string length", { key, error });
|
|
2686
2740
|
sizeBytes += value.length;
|
|
2687
2741
|
}
|
|
2688
2742
|
}
|
|
2689
2743
|
} catch (error) {
|
|
2690
|
-
|
|
2744
|
+
logger19.error("Error calculating size from localStorage", { error });
|
|
2691
2745
|
throw error;
|
|
2692
2746
|
}
|
|
2693
2747
|
return { itemCount, sizeBytes };
|
|
@@ -2708,7 +2762,7 @@ import {
|
|
|
2708
2762
|
isQueryMatch as isQueryMatch4
|
|
2709
2763
|
} from "@fjell/core";
|
|
2710
2764
|
import safeStringify2 from "fast-safe-stringify";
|
|
2711
|
-
var
|
|
2765
|
+
var logger20 = logger_default.get("SessionStorageCacheMap");
|
|
2712
2766
|
var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
2713
2767
|
implementationType = "browser/sessionStorage";
|
|
2714
2768
|
keyPrefix;
|
|
@@ -2736,7 +2790,7 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
2736
2790
|
}
|
|
2737
2791
|
}
|
|
2738
2792
|
} catch (error) {
|
|
2739
|
-
|
|
2793
|
+
logger20.error("Error getting keys from sessionStorage", { error });
|
|
2740
2794
|
}
|
|
2741
2795
|
return keys;
|
|
2742
2796
|
}
|
|
@@ -2759,7 +2813,7 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
2759
2813
|
}
|
|
2760
2814
|
}
|
|
2761
2815
|
async get(key) {
|
|
2762
|
-
|
|
2816
|
+
logger20.trace("get", { key });
|
|
2763
2817
|
try {
|
|
2764
2818
|
const currentHash = this.normalizedHashFunction(key);
|
|
2765
2819
|
if (this.hasCollisionForHash(currentHash)) {
|
|
@@ -2779,14 +2833,14 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
2779
2833
|
}
|
|
2780
2834
|
return null;
|
|
2781
2835
|
} catch (error) {
|
|
2782
|
-
|
|
2836
|
+
logger20.error("Error retrieving from sessionStorage", { key, error });
|
|
2783
2837
|
return null;
|
|
2784
2838
|
}
|
|
2785
2839
|
}
|
|
2786
2840
|
async set(key, value) {
|
|
2787
2841
|
try {
|
|
2788
2842
|
const storageKey = this.getStorageKey(key);
|
|
2789
|
-
|
|
2843
|
+
logger20.trace("set", { storageKey });
|
|
2790
2844
|
const toStore = {
|
|
2791
2845
|
originalKey: key,
|
|
2792
2846
|
value,
|
|
@@ -2796,7 +2850,7 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
2796
2850
|
const jsonString = safeStringify2(toStore);
|
|
2797
2851
|
sessionStorage.setItem(storageKey, jsonString);
|
|
2798
2852
|
} catch (error) {
|
|
2799
|
-
|
|
2853
|
+
logger20.error("Error storing to sessionStorage", { errorMessage: error?.message });
|
|
2800
2854
|
throw new Error(`Failed to store item in sessionStorage: ${error}`);
|
|
2801
2855
|
}
|
|
2802
2856
|
}
|
|
@@ -2817,23 +2871,23 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
2817
2871
|
}
|
|
2818
2872
|
return false;
|
|
2819
2873
|
} catch (error) {
|
|
2820
|
-
|
|
2874
|
+
logger20.error("Error checking key in sessionStorage", { key, error });
|
|
2821
2875
|
return false;
|
|
2822
2876
|
}
|
|
2823
2877
|
}
|
|
2824
2878
|
async delete(key) {
|
|
2825
|
-
|
|
2879
|
+
logger20.trace("delete", { key });
|
|
2826
2880
|
try {
|
|
2827
2881
|
const storageKey = this.getStorageKey(key);
|
|
2828
2882
|
sessionStorage.removeItem(storageKey);
|
|
2829
2883
|
} catch (error) {
|
|
2830
|
-
|
|
2884
|
+
logger20.error("Error deleting from sessionStorage", { key, error });
|
|
2831
2885
|
}
|
|
2832
2886
|
}
|
|
2833
2887
|
async allIn(locations) {
|
|
2834
2888
|
const allKeys = this.keys();
|
|
2835
2889
|
if (locations.length === 0) {
|
|
2836
|
-
|
|
2890
|
+
logger20.debug("Returning all items, LocKeys is empty");
|
|
2837
2891
|
const items = [];
|
|
2838
2892
|
for (const key of await allKeys) {
|
|
2839
2893
|
const item = await this.get(key);
|
|
@@ -2845,10 +2899,10 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
2845
2899
|
} else {
|
|
2846
2900
|
const locKeys = locations;
|
|
2847
2901
|
const resolvedKeys = await allKeys;
|
|
2848
|
-
|
|
2902
|
+
logger20.debug("allIn", { locKeys, keys: resolvedKeys.length });
|
|
2849
2903
|
const filteredKeys = resolvedKeys.filter((key) => key && isComKey4(key)).filter((key) => {
|
|
2850
2904
|
const ComKey15 = key;
|
|
2851
|
-
|
|
2905
|
+
logger20.debug("Comparing Location Keys", {
|
|
2852
2906
|
locKeys,
|
|
2853
2907
|
ComKey: ComKey15
|
|
2854
2908
|
});
|
|
@@ -2865,12 +2919,12 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
2865
2919
|
}
|
|
2866
2920
|
}
|
|
2867
2921
|
async contains(query, locations) {
|
|
2868
|
-
|
|
2922
|
+
logger20.debug("contains", { query, locations });
|
|
2869
2923
|
const items = await this.allIn(locations);
|
|
2870
2924
|
return items.some((item) => isQueryMatch4(item, query));
|
|
2871
2925
|
}
|
|
2872
2926
|
async queryIn(query, locations = []) {
|
|
2873
|
-
|
|
2927
|
+
logger20.debug("queryIn", { query, locations });
|
|
2874
2928
|
const items = await this.allIn(locations);
|
|
2875
2929
|
return items.filter((item) => isQueryMatch4(item, query));
|
|
2876
2930
|
}
|
|
@@ -2890,11 +2944,11 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
2890
2944
|
keys.push(parsed.originalKey);
|
|
2891
2945
|
}
|
|
2892
2946
|
} catch (itemError) {
|
|
2893
|
-
|
|
2947
|
+
logger20.trace("Skipping invalid storage item", { storageKey, error: itemError });
|
|
2894
2948
|
}
|
|
2895
2949
|
}
|
|
2896
2950
|
} catch (error) {
|
|
2897
|
-
|
|
2951
|
+
logger20.error("Error getting keys from sessionStorage", { error });
|
|
2898
2952
|
}
|
|
2899
2953
|
return keys;
|
|
2900
2954
|
}
|
|
@@ -2911,28 +2965,28 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
2911
2965
|
values.push(parsed.value);
|
|
2912
2966
|
}
|
|
2913
2967
|
} catch (itemError) {
|
|
2914
|
-
|
|
2968
|
+
logger20.trace("Skipping invalid storage item for values", { storageKey, error: itemError });
|
|
2915
2969
|
}
|
|
2916
2970
|
}
|
|
2917
2971
|
} catch (error) {
|
|
2918
|
-
|
|
2972
|
+
logger20.error("Error getting values from sessionStorage", { error });
|
|
2919
2973
|
}
|
|
2920
2974
|
return values;
|
|
2921
2975
|
}
|
|
2922
2976
|
async clear() {
|
|
2923
|
-
|
|
2977
|
+
logger20.debug("Clearing sessionStorage cache");
|
|
2924
2978
|
try {
|
|
2925
2979
|
const storageKeys = this.getAllStorageKeys();
|
|
2926
2980
|
for (const storageKey of storageKeys) {
|
|
2927
2981
|
sessionStorage.removeItem(storageKey);
|
|
2928
2982
|
}
|
|
2929
2983
|
} catch (error) {
|
|
2930
|
-
|
|
2984
|
+
logger20.error("Error clearing sessionStorage cache", { error });
|
|
2931
2985
|
}
|
|
2932
2986
|
}
|
|
2933
2987
|
// Query result caching methods implementation
|
|
2934
2988
|
async setQueryResult(queryHash, itemKeys) {
|
|
2935
|
-
|
|
2989
|
+
logger20.trace("setQueryResult", { queryHash, itemKeys });
|
|
2936
2990
|
const queryKey = `${this.keyPrefix}:query:${queryHash}`;
|
|
2937
2991
|
const entry = {
|
|
2938
2992
|
itemKeys
|
|
@@ -2941,11 +2995,11 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
2941
2995
|
const jsonString = safeStringify2(entry);
|
|
2942
2996
|
sessionStorage.setItem(queryKey, jsonString);
|
|
2943
2997
|
} catch (error) {
|
|
2944
|
-
|
|
2998
|
+
logger20.error("Failed to store query result in sessionStorage", { queryHash, error });
|
|
2945
2999
|
}
|
|
2946
3000
|
}
|
|
2947
3001
|
async getQueryResult(queryHash) {
|
|
2948
|
-
|
|
3002
|
+
logger20.trace("getQueryResult", { queryHash });
|
|
2949
3003
|
const queryKey = `${this.keyPrefix}:query:${queryHash}`;
|
|
2950
3004
|
try {
|
|
2951
3005
|
const data = sessionStorage.getItem(queryKey);
|
|
@@ -2958,7 +3012,7 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
2958
3012
|
}
|
|
2959
3013
|
return entry.itemKeys || null;
|
|
2960
3014
|
} catch (error) {
|
|
2961
|
-
|
|
3015
|
+
logger20.error("Failed to retrieve query result from sessionStorage", { queryHash, error });
|
|
2962
3016
|
return null;
|
|
2963
3017
|
}
|
|
2964
3018
|
}
|
|
@@ -2967,21 +3021,21 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
2967
3021
|
try {
|
|
2968
3022
|
return sessionStorage.getItem(queryKey) !== null;
|
|
2969
3023
|
} catch (error) {
|
|
2970
|
-
|
|
3024
|
+
logger20.error("Failed to check query result in sessionStorage", { queryHash, error });
|
|
2971
3025
|
return false;
|
|
2972
3026
|
}
|
|
2973
3027
|
}
|
|
2974
3028
|
async deleteQueryResult(queryHash) {
|
|
2975
|
-
|
|
3029
|
+
logger20.trace("deleteQueryResult", { queryHash });
|
|
2976
3030
|
const queryKey = `${this.keyPrefix}:query:${queryHash}`;
|
|
2977
3031
|
try {
|
|
2978
3032
|
sessionStorage.removeItem(queryKey);
|
|
2979
3033
|
} catch (error) {
|
|
2980
|
-
|
|
3034
|
+
logger20.error("Failed to delete query result from sessionStorage", { queryHash, error });
|
|
2981
3035
|
}
|
|
2982
3036
|
}
|
|
2983
3037
|
async clearQueryResults() {
|
|
2984
|
-
|
|
3038
|
+
logger20.trace("clearQueryResults");
|
|
2985
3039
|
const queryPrefix = `${this.keyPrefix}:query:`;
|
|
2986
3040
|
try {
|
|
2987
3041
|
const keysToRemove = [];
|
|
@@ -2993,7 +3047,7 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
2993
3047
|
}
|
|
2994
3048
|
keysToRemove.forEach((key) => sessionStorage.removeItem(key));
|
|
2995
3049
|
} catch (error) {
|
|
2996
|
-
|
|
3050
|
+
logger20.error("Failed to clear query results from sessionStorage", { error });
|
|
2997
3051
|
}
|
|
2998
3052
|
}
|
|
2999
3053
|
// CacheMapMetadataProvider implementation
|
|
@@ -3040,7 +3094,7 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
3040
3094
|
}
|
|
3041
3095
|
return metadata;
|
|
3042
3096
|
} catch (error) {
|
|
3043
|
-
|
|
3097
|
+
logger20.error("Error getting all metadata from sessionStorage", { error });
|
|
3044
3098
|
return metadata;
|
|
3045
3099
|
}
|
|
3046
3100
|
}
|
|
@@ -3060,7 +3114,7 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
3060
3114
|
}
|
|
3061
3115
|
// Invalidation methods
|
|
3062
3116
|
async invalidateItemKeys(keys) {
|
|
3063
|
-
|
|
3117
|
+
logger20.debug("invalidateItemKeys", { keys });
|
|
3064
3118
|
if (keys.length === 0) {
|
|
3065
3119
|
return;
|
|
3066
3120
|
}
|
|
@@ -3104,24 +3158,24 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
3104
3158
|
}
|
|
3105
3159
|
}
|
|
3106
3160
|
} catch (error) {
|
|
3107
|
-
|
|
3161
|
+
logger20.debug("Failed to parse query result", { queryKey, error });
|
|
3108
3162
|
}
|
|
3109
3163
|
}
|
|
3110
3164
|
queriesToRemove.forEach((queryKey) => {
|
|
3111
3165
|
sessionStorage.removeItem(queryKey);
|
|
3112
3166
|
});
|
|
3113
|
-
|
|
3167
|
+
logger20.debug("Selectively invalidated queries referencing affected keys", {
|
|
3114
3168
|
affectedKeys: keys.length,
|
|
3115
3169
|
queriesRemoved: queriesToRemove.length,
|
|
3116
3170
|
totalQueries: queryKeys.length
|
|
3117
3171
|
});
|
|
3118
3172
|
} catch (error) {
|
|
3119
|
-
|
|
3173
|
+
logger20.error("Error during selective query invalidation, falling back to clearing all queries", { error });
|
|
3120
3174
|
await this.clearQueryResults();
|
|
3121
3175
|
}
|
|
3122
3176
|
}
|
|
3123
3177
|
async invalidateLocation(locations) {
|
|
3124
|
-
|
|
3178
|
+
logger20.debug("invalidateLocation", { locations });
|
|
3125
3179
|
let keysToInvalidate = [];
|
|
3126
3180
|
if (locations.length === 0) {
|
|
3127
3181
|
const allKeys = await this.keys();
|
|
@@ -3187,7 +3241,7 @@ import {
|
|
|
3187
3241
|
isQueryMatch as isQueryMatch5
|
|
3188
3242
|
} from "@fjell/core";
|
|
3189
3243
|
import safeStringify3 from "fast-safe-stringify";
|
|
3190
|
-
var
|
|
3244
|
+
var logger21 = logger_default.get("AsyncIndexDBCacheMap");
|
|
3191
3245
|
var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
3192
3246
|
types;
|
|
3193
3247
|
dbName;
|
|
@@ -3213,19 +3267,19 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3213
3267
|
}
|
|
3214
3268
|
const request = indexedDB.open(this.dbName, this.version);
|
|
3215
3269
|
request.onerror = () => {
|
|
3216
|
-
|
|
3270
|
+
logger21.error("Error opening IndexedDB", { error: request.error });
|
|
3217
3271
|
reject(request.error);
|
|
3218
3272
|
};
|
|
3219
3273
|
request.onsuccess = () => {
|
|
3220
|
-
|
|
3274
|
+
logger21.debug("IndexedDB opened successfully");
|
|
3221
3275
|
resolve(request.result);
|
|
3222
3276
|
};
|
|
3223
3277
|
request.onupgradeneeded = (event) => {
|
|
3224
|
-
|
|
3278
|
+
logger21.debug("IndexedDB upgrade needed");
|
|
3225
3279
|
const db = event.target.result;
|
|
3226
3280
|
if (!db.objectStoreNames.contains(this.storeName)) {
|
|
3227
3281
|
db.createObjectStore(this.storeName);
|
|
3228
|
-
|
|
3282
|
+
logger21.debug("Created object store", { storeName: this.storeName });
|
|
3229
3283
|
}
|
|
3230
3284
|
};
|
|
3231
3285
|
});
|
|
@@ -3236,7 +3290,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3236
3290
|
return this.normalizedHashFunction(key);
|
|
3237
3291
|
}
|
|
3238
3292
|
async get(key) {
|
|
3239
|
-
|
|
3293
|
+
logger21.trace("get", { key });
|
|
3240
3294
|
try {
|
|
3241
3295
|
const db = await this.getDB();
|
|
3242
3296
|
const transaction = db.transaction([this.storeName], "readonly");
|
|
@@ -3245,7 +3299,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3245
3299
|
return new Promise((resolve, reject) => {
|
|
3246
3300
|
const request = store.get(storageKey);
|
|
3247
3301
|
request.onerror = () => {
|
|
3248
|
-
|
|
3302
|
+
logger21.error("Error getting from IndexedDB", { key, error: request.error });
|
|
3249
3303
|
reject(request.error);
|
|
3250
3304
|
};
|
|
3251
3305
|
request.onsuccess = () => {
|
|
@@ -3258,7 +3312,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3258
3312
|
};
|
|
3259
3313
|
});
|
|
3260
3314
|
} catch (error) {
|
|
3261
|
-
|
|
3315
|
+
logger21.error("Error in IndexedDB get operation", { key, error });
|
|
3262
3316
|
return null;
|
|
3263
3317
|
}
|
|
3264
3318
|
}
|
|
@@ -3266,7 +3320,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3266
3320
|
* Get both the value and metadata for an item
|
|
3267
3321
|
*/
|
|
3268
3322
|
async getWithMetadata(key) {
|
|
3269
|
-
|
|
3323
|
+
logger21.trace("getWithMetadata", { key });
|
|
3270
3324
|
try {
|
|
3271
3325
|
const db = await this.getDB();
|
|
3272
3326
|
const transaction = db.transaction([this.storeName], "readonly");
|
|
@@ -3275,7 +3329,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3275
3329
|
return new Promise((resolve, reject) => {
|
|
3276
3330
|
const request = store.get(storageKey);
|
|
3277
3331
|
request.onerror = () => {
|
|
3278
|
-
|
|
3332
|
+
logger21.error("Error getting from IndexedDB", { key, error: request.error });
|
|
3279
3333
|
reject(request.error);
|
|
3280
3334
|
};
|
|
3281
3335
|
request.onsuccess = () => {
|
|
@@ -3291,12 +3345,12 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3291
3345
|
};
|
|
3292
3346
|
});
|
|
3293
3347
|
} catch (error) {
|
|
3294
|
-
|
|
3348
|
+
logger21.error("Error in IndexedDB getWithMetadata operation", { key, error });
|
|
3295
3349
|
return null;
|
|
3296
3350
|
}
|
|
3297
3351
|
}
|
|
3298
3352
|
async set(key, value, metadata) {
|
|
3299
|
-
|
|
3353
|
+
logger21.trace("set", { key, value, hasMetadata: !!metadata });
|
|
3300
3354
|
try {
|
|
3301
3355
|
const db = await this.getDB();
|
|
3302
3356
|
const transaction = db.transaction([this.storeName], "readwrite");
|
|
@@ -3311,7 +3365,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3311
3365
|
return new Promise((resolve, reject) => {
|
|
3312
3366
|
const request = store.put(storedItem, storageKey);
|
|
3313
3367
|
request.onerror = () => {
|
|
3314
|
-
|
|
3368
|
+
logger21.error("Error setting in IndexedDB", { key, value, error: request.error });
|
|
3315
3369
|
reject(request.error);
|
|
3316
3370
|
};
|
|
3317
3371
|
request.onsuccess = () => {
|
|
@@ -3319,7 +3373,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3319
3373
|
};
|
|
3320
3374
|
});
|
|
3321
3375
|
} catch (error) {
|
|
3322
|
-
|
|
3376
|
+
logger21.error("Error in IndexedDB set operation", { key, value, error });
|
|
3323
3377
|
throw new Error(`Failed to store item in IndexedDB: ${error}`);
|
|
3324
3378
|
}
|
|
3325
3379
|
}
|
|
@@ -3327,16 +3381,16 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3327
3381
|
* Update only the metadata for an existing item
|
|
3328
3382
|
*/
|
|
3329
3383
|
async setMetadata(key, metadata) {
|
|
3330
|
-
|
|
3384
|
+
logger21.trace("setMetadata", { key, metadata });
|
|
3331
3385
|
try {
|
|
3332
3386
|
const existing = await this.getWithMetadata(key);
|
|
3333
3387
|
if (existing) {
|
|
3334
3388
|
await this.set(key, existing.value, metadata);
|
|
3335
3389
|
} else {
|
|
3336
|
-
|
|
3390
|
+
logger21.warning("Attempted to set metadata for non-existent item", { key });
|
|
3337
3391
|
}
|
|
3338
3392
|
} catch (error) {
|
|
3339
|
-
|
|
3393
|
+
logger21.error("Error in IndexedDB setMetadata operation", { key, error });
|
|
3340
3394
|
throw new Error(`Failed to update metadata in IndexedDB: ${error}`);
|
|
3341
3395
|
}
|
|
3342
3396
|
}
|
|
@@ -3349,7 +3403,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3349
3403
|
return new Promise((resolve, reject) => {
|
|
3350
3404
|
const request = store.get(storageKey);
|
|
3351
3405
|
request.onerror = () => {
|
|
3352
|
-
|
|
3406
|
+
logger21.error("Error checking key in IndexedDB", { key, error: request.error });
|
|
3353
3407
|
reject(request.error);
|
|
3354
3408
|
};
|
|
3355
3409
|
request.onsuccess = () => {
|
|
@@ -3363,12 +3417,12 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3363
3417
|
};
|
|
3364
3418
|
});
|
|
3365
3419
|
} catch (error) {
|
|
3366
|
-
|
|
3420
|
+
logger21.error("Error in IndexedDB includesKey operation", { key, error });
|
|
3367
3421
|
return false;
|
|
3368
3422
|
}
|
|
3369
3423
|
}
|
|
3370
3424
|
async delete(key) {
|
|
3371
|
-
|
|
3425
|
+
logger21.trace("delete", { key });
|
|
3372
3426
|
try {
|
|
3373
3427
|
const db = await this.getDB();
|
|
3374
3428
|
const transaction = db.transaction([this.storeName], "readwrite");
|
|
@@ -3377,7 +3431,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3377
3431
|
return new Promise((resolve, reject) => {
|
|
3378
3432
|
const request = store.delete(storageKey);
|
|
3379
3433
|
request.onerror = () => {
|
|
3380
|
-
|
|
3434
|
+
logger21.error("Error deleting from IndexedDB", { key, error: request.error });
|
|
3381
3435
|
reject(request.error);
|
|
3382
3436
|
};
|
|
3383
3437
|
request.onsuccess = () => {
|
|
@@ -3385,22 +3439,22 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3385
3439
|
};
|
|
3386
3440
|
});
|
|
3387
3441
|
} catch (error) {
|
|
3388
|
-
|
|
3442
|
+
logger21.error("Error in IndexedDB delete operation", { key, error });
|
|
3389
3443
|
}
|
|
3390
3444
|
}
|
|
3391
3445
|
async allIn(locations) {
|
|
3392
3446
|
const allKeys = await this.keys();
|
|
3393
3447
|
if (locations.length === 0) {
|
|
3394
|
-
|
|
3448
|
+
logger21.debug("Returning all items, LocKeys is empty");
|
|
3395
3449
|
const promises = allKeys.map((key) => this.get(key));
|
|
3396
3450
|
const results = await Promise.all(promises);
|
|
3397
3451
|
return results.filter((item) => item !== null);
|
|
3398
3452
|
} else {
|
|
3399
3453
|
const locKeys = locations;
|
|
3400
|
-
|
|
3454
|
+
logger21.debug("allIn", { locKeys, keys: allKeys.length });
|
|
3401
3455
|
const filteredKeys = allKeys.filter((key) => key && isComKey5(key)).filter((key) => {
|
|
3402
3456
|
const ComKey15 = key;
|
|
3403
|
-
|
|
3457
|
+
logger21.debug("Comparing Location Keys", {
|
|
3404
3458
|
locKeys,
|
|
3405
3459
|
ComKey: ComKey15
|
|
3406
3460
|
});
|
|
@@ -3412,12 +3466,12 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3412
3466
|
}
|
|
3413
3467
|
}
|
|
3414
3468
|
async contains(query, locations) {
|
|
3415
|
-
|
|
3469
|
+
logger21.debug("contains", { query, locations });
|
|
3416
3470
|
const items = await this.allIn(locations);
|
|
3417
3471
|
return items.some((item) => isQueryMatch5(item, query));
|
|
3418
3472
|
}
|
|
3419
3473
|
async queryIn(query, locations = []) {
|
|
3420
|
-
|
|
3474
|
+
logger21.debug("queryIn", { query, locations });
|
|
3421
3475
|
const items = await this.allIn(locations);
|
|
3422
3476
|
return items.filter((item) => isQueryMatch5(item, query));
|
|
3423
3477
|
}
|
|
@@ -3433,7 +3487,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3433
3487
|
return new Promise((resolve, reject) => {
|
|
3434
3488
|
const request = store.openCursor();
|
|
3435
3489
|
request.onerror = () => {
|
|
3436
|
-
|
|
3490
|
+
logger21.error("Error getting keys from IndexedDB", { error: request.error });
|
|
3437
3491
|
reject(request.error);
|
|
3438
3492
|
};
|
|
3439
3493
|
request.onsuccess = (event) => {
|
|
@@ -3448,7 +3502,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3448
3502
|
};
|
|
3449
3503
|
});
|
|
3450
3504
|
} catch (error) {
|
|
3451
|
-
|
|
3505
|
+
logger21.error("Error in IndexedDB keys operation", { error });
|
|
3452
3506
|
return [];
|
|
3453
3507
|
}
|
|
3454
3508
|
}
|
|
@@ -3464,7 +3518,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3464
3518
|
return new Promise((resolve, reject) => {
|
|
3465
3519
|
const request = store.openCursor();
|
|
3466
3520
|
request.onerror = () => {
|
|
3467
|
-
|
|
3521
|
+
logger21.error("Error getting metadata from IndexedDB", { error: request.error });
|
|
3468
3522
|
reject(request.error);
|
|
3469
3523
|
};
|
|
3470
3524
|
request.onsuccess = (event) => {
|
|
@@ -3482,7 +3536,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3482
3536
|
};
|
|
3483
3537
|
});
|
|
3484
3538
|
} catch (error) {
|
|
3485
|
-
|
|
3539
|
+
logger21.error("Error in IndexedDB getAllMetadata operation", { error });
|
|
3486
3540
|
return metadataMap;
|
|
3487
3541
|
}
|
|
3488
3542
|
}
|
|
@@ -3495,7 +3549,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3495
3549
|
return new Promise((resolve, reject) => {
|
|
3496
3550
|
const request = store.openCursor();
|
|
3497
3551
|
request.onerror = () => {
|
|
3498
|
-
|
|
3552
|
+
logger21.error("Error getting values from IndexedDB", { error: request.error });
|
|
3499
3553
|
reject(request.error);
|
|
3500
3554
|
};
|
|
3501
3555
|
request.onsuccess = (event) => {
|
|
@@ -3510,12 +3564,12 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3510
3564
|
};
|
|
3511
3565
|
});
|
|
3512
3566
|
} catch (error) {
|
|
3513
|
-
|
|
3567
|
+
logger21.error("Error in IndexedDB values operation", { error });
|
|
3514
3568
|
return [];
|
|
3515
3569
|
}
|
|
3516
3570
|
}
|
|
3517
3571
|
async clear() {
|
|
3518
|
-
|
|
3572
|
+
logger21.debug("Clearing IndexedDB cache");
|
|
3519
3573
|
try {
|
|
3520
3574
|
const db = await this.getDB();
|
|
3521
3575
|
const transaction = db.transaction([this.storeName], "readwrite");
|
|
@@ -3523,7 +3577,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3523
3577
|
return new Promise((resolve, reject) => {
|
|
3524
3578
|
const request = store.clear();
|
|
3525
3579
|
request.onerror = () => {
|
|
3526
|
-
|
|
3580
|
+
logger21.error("Error clearing IndexedDB cache", { error: request.error });
|
|
3527
3581
|
reject(request.error);
|
|
3528
3582
|
};
|
|
3529
3583
|
request.onsuccess = () => {
|
|
@@ -3531,17 +3585,17 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3531
3585
|
};
|
|
3532
3586
|
});
|
|
3533
3587
|
} catch (error) {
|
|
3534
|
-
|
|
3588
|
+
logger21.error("Error in IndexedDB clear operation", { error });
|
|
3535
3589
|
}
|
|
3536
3590
|
}
|
|
3537
3591
|
// Async Query result caching methods
|
|
3538
3592
|
async setQueryResult(queryHash, itemKeys) {
|
|
3539
|
-
|
|
3593
|
+
logger21.trace("setQueryResult", { queryHash, itemKeys });
|
|
3540
3594
|
try {
|
|
3541
3595
|
return new Promise((resolve, reject) => {
|
|
3542
3596
|
const request = indexedDB.open(this.dbName, this.version);
|
|
3543
3597
|
request.onerror = () => {
|
|
3544
|
-
|
|
3598
|
+
logger21.error("Failed to open database for setQueryResult", { error: request.error });
|
|
3545
3599
|
reject(request.error);
|
|
3546
3600
|
};
|
|
3547
3601
|
request.onsuccess = () => {
|
|
@@ -3554,7 +3608,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3554
3608
|
const queryKey = `query:${queryHash}`;
|
|
3555
3609
|
const putRequest = store.put(safeStringify3(entry), queryKey);
|
|
3556
3610
|
putRequest.onerror = () => {
|
|
3557
|
-
|
|
3611
|
+
logger21.error("Failed to store query result", { queryHash, error: putRequest.error });
|
|
3558
3612
|
reject(putRequest.error);
|
|
3559
3613
|
};
|
|
3560
3614
|
putRequest.onsuccess = () => {
|
|
@@ -3563,17 +3617,17 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3563
3617
|
};
|
|
3564
3618
|
});
|
|
3565
3619
|
} catch (error) {
|
|
3566
|
-
|
|
3620
|
+
logger21.error("Error in setQueryResult", { queryHash, error });
|
|
3567
3621
|
throw error;
|
|
3568
3622
|
}
|
|
3569
3623
|
}
|
|
3570
3624
|
async getQueryResult(queryHash) {
|
|
3571
|
-
|
|
3625
|
+
logger21.trace("getQueryResult", { queryHash });
|
|
3572
3626
|
try {
|
|
3573
3627
|
return new Promise((resolve, reject) => {
|
|
3574
3628
|
const request = indexedDB.open(this.dbName, this.version);
|
|
3575
3629
|
request.onerror = () => {
|
|
3576
|
-
|
|
3630
|
+
logger21.error("Failed to open database for getQueryResult", { error: request.error });
|
|
3577
3631
|
reject(request.error);
|
|
3578
3632
|
};
|
|
3579
3633
|
request.onsuccess = () => {
|
|
@@ -3583,7 +3637,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3583
3637
|
const queryKey = `query:${queryHash}`;
|
|
3584
3638
|
const getRequest = store.get(queryKey);
|
|
3585
3639
|
getRequest.onerror = () => {
|
|
3586
|
-
|
|
3640
|
+
logger21.error("Failed to retrieve query result", { queryHash, error: getRequest.error });
|
|
3587
3641
|
reject(getRequest.error);
|
|
3588
3642
|
};
|
|
3589
3643
|
getRequest.onsuccess = () => {
|
|
@@ -3600,34 +3654,34 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3600
3654
|
}
|
|
3601
3655
|
resolve(entry.itemKeys || null);
|
|
3602
3656
|
} catch (parseError) {
|
|
3603
|
-
|
|
3657
|
+
logger21.error("Failed to parse query result", { queryHash, error: parseError });
|
|
3604
3658
|
resolve(null);
|
|
3605
3659
|
}
|
|
3606
3660
|
};
|
|
3607
3661
|
};
|
|
3608
3662
|
});
|
|
3609
3663
|
} catch (error) {
|
|
3610
|
-
|
|
3664
|
+
logger21.error("Error in getQueryResult", { queryHash, error });
|
|
3611
3665
|
return null;
|
|
3612
3666
|
}
|
|
3613
3667
|
}
|
|
3614
3668
|
async hasQueryResult(queryHash) {
|
|
3615
|
-
|
|
3669
|
+
logger21.trace("hasQueryResult", { queryHash });
|
|
3616
3670
|
try {
|
|
3617
3671
|
const result = await this.getQueryResult(queryHash);
|
|
3618
3672
|
return result !== null;
|
|
3619
3673
|
} catch (error) {
|
|
3620
|
-
|
|
3674
|
+
logger21.error("Error in hasQueryResult", { queryHash, error });
|
|
3621
3675
|
return false;
|
|
3622
3676
|
}
|
|
3623
3677
|
}
|
|
3624
3678
|
async deleteQueryResult(queryHash) {
|
|
3625
|
-
|
|
3679
|
+
logger21.trace("deleteQueryResult", { queryHash });
|
|
3626
3680
|
try {
|
|
3627
3681
|
return new Promise((resolve, reject) => {
|
|
3628
3682
|
const request = indexedDB.open(this.dbName, this.version);
|
|
3629
3683
|
request.onerror = () => {
|
|
3630
|
-
|
|
3684
|
+
logger21.error("Failed to open database for deleteQueryResult", { error: request.error });
|
|
3631
3685
|
reject(request.error);
|
|
3632
3686
|
};
|
|
3633
3687
|
request.onsuccess = () => {
|
|
@@ -3637,7 +3691,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3637
3691
|
const queryKey = `query:${queryHash}`;
|
|
3638
3692
|
const deleteRequest = store.delete(queryKey);
|
|
3639
3693
|
deleteRequest.onerror = () => {
|
|
3640
|
-
|
|
3694
|
+
logger21.error("Failed to delete query result", { queryHash, error: deleteRequest.error });
|
|
3641
3695
|
reject(deleteRequest.error);
|
|
3642
3696
|
};
|
|
3643
3697
|
deleteRequest.onsuccess = () => {
|
|
@@ -3646,12 +3700,12 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3646
3700
|
};
|
|
3647
3701
|
});
|
|
3648
3702
|
} catch (error) {
|
|
3649
|
-
|
|
3703
|
+
logger21.error("Error in deleteQueryResult", { queryHash, error });
|
|
3650
3704
|
throw error;
|
|
3651
3705
|
}
|
|
3652
3706
|
}
|
|
3653
3707
|
async invalidateItemKeys(keys) {
|
|
3654
|
-
|
|
3708
|
+
logger21.debug("invalidateItemKeys", { keys });
|
|
3655
3709
|
if (keys.length === 0) {
|
|
3656
3710
|
return;
|
|
3657
3711
|
}
|
|
@@ -3688,7 +3742,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3688
3742
|
queryResults2[queryHash] = itemKeys;
|
|
3689
3743
|
}
|
|
3690
3744
|
} catch (error) {
|
|
3691
|
-
|
|
3745
|
+
logger21.debug("Failed to parse query result", { key: item.key, error });
|
|
3692
3746
|
}
|
|
3693
3747
|
}
|
|
3694
3748
|
}
|
|
@@ -3716,18 +3770,18 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3716
3770
|
});
|
|
3717
3771
|
}
|
|
3718
3772
|
}
|
|
3719
|
-
|
|
3773
|
+
logger21.debug("Selectively invalidated queries referencing affected keys", {
|
|
3720
3774
|
affectedKeys: keys.length,
|
|
3721
3775
|
queriesRemoved: queriesToRemove.length,
|
|
3722
3776
|
totalQueries: Object.keys(queryResults).length
|
|
3723
3777
|
});
|
|
3724
3778
|
} catch (error) {
|
|
3725
|
-
|
|
3779
|
+
logger21.error("Error during selective query invalidation, falling back to clearing all queries", { error });
|
|
3726
3780
|
await this.clearQueryResults();
|
|
3727
3781
|
}
|
|
3728
3782
|
}
|
|
3729
3783
|
async invalidateLocation(locations) {
|
|
3730
|
-
|
|
3784
|
+
logger21.debug("invalidateLocation", { locations });
|
|
3731
3785
|
let keysToInvalidate = [];
|
|
3732
3786
|
if (locations.length === 0) {
|
|
3733
3787
|
await this.clearQueryResults();
|
|
@@ -3740,12 +3794,12 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3740
3794
|
}
|
|
3741
3795
|
}
|
|
3742
3796
|
async clearQueryResults() {
|
|
3743
|
-
|
|
3797
|
+
logger21.trace("clearQueryResults");
|
|
3744
3798
|
try {
|
|
3745
3799
|
return new Promise((resolve, reject) => {
|
|
3746
3800
|
const request = indexedDB.open(this.dbName, this.version);
|
|
3747
3801
|
request.onerror = () => {
|
|
3748
|
-
|
|
3802
|
+
logger21.error("Failed to open database for clearQueryResults", { error: request.error });
|
|
3749
3803
|
reject(request.error);
|
|
3750
3804
|
};
|
|
3751
3805
|
request.onsuccess = () => {
|
|
@@ -3755,7 +3809,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3755
3809
|
const cursorRequest = store.openCursor();
|
|
3756
3810
|
const keysToDelete = [];
|
|
3757
3811
|
cursorRequest.onerror = () => {
|
|
3758
|
-
|
|
3812
|
+
logger21.error("Failed to open cursor for clearQueryResults", { error: cursorRequest.error });
|
|
3759
3813
|
reject(cursorRequest.error);
|
|
3760
3814
|
};
|
|
3761
3815
|
cursorRequest.onsuccess = () => {
|
|
@@ -3776,7 +3830,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3776
3830
|
keysToDelete.forEach((queryKey) => {
|
|
3777
3831
|
const deleteRequest = store.delete(queryKey);
|
|
3778
3832
|
deleteRequest.onerror = () => {
|
|
3779
|
-
|
|
3833
|
+
logger21.error("Failed to delete query key", { queryKey, error: deleteRequest.error });
|
|
3780
3834
|
deletedCount++;
|
|
3781
3835
|
if (deletedCount === totalToDelete) {
|
|
3782
3836
|
resolve();
|
|
@@ -3794,14 +3848,14 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3794
3848
|
};
|
|
3795
3849
|
});
|
|
3796
3850
|
} catch (error) {
|
|
3797
|
-
|
|
3851
|
+
logger21.error("Error in clearQueryResults", { error });
|
|
3798
3852
|
throw error;
|
|
3799
3853
|
}
|
|
3800
3854
|
}
|
|
3801
3855
|
};
|
|
3802
3856
|
|
|
3803
3857
|
// src/browser/IndexDBCacheMap.ts
|
|
3804
|
-
var
|
|
3858
|
+
var logger22 = logger_default.get("IndexDBCacheMap");
|
|
3805
3859
|
var IndexDBCacheMap = class _IndexDBCacheMap extends CacheMap {
|
|
3806
3860
|
implementationType = "browser/indexedDB";
|
|
3807
3861
|
// Memory storage
|
|
@@ -3985,7 +4039,7 @@ var IndexDBCacheMap = class _IndexDBCacheMap extends CacheMap {
|
|
|
3985
4039
|
}
|
|
3986
4040
|
// Invalidation methods
|
|
3987
4041
|
async invalidateItemKeys(keys) {
|
|
3988
|
-
|
|
4042
|
+
logger22.debug("invalidateItemKeys", { keys });
|
|
3989
4043
|
if (keys.length === 0) {
|
|
3990
4044
|
return;
|
|
3991
4045
|
}
|
|
@@ -4015,7 +4069,7 @@ var IndexDBCacheMap = class _IndexDBCacheMap extends CacheMap {
|
|
|
4015
4069
|
queriesToRemove.forEach((queryHash) => {
|
|
4016
4070
|
delete this.queryResultCache[queryHash];
|
|
4017
4071
|
});
|
|
4018
|
-
|
|
4072
|
+
logger22.debug("Selectively invalidated queries referencing affected keys", {
|
|
4019
4073
|
affectedKeys: keys.length,
|
|
4020
4074
|
queriesRemoved: queriesToRemove.length,
|
|
4021
4075
|
totalQueries: Object.keys(this.queryResultCache).length
|
|
@@ -4398,7 +4452,7 @@ var reset = async (coordinate, options) => {
|
|
|
4398
4452
|
|
|
4399
4453
|
// src/Operations.ts
|
|
4400
4454
|
var createOperations = (api, coordinate, cacheMap, pkType, options, eventEmitter, ttlManager, evictionManager, statsManager, registry) => {
|
|
4401
|
-
const context = createCacheContext(api, cacheMap, pkType, options, eventEmitter, ttlManager, evictionManager, statsManager, registry);
|
|
4455
|
+
const context = createCacheContext(api, cacheMap, pkType, options, eventEmitter, ttlManager, evictionManager, statsManager, registry, coordinate);
|
|
4402
4456
|
return {
|
|
4403
4457
|
all: (query, locations) => all(query, locations, context).then(([ctx, result]) => result),
|
|
4404
4458
|
one: (query, locations) => one(query, locations, context).then(([ctx, result]) => result),
|
|
@@ -4419,7 +4473,7 @@ var createOperations = (api, coordinate, cacheMap, pkType, options, eventEmitter
|
|
|
4419
4473
|
};
|
|
4420
4474
|
|
|
4421
4475
|
// src/eviction/EvictionManager.ts
|
|
4422
|
-
var
|
|
4476
|
+
var logger23 = logger_default.get("EvictionManager");
|
|
4423
4477
|
var EvictionManager = class {
|
|
4424
4478
|
evictionStrategy;
|
|
4425
4479
|
constructor(evictionStrategy) {
|
|
@@ -4431,7 +4485,7 @@ var EvictionManager = class {
|
|
|
4431
4485
|
*/
|
|
4432
4486
|
setEvictionStrategy(strategy) {
|
|
4433
4487
|
this.evictionStrategy = strategy;
|
|
4434
|
-
|
|
4488
|
+
logger23.debug("Eviction strategy updated", {
|
|
4435
4489
|
strategy: strategy?.getStrategyName() || "none"
|
|
4436
4490
|
});
|
|
4437
4491
|
}
|
|
@@ -4454,7 +4508,7 @@ var EvictionManager = class {
|
|
|
4454
4508
|
try {
|
|
4455
4509
|
await this.evictionStrategy.onItemAccessed(key, metadataProvider);
|
|
4456
4510
|
} catch (error) {
|
|
4457
|
-
|
|
4511
|
+
logger23.error("Error in eviction strategy onItemAccessed", { key, error });
|
|
4458
4512
|
}
|
|
4459
4513
|
}
|
|
4460
4514
|
/**
|
|
@@ -4479,14 +4533,14 @@ var EvictionManager = class {
|
|
|
4479
4533
|
}
|
|
4480
4534
|
await this.evictionStrategy.onItemAdded(key, estimatedSize, metadataProvider);
|
|
4481
4535
|
if (evictedKeys.length > 0) {
|
|
4482
|
-
|
|
4536
|
+
logger23.debug("Items evicted during addition", {
|
|
4483
4537
|
newKey: key,
|
|
4484
4538
|
evictedKeys,
|
|
4485
4539
|
strategy: this.evictionStrategy.getStrategyName()
|
|
4486
4540
|
});
|
|
4487
4541
|
}
|
|
4488
4542
|
} catch (error) {
|
|
4489
|
-
|
|
4543
|
+
logger23.error("Error in eviction strategy onItemAdded", { key, error });
|
|
4490
4544
|
}
|
|
4491
4545
|
return evictedKeys;
|
|
4492
4546
|
}
|
|
@@ -4502,7 +4556,7 @@ var EvictionManager = class {
|
|
|
4502
4556
|
try {
|
|
4503
4557
|
this.evictionStrategy.onItemRemoved(key, metadataProvider);
|
|
4504
4558
|
} catch (error) {
|
|
4505
|
-
|
|
4559
|
+
logger23.error("Error in eviction strategy onItemRemoved", { key, error });
|
|
4506
4560
|
}
|
|
4507
4561
|
}
|
|
4508
4562
|
/**
|
|
@@ -4523,13 +4577,13 @@ var EvictionManager = class {
|
|
|
4523
4577
|
evictedKeys.push(evictKey);
|
|
4524
4578
|
}
|
|
4525
4579
|
if (evictedKeys.length > 0) {
|
|
4526
|
-
|
|
4580
|
+
logger23.debug("Manual eviction performed", {
|
|
4527
4581
|
evictedKeys,
|
|
4528
4582
|
strategy: this.evictionStrategy.getStrategyName()
|
|
4529
4583
|
});
|
|
4530
4584
|
}
|
|
4531
4585
|
} catch (error) {
|
|
4532
|
-
|
|
4586
|
+
logger23.error("Error in manual eviction", { error });
|
|
4533
4587
|
}
|
|
4534
4588
|
return evictedKeys;
|
|
4535
4589
|
}
|
|
@@ -4549,7 +4603,7 @@ var EvictionManager = class {
|
|
|
4549
4603
|
this.evictionStrategy.reset();
|
|
4550
4604
|
}
|
|
4551
4605
|
}
|
|
4552
|
-
|
|
4606
|
+
logger23.debug("Eviction manager cleared");
|
|
4553
4607
|
}
|
|
4554
4608
|
/**
|
|
4555
4609
|
* Create eviction context from current cache state
|
|
@@ -5887,7 +5941,7 @@ function createEvictionStrategy(policy, maxCacheSize, config) {
|
|
|
5887
5941
|
}
|
|
5888
5942
|
|
|
5889
5943
|
// src/ttl/TTLManager.ts
|
|
5890
|
-
var
|
|
5944
|
+
var logger24 = logger_default.get("TTLManager");
|
|
5891
5945
|
var TTLManager = class {
|
|
5892
5946
|
config;
|
|
5893
5947
|
cleanupTimer;
|
|
@@ -5899,7 +5953,7 @@ var TTLManager = class {
|
|
|
5899
5953
|
validateOnAccess: true,
|
|
5900
5954
|
...config
|
|
5901
5955
|
};
|
|
5902
|
-
|
|
5956
|
+
logger24.debug("TTL_DEBUG: TTLManager created", {
|
|
5903
5957
|
config: this.config,
|
|
5904
5958
|
isTTLEnabled: this.isTTLEnabled(),
|
|
5905
5959
|
defaultTTL: this.config.defaultTTL
|
|
@@ -5932,13 +5986,13 @@ var TTLManager = class {
|
|
|
5932
5986
|
this.startAutoCleanup();
|
|
5933
5987
|
}
|
|
5934
5988
|
}
|
|
5935
|
-
|
|
5989
|
+
logger24.debug("TTL configuration updated", { config: this.config });
|
|
5936
5990
|
}
|
|
5937
5991
|
/**
|
|
5938
5992
|
* Set TTL metadata for an item when it's added
|
|
5939
5993
|
*/
|
|
5940
5994
|
async onItemAdded(key, metadataProvider, itemTTL) {
|
|
5941
|
-
|
|
5995
|
+
logger24.debug("TTL_DEBUG: onItemAdded called", {
|
|
5942
5996
|
key,
|
|
5943
5997
|
itemTTL,
|
|
5944
5998
|
isTTLEnabled: this.isTTLEnabled(),
|
|
@@ -5946,19 +6000,19 @@ var TTLManager = class {
|
|
|
5946
6000
|
metadataProviderType: metadataProvider?.constructor?.name
|
|
5947
6001
|
});
|
|
5948
6002
|
if (!this.isTTLEnabled() && !itemTTL) {
|
|
5949
|
-
|
|
6003
|
+
logger24.debug("TTL_DEBUG: No TTL configured for item - returning early", { key });
|
|
5950
6004
|
return;
|
|
5951
6005
|
}
|
|
5952
|
-
|
|
6006
|
+
logger24.debug("TTL_DEBUG: Getting metadata for key", { key });
|
|
5953
6007
|
const metadata = await metadataProvider.getMetadata(key);
|
|
5954
|
-
|
|
6008
|
+
logger24.debug("TTL_DEBUG: Retrieved metadata", {
|
|
5955
6009
|
key,
|
|
5956
6010
|
hasMetadata: !!metadata,
|
|
5957
6011
|
metadataKeys: metadata ? Object.keys(metadata) : null,
|
|
5958
6012
|
metadata
|
|
5959
6013
|
});
|
|
5960
6014
|
if (!metadata) {
|
|
5961
|
-
|
|
6015
|
+
logger24.warning("TTL_DEBUG: No metadata found for item when setting TTL", {
|
|
5962
6016
|
key,
|
|
5963
6017
|
metadataProviderType: metadataProvider?.constructor?.name,
|
|
5964
6018
|
metadataProviderMethods: metadataProvider ? Object.getOwnPropertyNames(Object.getPrototypeOf(metadataProvider)) : null
|
|
@@ -5966,7 +6020,7 @@ var TTLManager = class {
|
|
|
5966
6020
|
return;
|
|
5967
6021
|
}
|
|
5968
6022
|
const ttl = itemTTL || this.config.defaultTTL;
|
|
5969
|
-
|
|
6023
|
+
logger24.debug("TTL_DEBUG: Calculated TTL value", {
|
|
5970
6024
|
key,
|
|
5971
6025
|
itemTTL,
|
|
5972
6026
|
defaultTTL: this.config.defaultTTL,
|
|
@@ -5979,7 +6033,7 @@ var TTLManager = class {
|
|
|
5979
6033
|
expiresAt: metadata.addedAt + ttl,
|
|
5980
6034
|
ttl
|
|
5981
6035
|
};
|
|
5982
|
-
|
|
6036
|
+
logger24.debug("TTL_DEBUG: Setting TTL metadata", {
|
|
5983
6037
|
key,
|
|
5984
6038
|
ttl,
|
|
5985
6039
|
addedAt: metadata.addedAt,
|
|
@@ -5987,9 +6041,9 @@ var TTLManager = class {
|
|
|
5987
6041
|
ttlMetadata
|
|
5988
6042
|
});
|
|
5989
6043
|
await metadataProvider.setMetadata(key, ttlMetadata);
|
|
5990
|
-
|
|
6044
|
+
logger24.trace("TTL_DEBUG: TTL set for item", { key, ttl, expiresAt: ttlMetadata.expiresAt });
|
|
5991
6045
|
} else {
|
|
5992
|
-
|
|
6046
|
+
logger24.debug("TTL_DEBUG: No TTL set - invalid TTL value", { key, ttl });
|
|
5993
6047
|
}
|
|
5994
6048
|
}
|
|
5995
6049
|
/**
|
|
@@ -6003,7 +6057,7 @@ var TTLManager = class {
|
|
|
6003
6057
|
const now = Date.now();
|
|
6004
6058
|
const expired = now >= metadata.expiresAt;
|
|
6005
6059
|
if (expired) {
|
|
6006
|
-
|
|
6060
|
+
logger24.trace("Item expired", { key, expiresAt: metadata.expiresAt, now });
|
|
6007
6061
|
}
|
|
6008
6062
|
return expired;
|
|
6009
6063
|
}
|
|
@@ -6050,7 +6104,7 @@ var TTLManager = class {
|
|
|
6050
6104
|
}
|
|
6051
6105
|
}
|
|
6052
6106
|
if (expiredKeys.length > 0) {
|
|
6053
|
-
|
|
6107
|
+
logger24.debug("Found expired items", { count: expiredKeys.length, keys: expiredKeys });
|
|
6054
6108
|
}
|
|
6055
6109
|
return expiredKeys;
|
|
6056
6110
|
}
|
|
@@ -6078,7 +6132,7 @@ var TTLManager = class {
|
|
|
6078
6132
|
}
|
|
6079
6133
|
metadata.expiresAt += additionalTTL;
|
|
6080
6134
|
await metadataProvider.setMetadata(key, metadata);
|
|
6081
|
-
|
|
6135
|
+
logger24.trace("TTL extended for item", { key, additionalTTL, newExpiresAt: metadata.expiresAt });
|
|
6082
6136
|
return true;
|
|
6083
6137
|
}
|
|
6084
6138
|
/**
|
|
@@ -6100,7 +6154,7 @@ var TTLManager = class {
|
|
|
6100
6154
|
ttl
|
|
6101
6155
|
};
|
|
6102
6156
|
await metadataProvider.setMetadata(key, ttlMetadata);
|
|
6103
|
-
|
|
6157
|
+
logger24.trace("TTL refreshed for item", { key, ttl, expiresAt: ttlMetadata.expiresAt });
|
|
6104
6158
|
return true;
|
|
6105
6159
|
}
|
|
6106
6160
|
/**
|
|
@@ -6112,9 +6166,9 @@ var TTLManager = class {
|
|
|
6112
6166
|
}
|
|
6113
6167
|
if (this.config.cleanupInterval) {
|
|
6114
6168
|
this.cleanupTimer = setInterval(() => {
|
|
6115
|
-
|
|
6169
|
+
logger24.trace("Auto cleanup timer triggered");
|
|
6116
6170
|
}, this.config.cleanupInterval);
|
|
6117
|
-
|
|
6171
|
+
logger24.debug("Auto cleanup started", { interval: this.config.cleanupInterval });
|
|
6118
6172
|
}
|
|
6119
6173
|
}
|
|
6120
6174
|
/**
|
|
@@ -6124,7 +6178,7 @@ var TTLManager = class {
|
|
|
6124
6178
|
if (this.cleanupTimer) {
|
|
6125
6179
|
clearInterval(this.cleanupTimer);
|
|
6126
6180
|
this.cleanupTimer = null;
|
|
6127
|
-
|
|
6181
|
+
logger24.debug("Auto cleanup stopped");
|
|
6128
6182
|
}
|
|
6129
6183
|
}
|
|
6130
6184
|
/**
|
|
@@ -6132,14 +6186,14 @@ var TTLManager = class {
|
|
|
6132
6186
|
*/
|
|
6133
6187
|
clear() {
|
|
6134
6188
|
this.stopAutoCleanup();
|
|
6135
|
-
|
|
6189
|
+
logger24.debug("TTL manager cleared");
|
|
6136
6190
|
}
|
|
6137
6191
|
/**
|
|
6138
6192
|
* Cleanup resources
|
|
6139
6193
|
*/
|
|
6140
6194
|
destroy() {
|
|
6141
6195
|
this.stopAutoCleanup();
|
|
6142
|
-
|
|
6196
|
+
logger24.debug("TTL manager destroyed");
|
|
6143
6197
|
}
|
|
6144
6198
|
};
|
|
6145
6199
|
|
|
@@ -6539,9 +6593,9 @@ var CacheStatsManager = class {
|
|
|
6539
6593
|
};
|
|
6540
6594
|
|
|
6541
6595
|
// src/Cache.ts
|
|
6542
|
-
var
|
|
6596
|
+
var logger25 = logger_default.get("Cache");
|
|
6543
6597
|
var createCache = (api, coordinate, registry, options) => {
|
|
6544
|
-
|
|
6598
|
+
logger25.debug("createCache", { coordinate, registry, options });
|
|
6545
6599
|
const completeOptions = createOptions(options);
|
|
6546
6600
|
const cacheMap = createCacheMap(coordinate.kta, completeOptions);
|
|
6547
6601
|
const pkType = coordinate.kta[0];
|
|
@@ -6621,13 +6675,13 @@ var isCache2 = (cache) => {
|
|
|
6621
6675
|
};
|
|
6622
6676
|
|
|
6623
6677
|
// src/InstanceFactory.ts
|
|
6624
|
-
var
|
|
6678
|
+
var logger26 = logger_default.get("InstanceFactory");
|
|
6625
6679
|
var createInstanceFactory = (api, options) => {
|
|
6626
6680
|
const templateOptions = createOptions(options);
|
|
6627
6681
|
validateOptions(templateOptions);
|
|
6628
6682
|
return (coordinate, context) => {
|
|
6629
6683
|
const instanceOptions = createOptions(options);
|
|
6630
|
-
|
|
6684
|
+
logger26.debug("Creating cache instance", {
|
|
6631
6685
|
coordinate,
|
|
6632
6686
|
registry: context.registry,
|
|
6633
6687
|
api,
|
|
@@ -6694,9 +6748,9 @@ var createInstanceFactory = (api, options) => {
|
|
|
6694
6748
|
};
|
|
6695
6749
|
|
|
6696
6750
|
// src/Instance.ts
|
|
6697
|
-
var
|
|
6751
|
+
var logger27 = logger_default.get("Instance");
|
|
6698
6752
|
var createInstance = (registry, coordinate, api, options) => {
|
|
6699
|
-
|
|
6753
|
+
logger27.debug("createInstance", { coordinate, api, registry, options });
|
|
6700
6754
|
return createCache(api, coordinate, registry, options);
|
|
6701
6755
|
};
|
|
6702
6756
|
var isInstance = (instance) => {
|
|
@@ -6704,7 +6758,7 @@ var isInstance = (instance) => {
|
|
|
6704
6758
|
};
|
|
6705
6759
|
|
|
6706
6760
|
// src/Aggregator.ts
|
|
6707
|
-
var
|
|
6761
|
+
var logger28 = logger_default.get("ItemAggregator");
|
|
6708
6762
|
var toCacheConfig = (config) => {
|
|
6709
6763
|
let cacheConfig;
|
|
6710
6764
|
if (config.optional === void 0) {
|
|
@@ -6716,22 +6770,22 @@ var toCacheConfig = (config) => {
|
|
|
6716
6770
|
};
|
|
6717
6771
|
var createAggregator = async (cache, { aggregates = {}, events = {} }) => {
|
|
6718
6772
|
const populate = async (item) => {
|
|
6719
|
-
|
|
6773
|
+
logger28.default("populate", { item });
|
|
6720
6774
|
for (const key in aggregates) {
|
|
6721
6775
|
await populateAggregate(key, item);
|
|
6722
6776
|
}
|
|
6723
6777
|
for (const key in events) {
|
|
6724
6778
|
await populateEvent(key, item);
|
|
6725
6779
|
}
|
|
6726
|
-
|
|
6780
|
+
logger28.default("populate done", { item });
|
|
6727
6781
|
return item;
|
|
6728
6782
|
};
|
|
6729
6783
|
const populateAggregate = async (key, item) => {
|
|
6730
|
-
|
|
6784
|
+
logger28.default("populate aggregate key", { key });
|
|
6731
6785
|
const cacheConfig = toCacheConfig(aggregates[key]);
|
|
6732
6786
|
if (item.refs === void 0) {
|
|
6733
6787
|
if (cacheConfig.optional === false) {
|
|
6734
|
-
|
|
6788
|
+
logger28.error("Item does not have refs an is not optional ", { item });
|
|
6735
6789
|
throw new Error("Item does not have refs an is not optional " + JSON.stringify(item));
|
|
6736
6790
|
} else {
|
|
6737
6791
|
if (item.events && Object.prototype.hasOwnProperty.call(item.events, key)) {
|
|
@@ -6740,7 +6794,7 @@ var createAggregator = async (cache, { aggregates = {}, events = {} }) => {
|
|
|
6740
6794
|
}
|
|
6741
6795
|
} else if (item.refs[key] === void 0) {
|
|
6742
6796
|
if (cacheConfig.optional === false) {
|
|
6743
|
-
|
|
6797
|
+
logger28.error("Item does not have mandatory ref with key, not optional ", { key, item });
|
|
6744
6798
|
throw new Error("Item does not have mandatory ref with key, not optional " + key + " " + JSON.stringify(item));
|
|
6745
6799
|
} else {
|
|
6746
6800
|
if (item.events && Object.prototype.hasOwnProperty.call(item.events, key)) {
|
|
@@ -6749,7 +6803,7 @@ var createAggregator = async (cache, { aggregates = {}, events = {} }) => {
|
|
|
6749
6803
|
}
|
|
6750
6804
|
} else {
|
|
6751
6805
|
const ref = item.refs[key];
|
|
6752
|
-
|
|
6806
|
+
logger28.default("AGG Retrieving Item in Populate", { key: ref });
|
|
6753
6807
|
const newItem = await cacheConfig.cache.operations.retrieve(ref);
|
|
6754
6808
|
if (newItem) {
|
|
6755
6809
|
if (item.aggs === void 0) {
|
|
@@ -6766,25 +6820,25 @@ var createAggregator = async (cache, { aggregates = {}, events = {} }) => {
|
|
|
6766
6820
|
}
|
|
6767
6821
|
};
|
|
6768
6822
|
const populateEvent = async (key, item) => {
|
|
6769
|
-
|
|
6823
|
+
logger28.default("populate event key", { key });
|
|
6770
6824
|
const cacheConfig = toCacheConfig(events[key]);
|
|
6771
6825
|
if (item.events === void 0) {
|
|
6772
6826
|
throw new Error("Item does not have events " + JSON.stringify(item));
|
|
6773
6827
|
} else if (item.events[key] === void 0) {
|
|
6774
6828
|
if (cacheConfig.optional === false) {
|
|
6775
|
-
|
|
6829
|
+
logger28.error("Item does not have mandatory event with key", { key, item });
|
|
6776
6830
|
throw new Error("Item does not have mandatory event with key " + key + " " + JSON.stringify(item));
|
|
6777
6831
|
}
|
|
6778
6832
|
} else {
|
|
6779
6833
|
const event = item.events[key];
|
|
6780
6834
|
if (event.by === void 0) {
|
|
6781
|
-
|
|
6835
|
+
logger28.error(
|
|
6782
6836
|
"populateEvent with an Event that does not have by",
|
|
6783
6837
|
{ event, ik: item.key, eventKey: key }
|
|
6784
6838
|
);
|
|
6785
6839
|
throw new Error("populateEvent with an Event that does not have by: " + JSON.stringify({ key }));
|
|
6786
6840
|
}
|
|
6787
|
-
|
|
6841
|
+
logger28.default("EVENT Retrieving Item in Populate", { key: event.by });
|
|
6788
6842
|
const newItem = await cacheConfig.cache.operations.retrieve(event.by);
|
|
6789
6843
|
if (newItem) {
|
|
6790
6844
|
event.agg = newItem;
|
|
@@ -6792,13 +6846,13 @@ var createAggregator = async (cache, { aggregates = {}, events = {} }) => {
|
|
|
6792
6846
|
}
|
|
6793
6847
|
};
|
|
6794
6848
|
const all2 = async (query = {}, locations = []) => {
|
|
6795
|
-
|
|
6849
|
+
logger28.default("all", { query, locations });
|
|
6796
6850
|
const items = await cache.operations.all(query, locations);
|
|
6797
6851
|
const populatedItems = await Promise.all(items.map(async (item) => populate(item)));
|
|
6798
6852
|
return populatedItems;
|
|
6799
6853
|
};
|
|
6800
6854
|
const one2 = async (query = {}, locations = []) => {
|
|
6801
|
-
|
|
6855
|
+
logger28.default("one", { query, locations });
|
|
6802
6856
|
const item = await cache.operations.one(query, locations);
|
|
6803
6857
|
let populatedItem = null;
|
|
6804
6858
|
if (item) {
|
|
@@ -6807,30 +6861,30 @@ var createAggregator = async (cache, { aggregates = {}, events = {} }) => {
|
|
|
6807
6861
|
return populatedItem;
|
|
6808
6862
|
};
|
|
6809
6863
|
const action2 = async (key, action3, body = {}) => {
|
|
6810
|
-
|
|
6864
|
+
logger28.default("action", { key, action: action3, body });
|
|
6811
6865
|
const [item, affectedItems] = await cache.operations.action(key, action3, body);
|
|
6812
6866
|
const populatedItem = await populate(item);
|
|
6813
6867
|
return [populatedItem, affectedItems];
|
|
6814
6868
|
};
|
|
6815
6869
|
const allAction2 = async (action3, body = {}, locations = []) => {
|
|
6816
|
-
|
|
6870
|
+
logger28.default("action", { action: action3, body, locations });
|
|
6817
6871
|
const [items, affectedItems] = await cache.operations.allAction(action3, body, locations);
|
|
6818
6872
|
const populatedItems = await Promise.all(items.map(async (item) => populate(item)));
|
|
6819
6873
|
return [populatedItems, affectedItems];
|
|
6820
6874
|
};
|
|
6821
6875
|
const allFacet2 = async (facet3, params = {}, locations = []) => {
|
|
6822
|
-
|
|
6876
|
+
logger28.default("allFacet", { facet: facet3, params, locations });
|
|
6823
6877
|
const response = await cache.operations.allFacet(facet3, params, locations);
|
|
6824
6878
|
return response;
|
|
6825
6879
|
};
|
|
6826
6880
|
const create2 = async (v, locations = []) => {
|
|
6827
|
-
|
|
6881
|
+
logger28.default("create", { v, locations });
|
|
6828
6882
|
const item = await cache.operations.create(v, locations);
|
|
6829
6883
|
const populatedItem = await populate(item);
|
|
6830
6884
|
return populatedItem;
|
|
6831
6885
|
};
|
|
6832
6886
|
const get2 = async (key) => {
|
|
6833
|
-
|
|
6887
|
+
logger28.default("get", { key });
|
|
6834
6888
|
const item = await cache.operations.get(key);
|
|
6835
6889
|
let populatedItem = null;
|
|
6836
6890
|
if (item) {
|
|
@@ -6839,7 +6893,7 @@ var createAggregator = async (cache, { aggregates = {}, events = {} }) => {
|
|
|
6839
6893
|
return populatedItem;
|
|
6840
6894
|
};
|
|
6841
6895
|
const retrieve2 = async (key) => {
|
|
6842
|
-
|
|
6896
|
+
logger28.default("retrieve", { key });
|
|
6843
6897
|
const item = await cache.operations.retrieve(key);
|
|
6844
6898
|
let populatedItem = null;
|
|
6845
6899
|
if (item) {
|
|
@@ -6848,34 +6902,34 @@ var createAggregator = async (cache, { aggregates = {}, events = {} }) => {
|
|
|
6848
6902
|
return populatedItem;
|
|
6849
6903
|
};
|
|
6850
6904
|
const remove2 = async (key) => {
|
|
6851
|
-
|
|
6905
|
+
logger28.default("remove", { key });
|
|
6852
6906
|
await cache.operations.remove(key);
|
|
6853
6907
|
};
|
|
6854
6908
|
const update2 = async (key, v) => {
|
|
6855
|
-
|
|
6909
|
+
logger28.default("update", { key, v });
|
|
6856
6910
|
const item = await cache.operations.update(key, v);
|
|
6857
6911
|
const populatedItem = await populate(item);
|
|
6858
6912
|
return populatedItem;
|
|
6859
6913
|
};
|
|
6860
6914
|
const facet2 = async (key, facet3) => {
|
|
6861
|
-
|
|
6915
|
+
logger28.default("facet", { key, facet: facet3 });
|
|
6862
6916
|
const response = await cache.operations.facet(key, facet3);
|
|
6863
6917
|
return response;
|
|
6864
6918
|
};
|
|
6865
6919
|
const find2 = async (finder, finderParams = {}, locations = []) => {
|
|
6866
|
-
|
|
6920
|
+
logger28.default("find", { finder, finderParams, locations });
|
|
6867
6921
|
const items = await cache.operations.find(finder, finderParams, locations);
|
|
6868
6922
|
const populatedItems = await Promise.all(items.map(async (item) => populate(item)));
|
|
6869
6923
|
return populatedItems;
|
|
6870
6924
|
};
|
|
6871
6925
|
const findOne2 = async (finder, finderParams = {}, locations = []) => {
|
|
6872
|
-
|
|
6926
|
+
logger28.default("find", { finder, finderParams, locations });
|
|
6873
6927
|
const item = await cache.operations.findOne(finder, finderParams, locations);
|
|
6874
6928
|
const populatedItem = await populate(item);
|
|
6875
6929
|
return populatedItem;
|
|
6876
6930
|
};
|
|
6877
6931
|
const set2 = async (key, v) => {
|
|
6878
|
-
|
|
6932
|
+
logger28.default("set", { key, v });
|
|
6879
6933
|
const item = await cache.operations.set(key, v);
|
|
6880
6934
|
const populatedItem = await populate(item);
|
|
6881
6935
|
return populatedItem;
|
|
@@ -6927,13 +6981,13 @@ var createAggregator = async (cache, { aggregates = {}, events = {} }) => {
|
|
|
6927
6981
|
import {
|
|
6928
6982
|
createRegistry as createBaseRegistry
|
|
6929
6983
|
} from "@fjell/registry";
|
|
6930
|
-
var
|
|
6984
|
+
var logger29 = logger_default.get("Registry");
|
|
6931
6985
|
var createRegistryFactory = () => {
|
|
6932
6986
|
return (type, registryHub) => {
|
|
6933
6987
|
if (type !== "cache") {
|
|
6934
6988
|
throw new Error(`Cache registry factory can only create 'cache' type registries, got: ${type}`);
|
|
6935
6989
|
}
|
|
6936
|
-
|
|
6990
|
+
logger29.debug("Creating cache registry", { type, registryHub });
|
|
6937
6991
|
const baseRegistry = createBaseRegistry(type, registryHub);
|
|
6938
6992
|
return baseRegistry;
|
|
6939
6993
|
};
|