@fjell/cache 4.7.33 → 4.7.35
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/MIGRATION_v3.md +249 -0
- package/README.md +24 -0
- package/dist/Aggregator.d.ts.map +1 -1
- package/dist/Cache.d.ts +2 -1
- package/dist/Cache.d.ts.map +1 -1
- package/dist/CacheContext.d.ts +2 -1
- package/dist/CacheContext.d.ts.map +1 -1
- package/dist/Instance.d.ts +2 -1
- package/dist/Instance.d.ts.map +1 -1
- package/dist/Operations.d.ts +16 -55
- package/dist/Operations.d.ts.map +1 -1
- package/dist/index.js +601 -511
- package/dist/ops/action.d.ts.map +1 -1
- 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/facet.d.ts.map +1 -1
- package/dist/ops/find.d.ts.map +1 -1
- package/dist/ops/findOne.d.ts +1 -1
- package/dist/ops/findOne.d.ts.map +1 -1
- package/dist/ops/get.d.ts.map +1 -1
- package/dist/ops/one.d.ts.map +1 -1
- package/dist/ops/remove.d.ts.map +1 -1
- package/dist/ops/reset.d.ts +1 -2
- package/dist/ops/reset.d.ts.map +1 -1
- package/dist/ops/retrieve.d.ts.map +1 -1
- package/dist/ops/set.d.ts.map +1 -1
- package/dist/ops/update.d.ts.map +1 -1
- package/package.json +6 -6
- package/dist/validation/LocationKeyValidator.d.ts +0 -13
- package/dist/validation/LocationKeyValidator.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
// src/Operations.ts
|
|
2
|
+
import {
|
|
3
|
+
isOperationComKey as isComKey7,
|
|
4
|
+
isOperationPriKey as isPriKey
|
|
5
|
+
} from "@fjell/core";
|
|
6
|
+
|
|
1
7
|
// src/CacheContext.ts
|
|
2
8
|
var createCacheContext = (api, cacheMap, pkType, options, eventEmitter, ttlManager, evictionManager, statsManager, registry, coordinate) => {
|
|
3
9
|
return {
|
|
@@ -16,7 +22,7 @@ var createCacheContext = (api, cacheMap, pkType, options, eventEmitter, ttlManag
|
|
|
16
22
|
|
|
17
23
|
// src/ops/all.ts
|
|
18
24
|
import {
|
|
19
|
-
|
|
25
|
+
createAllWrapper
|
|
20
26
|
} from "@fjell/core";
|
|
21
27
|
import { NotFoundError } from "@fjell/http-api";
|
|
22
28
|
|
|
@@ -314,74 +320,38 @@ import Logging from "@fjell/logging";
|
|
|
314
320
|
var LibLogger = Logging.getLogger("@fjell/cache");
|
|
315
321
|
var logger_default = LibLogger;
|
|
316
322
|
|
|
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
|
-
|
|
363
323
|
// src/ops/all.ts
|
|
364
|
-
var
|
|
324
|
+
var logger = logger_default.get("all");
|
|
365
325
|
var all = async (query = {}, locations = [], context) => {
|
|
366
326
|
const { api, cacheMap, pkType, ttlManager, coordinate } = context;
|
|
367
|
-
|
|
368
|
-
|
|
327
|
+
logger.default("all", { query, locations });
|
|
328
|
+
const wrappedAll = createAllWrapper(
|
|
329
|
+
coordinate,
|
|
330
|
+
async (q, locs) => {
|
|
331
|
+
return await executeAllLogic(q ?? {}, locs ?? [], context);
|
|
332
|
+
}
|
|
333
|
+
);
|
|
334
|
+
const result = await wrappedAll(query, locations);
|
|
335
|
+
return [context, result];
|
|
336
|
+
};
|
|
337
|
+
async function executeAllLogic(query, locations, context) {
|
|
338
|
+
const { api, cacheMap, pkType, ttlManager } = context;
|
|
369
339
|
if (context.options?.bypassCache) {
|
|
370
|
-
|
|
340
|
+
logger.debug("Cache bypass enabled, fetching directly from API", { query, locations });
|
|
371
341
|
try {
|
|
372
342
|
const ret2 = await api.all(query, locations);
|
|
373
|
-
|
|
374
|
-
return
|
|
343
|
+
logger.debug("API response received (not cached due to bypass)", { query, locations, itemCount: ret2.length });
|
|
344
|
+
return ret2;
|
|
375
345
|
} catch (error) {
|
|
376
|
-
|
|
346
|
+
logger.error("API request failed", { query, locations, error });
|
|
377
347
|
throw error;
|
|
378
348
|
}
|
|
379
349
|
}
|
|
380
350
|
const queryHash = createQueryHash(pkType, query, locations);
|
|
381
|
-
|
|
351
|
+
logger.debug("Generated query hash for all", { queryHash });
|
|
382
352
|
const cachedItemKeys = await cacheMap.getQueryResult(queryHash);
|
|
383
353
|
if (cachedItemKeys) {
|
|
384
|
-
|
|
354
|
+
logger.debug("Using cached query results", { cachedKeyCount: cachedItemKeys.length });
|
|
385
355
|
const cachedItems = [];
|
|
386
356
|
let allItemsAvailable = true;
|
|
387
357
|
for (const itemKey of cachedItemKeys) {
|
|
@@ -394,23 +364,23 @@ var all = async (query = {}, locations = [], context) => {
|
|
|
394
364
|
}
|
|
395
365
|
}
|
|
396
366
|
if (allItemsAvailable) {
|
|
397
|
-
return
|
|
367
|
+
return cachedItems;
|
|
398
368
|
} else {
|
|
399
|
-
|
|
369
|
+
logger.debug("Some cached items missing, invalidating query cache");
|
|
400
370
|
cacheMap.deleteQueryResult(queryHash);
|
|
401
371
|
}
|
|
402
372
|
}
|
|
403
373
|
try {
|
|
404
374
|
const directCachedItems = await cacheMap.queryIn(query, locations);
|
|
405
375
|
if (directCachedItems && directCachedItems.length > 0) {
|
|
406
|
-
|
|
376
|
+
logger.debug("Found items directly in cache, skipping API call", { itemCount: directCachedItems.length });
|
|
407
377
|
const itemKeys = directCachedItems.map((item) => item.key);
|
|
408
378
|
await cacheMap.setQueryResult(queryHash, itemKeys);
|
|
409
|
-
|
|
410
|
-
return
|
|
379
|
+
logger.debug("Cached query result from direct cache hit", { queryHash, itemKeyCount: itemKeys.length });
|
|
380
|
+
return directCachedItems;
|
|
411
381
|
}
|
|
412
382
|
} catch (error) {
|
|
413
|
-
|
|
383
|
+
logger.debug("Error querying cache directly, proceeding to API", { error });
|
|
414
384
|
}
|
|
415
385
|
let ret = [];
|
|
416
386
|
try {
|
|
@@ -427,23 +397,23 @@ var all = async (query = {}, locations = [], context) => {
|
|
|
427
397
|
}
|
|
428
398
|
const itemKeys = ret.map((item) => item.key);
|
|
429
399
|
cacheMap.setQueryResult(queryHash, itemKeys);
|
|
430
|
-
|
|
400
|
+
logger.debug("Cached query result", { queryHash, itemKeyCount: itemKeys.length });
|
|
431
401
|
const event = CacheEventFactory.createQueryEvent(query, locations, ret);
|
|
432
402
|
context.eventEmitter.emit(event);
|
|
433
403
|
} catch (e) {
|
|
434
404
|
if (e instanceof NotFoundError) {
|
|
435
405
|
cacheMap.setQueryResult(queryHash, []);
|
|
436
|
-
|
|
406
|
+
logger.debug("Cached empty query result for not found", { queryHash });
|
|
437
407
|
} else {
|
|
438
408
|
throw e;
|
|
439
409
|
}
|
|
440
410
|
}
|
|
441
|
-
return
|
|
442
|
-
}
|
|
411
|
+
return ret;
|
|
412
|
+
}
|
|
443
413
|
|
|
444
414
|
// src/ops/one.ts
|
|
445
415
|
import {
|
|
446
|
-
|
|
416
|
+
createOneWrapper
|
|
447
417
|
} from "@fjell/core";
|
|
448
418
|
import { NotFoundError as NotFoundError2 } from "@fjell/http-api";
|
|
449
419
|
|
|
@@ -608,54 +578,64 @@ function validateSizeConfig(config) {
|
|
|
608
578
|
}
|
|
609
579
|
|
|
610
580
|
// src/ops/one.ts
|
|
611
|
-
var
|
|
581
|
+
var logger2 = logger_default.get("one");
|
|
612
582
|
var one = async (query = {}, locations = [], context) => {
|
|
613
583
|
const { api, cacheMap, pkType, ttlManager, coordinate } = context;
|
|
614
|
-
|
|
615
|
-
|
|
584
|
+
logger2.default("one", { query, locations });
|
|
585
|
+
const wrappedOne = createOneWrapper(
|
|
586
|
+
coordinate,
|
|
587
|
+
async (q, locs) => {
|
|
588
|
+
return await executeOneLogic(q ?? {}, locs ?? [], context);
|
|
589
|
+
}
|
|
590
|
+
);
|
|
591
|
+
const result = await wrappedOne(query, locations);
|
|
592
|
+
return [context, result];
|
|
593
|
+
};
|
|
594
|
+
async function executeOneLogic(query, locations, context) {
|
|
595
|
+
const { api, cacheMap, pkType, ttlManager } = context;
|
|
616
596
|
if (context.options?.bypassCache) {
|
|
617
|
-
|
|
597
|
+
logger2.debug("Cache bypass enabled, fetching directly from API", { query, locations });
|
|
618
598
|
try {
|
|
619
599
|
const retItem2 = await api.one(query, locations);
|
|
620
600
|
if (retItem2) {
|
|
621
|
-
|
|
622
|
-
return
|
|
601
|
+
logger2.debug("API response received (not cached due to bypass)", { query, locations });
|
|
602
|
+
return retItem2;
|
|
623
603
|
} else {
|
|
624
|
-
|
|
625
|
-
return
|
|
604
|
+
logger2.debug("API returned null", { query, locations });
|
|
605
|
+
return null;
|
|
626
606
|
}
|
|
627
607
|
} catch (error) {
|
|
628
|
-
|
|
608
|
+
logger2.error("API request failed", { query, locations, error });
|
|
629
609
|
throw error;
|
|
630
610
|
}
|
|
631
611
|
}
|
|
632
612
|
const queryHash = createQueryHash(pkType, query, locations);
|
|
633
|
-
|
|
613
|
+
logger2.debug("Generated query hash for one", { queryHash });
|
|
634
614
|
const cachedItemKeys = await cacheMap.getQueryResult(queryHash);
|
|
635
615
|
if (cachedItemKeys) {
|
|
636
|
-
|
|
616
|
+
logger2.debug("Using cached query results", { cachedKeyCount: cachedItemKeys.length });
|
|
637
617
|
if (cachedItemKeys.length === 0) {
|
|
638
|
-
return
|
|
618
|
+
return null;
|
|
639
619
|
}
|
|
640
620
|
const item = await cacheMap.get(cachedItemKeys[0]);
|
|
641
621
|
if (item) {
|
|
642
|
-
return
|
|
622
|
+
return item;
|
|
643
623
|
} else {
|
|
644
|
-
|
|
624
|
+
logger2.debug("Cached item missing, invalidating query cache");
|
|
645
625
|
cacheMap.deleteQueryResult(queryHash);
|
|
646
626
|
}
|
|
647
627
|
}
|
|
648
628
|
try {
|
|
649
629
|
const directCachedItems = await cacheMap.queryIn(query, locations);
|
|
650
630
|
if (directCachedItems && directCachedItems.length > 0) {
|
|
651
|
-
|
|
631
|
+
logger2.debug("Found item directly in cache, skipping API call");
|
|
652
632
|
const foundItem = directCachedItems[0];
|
|
653
633
|
await cacheMap.setQueryResult(queryHash, [foundItem.key]);
|
|
654
|
-
|
|
655
|
-
return
|
|
634
|
+
logger2.debug("Cached query result from direct cache hit", { queryHash, itemKey: foundItem.key });
|
|
635
|
+
return foundItem;
|
|
656
636
|
}
|
|
657
637
|
} catch (error) {
|
|
658
|
-
|
|
638
|
+
logger2.debug("Error querying cache directly, proceeding to API", { error });
|
|
659
639
|
}
|
|
660
640
|
let retItem = null;
|
|
661
641
|
try {
|
|
@@ -682,35 +662,43 @@ var one = async (query = {}, locations = [], context) => {
|
|
|
682
662
|
await cacheMap.delete(parsedKey);
|
|
683
663
|
}
|
|
684
664
|
await cacheMap.setQueryResult(queryHash, [retItem.key]);
|
|
685
|
-
|
|
665
|
+
logger2.debug("Cached query result", { queryHash, itemKey: retItem.key });
|
|
686
666
|
} else {
|
|
687
667
|
await cacheMap.setQueryResult(queryHash, []);
|
|
688
|
-
|
|
668
|
+
logger2.debug("Cached empty query result", { queryHash });
|
|
689
669
|
}
|
|
690
670
|
} catch (e) {
|
|
691
671
|
if (e instanceof NotFoundError2) {
|
|
692
672
|
cacheMap.setQueryResult(queryHash, []);
|
|
693
|
-
|
|
673
|
+
logger2.debug("Cached empty query result for not found", { queryHash });
|
|
694
674
|
} else {
|
|
695
675
|
throw e;
|
|
696
676
|
}
|
|
697
677
|
}
|
|
698
|
-
return
|
|
699
|
-
|
|
700
|
-
retItem ? validatePK2(retItem, pkType) : null
|
|
701
|
-
];
|
|
702
|
-
};
|
|
678
|
+
return retItem || null;
|
|
679
|
+
}
|
|
703
680
|
|
|
704
681
|
// src/ops/create.ts
|
|
705
682
|
import {
|
|
706
|
-
|
|
683
|
+
createCreateWrapper
|
|
707
684
|
} from "@fjell/core";
|
|
708
|
-
var
|
|
685
|
+
var logger3 = logger_default.get("create");
|
|
709
686
|
var create = async (v, locations = [], context) => {
|
|
710
|
-
const {
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
687
|
+
const { coordinate } = context;
|
|
688
|
+
logger3.default("create", { v, locations });
|
|
689
|
+
const wrappedCreate = createCreateWrapper(
|
|
690
|
+
coordinate,
|
|
691
|
+
async (item, createOptions2) => {
|
|
692
|
+
const locs = createOptions2?.locations ?? [];
|
|
693
|
+
return await executeCreateLogic(item, locs, context);
|
|
694
|
+
}
|
|
695
|
+
);
|
|
696
|
+
const result = await wrappedCreate(v, locations.length > 0 ? { locations } : void 0);
|
|
697
|
+
return [context, result];
|
|
698
|
+
};
|
|
699
|
+
async function executeCreateLogic(v, locations, context) {
|
|
700
|
+
const { api, cacheMap, pkType, eventEmitter, ttlManager, evictionManager } = context;
|
|
701
|
+
const created = await api.create(v, locations.length > 0 ? { locations } : void 0);
|
|
714
702
|
cacheMap.set(created.key, created);
|
|
715
703
|
const keyStr = JSON.stringify(created.key);
|
|
716
704
|
ttlManager.onItemAdded(keyStr, cacheMap);
|
|
@@ -729,15 +717,15 @@ var create = async (v, locations = [], context) => {
|
|
|
729
717
|
{ source: "operation", context: { operation: "create" } }
|
|
730
718
|
);
|
|
731
719
|
eventEmitter.emit(queryInvalidatedEvent);
|
|
732
|
-
return
|
|
733
|
-
}
|
|
720
|
+
return created;
|
|
721
|
+
}
|
|
734
722
|
|
|
735
723
|
// src/ops/get.ts
|
|
736
724
|
import {
|
|
737
|
-
|
|
738
|
-
|
|
725
|
+
createGetWrapper,
|
|
726
|
+
isValidItemKey
|
|
739
727
|
} from "@fjell/core";
|
|
740
|
-
var
|
|
728
|
+
var logger4 = logger_default.get("get");
|
|
741
729
|
var inFlightRequests = /* @__PURE__ */ new Map();
|
|
742
730
|
var CLEANUP_TIMEOUT = 5 * 60 * 1e3;
|
|
743
731
|
var cleanupStaleRequests = () => {
|
|
@@ -749,34 +737,45 @@ var cleanupStaleRequests = () => {
|
|
|
749
737
|
}
|
|
750
738
|
});
|
|
751
739
|
keysToDelete.forEach((key) => {
|
|
752
|
-
|
|
740
|
+
logger4.debug("Cleaning up stale in-flight request", { key });
|
|
753
741
|
inFlightRequests.delete(key);
|
|
754
742
|
});
|
|
755
743
|
};
|
|
756
744
|
var cleanupInterval = setInterval(cleanupStaleRequests, 60 * 1e3);
|
|
757
745
|
var keyToString = createNormalizedHashFunction();
|
|
758
746
|
var get = async (key, context) => {
|
|
747
|
+
const { api, cacheMap, pkType, ttlManager, statsManager, coordinate } = context;
|
|
748
|
+
logger4.default("get", { key, defaultTTL: ttlManager.getDefaultTTL() });
|
|
749
|
+
const wrappedGet = createGetWrapper(
|
|
750
|
+
coordinate,
|
|
751
|
+
async (k) => {
|
|
752
|
+
return await executeGetLogic(k, context);
|
|
753
|
+
}
|
|
754
|
+
);
|
|
755
|
+
const result = await wrappedGet(key);
|
|
756
|
+
return [context, result];
|
|
757
|
+
};
|
|
758
|
+
async function executeGetLogic(key, context) {
|
|
759
759
|
const { api, cacheMap, pkType, ttlManager, statsManager } = context;
|
|
760
|
-
logger5.default("get", { key, defaultTTL: ttlManager.getDefaultTTL() });
|
|
761
760
|
statsManager.incrementRequests();
|
|
762
761
|
if (!isValidItemKey(key)) {
|
|
763
|
-
|
|
762
|
+
logger4.error("Key for Get is not a valid ItemKey: %j", key);
|
|
764
763
|
throw new Error("Key for Get is not a valid ItemKey");
|
|
765
764
|
}
|
|
766
765
|
if (context.options?.bypassCache) {
|
|
767
|
-
|
|
766
|
+
logger4.debug("Cache bypass enabled, fetching directly from API", { key });
|
|
768
767
|
statsManager.incrementMisses();
|
|
769
768
|
try {
|
|
770
769
|
const ret2 = await api.get(key);
|
|
771
770
|
if (ret2) {
|
|
772
|
-
|
|
773
|
-
return
|
|
771
|
+
logger4.debug("API response received (not cached due to bypass)", { key });
|
|
772
|
+
return ret2;
|
|
774
773
|
} else {
|
|
775
|
-
|
|
776
|
-
return
|
|
774
|
+
logger4.debug("API returned null", { key });
|
|
775
|
+
return null;
|
|
777
776
|
}
|
|
778
777
|
} catch (error) {
|
|
779
|
-
|
|
778
|
+
logger4.error("API request failed", { key, error });
|
|
780
779
|
throw error;
|
|
781
780
|
}
|
|
782
781
|
}
|
|
@@ -786,24 +785,24 @@ var get = async (key, context) => {
|
|
|
786
785
|
if (cachedItem) {
|
|
787
786
|
const isValid = await ttlManager.validateItem(keyStr2, cacheMap);
|
|
788
787
|
if (isValid) {
|
|
789
|
-
|
|
788
|
+
logger4.debug("Cache hit with valid TTL", { key, defaultTTL: ttlManager.getDefaultTTL() });
|
|
790
789
|
statsManager.incrementHits();
|
|
791
|
-
return
|
|
790
|
+
return cachedItem;
|
|
792
791
|
} else {
|
|
793
|
-
|
|
792
|
+
logger4.debug("Cache item expired, removing", { key });
|
|
794
793
|
cacheMap.delete(key);
|
|
795
794
|
statsManager.incrementMisses();
|
|
796
795
|
}
|
|
797
796
|
} else {
|
|
798
797
|
statsManager.incrementMisses();
|
|
799
798
|
}
|
|
800
|
-
|
|
799
|
+
logger4.debug("Cache miss or expired", { key, defaultTTL: ttlManager.getDefaultTTL() });
|
|
801
800
|
} else {
|
|
802
801
|
const cachedItem = await cacheMap.get(key);
|
|
803
802
|
if (cachedItem) {
|
|
804
|
-
|
|
803
|
+
logger4.debug("Cache hit (TTL disabled)", { key });
|
|
805
804
|
statsManager.incrementHits();
|
|
806
|
-
return
|
|
805
|
+
return cachedItem;
|
|
807
806
|
} else {
|
|
808
807
|
statsManager.incrementMisses();
|
|
809
808
|
}
|
|
@@ -826,7 +825,7 @@ var get = async (key, context) => {
|
|
|
826
825
|
}
|
|
827
826
|
}
|
|
828
827
|
} else {
|
|
829
|
-
|
|
828
|
+
logger4.debug("Using in-flight request for key", { key });
|
|
830
829
|
apiRequest = requestEntry.promise;
|
|
831
830
|
}
|
|
832
831
|
ret = await apiRequest;
|
|
@@ -856,44 +855,40 @@ var get = async (key, context) => {
|
|
|
856
855
|
}
|
|
857
856
|
} catch (e) {
|
|
858
857
|
inFlightRequests.delete(keyStr);
|
|
859
|
-
|
|
858
|
+
logger4.error("Error getting item for key", { key, message: e.message, stack: e.stack });
|
|
860
859
|
throw e;
|
|
861
860
|
}
|
|
862
|
-
return
|
|
863
|
-
|
|
864
|
-
ret ? validatePK4(ret, pkType) : null
|
|
865
|
-
];
|
|
866
|
-
};
|
|
861
|
+
return ret || null;
|
|
862
|
+
}
|
|
867
863
|
|
|
868
864
|
// src/ops/retrieve.ts
|
|
869
865
|
import {
|
|
870
|
-
isValidItemKey as isValidItemKey2
|
|
871
|
-
validatePK as validatePK5
|
|
866
|
+
isValidItemKey as isValidItemKey2
|
|
872
867
|
} from "@fjell/core";
|
|
873
|
-
var
|
|
868
|
+
var logger5 = logger_default.get("retrieve");
|
|
874
869
|
var retrieve = async (key, context) => {
|
|
875
870
|
const { cacheMap, pkType, statsManager } = context;
|
|
876
|
-
|
|
871
|
+
logger5.default("retrieve", { key });
|
|
877
872
|
statsManager.incrementRequests();
|
|
878
873
|
if (!isValidItemKey2(key)) {
|
|
879
|
-
|
|
874
|
+
logger5.error("Key for Retrieve is not a valid ItemKey: %j", key);
|
|
880
875
|
throw new Error("Key for Retrieve is not a valid ItemKey");
|
|
881
876
|
}
|
|
882
877
|
if (context.options?.bypassCache) {
|
|
883
|
-
|
|
878
|
+
logger5.debug("Cache bypass enabled, fetching directly from API", { key });
|
|
884
879
|
statsManager.incrementMisses();
|
|
885
880
|
try {
|
|
886
881
|
const { api } = context;
|
|
887
882
|
const retrieved2 = await api.get(key);
|
|
888
883
|
if (retrieved2) {
|
|
889
|
-
|
|
890
|
-
return [null,
|
|
884
|
+
logger5.debug("API response received (not cached due to bypass)", { key });
|
|
885
|
+
return [null, retrieved2];
|
|
891
886
|
} else {
|
|
892
|
-
|
|
887
|
+
logger5.debug("API returned null", { key });
|
|
893
888
|
return [null, null];
|
|
894
889
|
}
|
|
895
890
|
} catch (error) {
|
|
896
|
-
|
|
891
|
+
logger5.error("API request failed", { key, error });
|
|
897
892
|
throw error;
|
|
898
893
|
}
|
|
899
894
|
}
|
|
@@ -901,32 +896,44 @@ var retrieve = async (key, context) => {
|
|
|
901
896
|
let retrieved;
|
|
902
897
|
let contextToReturn;
|
|
903
898
|
if (containsItemKey) {
|
|
904
|
-
|
|
899
|
+
logger5.default("Looking for Object in Cache", key);
|
|
905
900
|
retrieved = await cacheMap.get(key);
|
|
906
901
|
contextToReturn = null;
|
|
907
902
|
statsManager.incrementHits();
|
|
908
903
|
} else {
|
|
909
|
-
|
|
904
|
+
logger5.default("Object Not Found in Cache, Retrieving from Server API", { key });
|
|
910
905
|
statsManager.incrementMisses();
|
|
911
906
|
[contextToReturn, retrieved] = await get(key, context);
|
|
912
907
|
}
|
|
913
908
|
const retValue = [
|
|
914
909
|
contextToReturn,
|
|
915
|
-
retrieved
|
|
910
|
+
retrieved || null
|
|
916
911
|
];
|
|
917
912
|
return retValue;
|
|
918
913
|
};
|
|
919
914
|
|
|
920
915
|
// src/ops/remove.ts
|
|
921
916
|
import {
|
|
917
|
+
createRemoveWrapper,
|
|
922
918
|
isValidItemKey as isValidItemKey3
|
|
923
919
|
} from "@fjell/core";
|
|
924
|
-
var
|
|
920
|
+
var logger6 = logger_default.get("remove");
|
|
925
921
|
var remove = async (key, context) => {
|
|
922
|
+
const { coordinate } = context;
|
|
923
|
+
logger6.default("remove", { key });
|
|
924
|
+
const wrappedRemove = createRemoveWrapper(
|
|
925
|
+
coordinate,
|
|
926
|
+
async (k) => {
|
|
927
|
+
await executeRemoveLogic(k, context);
|
|
928
|
+
}
|
|
929
|
+
);
|
|
930
|
+
await wrappedRemove(key);
|
|
931
|
+
return context;
|
|
932
|
+
};
|
|
933
|
+
async function executeRemoveLogic(key, context) {
|
|
926
934
|
const { api, cacheMap } = context;
|
|
927
|
-
logger7.default("remove", { key });
|
|
928
935
|
if (!isValidItemKey3(key)) {
|
|
929
|
-
|
|
936
|
+
logger6.error("Key for Remove is not a valid ItemKey: %j", key);
|
|
930
937
|
throw new Error("Key for Remove is not a valid ItemKey");
|
|
931
938
|
}
|
|
932
939
|
try {
|
|
@@ -940,39 +947,48 @@ var remove = async (key, context) => {
|
|
|
940
947
|
}
|
|
941
948
|
const queryInvalidatedEvent = CacheEventFactory.createQueryInvalidatedEvent(
|
|
942
949
|
[],
|
|
943
|
-
// We don't track which specific queries were invalidated
|
|
944
950
|
"item_changed",
|
|
945
951
|
{ source: "operation", context: { operation: "remove" } }
|
|
946
952
|
);
|
|
947
953
|
context.eventEmitter.emit(queryInvalidatedEvent);
|
|
948
|
-
|
|
954
|
+
logger6.debug("Successfully removed item from API and cache", { key });
|
|
949
955
|
} catch (e) {
|
|
950
|
-
|
|
956
|
+
logger6.error("Error deleting item", { error: e });
|
|
951
957
|
throw e;
|
|
952
958
|
}
|
|
953
|
-
|
|
954
|
-
};
|
|
959
|
+
}
|
|
955
960
|
|
|
956
961
|
// src/ops/update.ts
|
|
957
962
|
import {
|
|
958
|
-
|
|
959
|
-
|
|
963
|
+
createUpdateWrapper,
|
|
964
|
+
isValidItemKey as isValidItemKey4
|
|
960
965
|
} from "@fjell/core";
|
|
961
|
-
var
|
|
966
|
+
var logger7 = logger_default.get("update");
|
|
962
967
|
var update = async (key, v, context) => {
|
|
968
|
+
const { coordinate } = context;
|
|
969
|
+
logger7.default("update", { key, v });
|
|
970
|
+
const wrappedUpdate = createUpdateWrapper(
|
|
971
|
+
coordinate,
|
|
972
|
+
async (k, item) => {
|
|
973
|
+
return await executeUpdateLogic(k, item, context);
|
|
974
|
+
}
|
|
975
|
+
);
|
|
976
|
+
const result = await wrappedUpdate(key, v);
|
|
977
|
+
return [context, result];
|
|
978
|
+
};
|
|
979
|
+
async function executeUpdateLogic(key, v, context) {
|
|
963
980
|
const { api, cacheMap, pkType } = context;
|
|
964
|
-
logger8.default("update", { key, v });
|
|
965
981
|
if (!isValidItemKey4(key)) {
|
|
966
|
-
|
|
982
|
+
logger7.error("Key for Update is not a valid ItemKey: %j", key);
|
|
967
983
|
throw new Error("Key for Update is not a valid ItemKey");
|
|
968
984
|
}
|
|
969
|
-
|
|
985
|
+
logger7.debug("Invalidating item key before update", { key });
|
|
970
986
|
cacheMap.invalidateItemKeys([key]);
|
|
971
987
|
await cacheMap.clearQueryResults();
|
|
972
988
|
try {
|
|
973
989
|
const previousItem = await cacheMap.get(key);
|
|
974
990
|
const updated = await api.update(key, v);
|
|
975
|
-
|
|
991
|
+
logger7.debug("Caching update result", { updatedKey: updated.key });
|
|
976
992
|
await cacheMap.set(updated.key, updated);
|
|
977
993
|
const cachedItem = await cacheMap.get(updated.key);
|
|
978
994
|
const keyStr = JSON.stringify(updated.key);
|
|
@@ -1003,22 +1019,22 @@ var update = async (key, v, context) => {
|
|
|
1003
1019
|
{ source: "operation", context: { operation: "update" } }
|
|
1004
1020
|
);
|
|
1005
1021
|
context.eventEmitter.emit(queryInvalidatedEvent);
|
|
1006
|
-
return
|
|
1022
|
+
return updated;
|
|
1007
1023
|
} catch (e) {
|
|
1008
|
-
|
|
1024
|
+
logger7.error("Error updating item", { error: e });
|
|
1009
1025
|
throw e;
|
|
1010
1026
|
}
|
|
1011
|
-
}
|
|
1027
|
+
}
|
|
1012
1028
|
|
|
1013
1029
|
// src/ops/action.ts
|
|
1014
1030
|
import {
|
|
1015
|
-
|
|
1016
|
-
|
|
1031
|
+
createActionWrapper,
|
|
1032
|
+
isValidItemKey as isValidItemKey5
|
|
1017
1033
|
} from "@fjell/core";
|
|
1018
1034
|
|
|
1019
1035
|
// src/utils/cacheInvalidation.ts
|
|
1020
1036
|
import { toKeyTypeArray } from "@fjell/core";
|
|
1021
|
-
var
|
|
1037
|
+
var logger8 = logger_default.get("cache", "utils", "cacheInvalidation");
|
|
1022
1038
|
var extractKeysAndKeyTypesFromActionResult = (affectedItems) => {
|
|
1023
1039
|
const keys = [];
|
|
1024
1040
|
const keyTypeArrays = [];
|
|
@@ -1035,7 +1051,7 @@ var extractKeysAndKeyTypesFromActionResult = (affectedItems) => {
|
|
|
1035
1051
|
return { keys, keyTypeArrays };
|
|
1036
1052
|
};
|
|
1037
1053
|
var invalidateCachesByKeysAndKeyTypes = async (registry, keys, keyTypeArrays) => {
|
|
1038
|
-
|
|
1054
|
+
logger8.debug("Invalidating caches by keys and key types", {
|
|
1039
1055
|
keysCount: keys.length,
|
|
1040
1056
|
keyTypeArrays
|
|
1041
1057
|
});
|
|
@@ -1053,22 +1069,22 @@ var invalidateCachesByKeysAndKeyTypes = async (registry, keys, keyTypeArrays) =>
|
|
|
1053
1069
|
try {
|
|
1054
1070
|
const cacheInstance = registry.get(keyTypes);
|
|
1055
1071
|
if (cacheInstance && isCache(cacheInstance)) {
|
|
1056
|
-
|
|
1072
|
+
logger8.debug("Found cache instance for targeted invalidation", {
|
|
1057
1073
|
keyTypes,
|
|
1058
1074
|
cacheType: cacheInstance.coordinate.kta,
|
|
1059
1075
|
keysToInvalidate: cacheKeys.length
|
|
1060
1076
|
});
|
|
1061
1077
|
await cacheInstance.cacheMap.invalidateItemKeys(cacheKeys);
|
|
1062
1078
|
await cacheInstance.cacheMap.clearQueryResults();
|
|
1063
|
-
|
|
1079
|
+
logger8.debug("Successfully invalidated specific items in cache", {
|
|
1064
1080
|
keyTypes,
|
|
1065
1081
|
invalidatedCount: cacheKeys.length
|
|
1066
1082
|
});
|
|
1067
1083
|
} else {
|
|
1068
|
-
|
|
1084
|
+
logger8.debug("No cache instance found for key types", { keyTypes });
|
|
1069
1085
|
}
|
|
1070
1086
|
} catch (error) {
|
|
1071
|
-
|
|
1087
|
+
logger8.warning("Failed to invalidate cache for key types", {
|
|
1072
1088
|
keyTypes,
|
|
1073
1089
|
error: error instanceof Error ? error.message : String(error)
|
|
1074
1090
|
});
|
|
@@ -1078,12 +1094,12 @@ var invalidateCachesByKeysAndKeyTypes = async (registry, keys, keyTypeArrays) =>
|
|
|
1078
1094
|
try {
|
|
1079
1095
|
const cacheInstance = registry.get(keyTypes);
|
|
1080
1096
|
if (cacheInstance && isCache(cacheInstance)) {
|
|
1081
|
-
|
|
1097
|
+
logger8.debug("Handling location-based invalidation", { keyTypes });
|
|
1082
1098
|
await cacheInstance.cacheMap.clearQueryResults();
|
|
1083
|
-
|
|
1099
|
+
logger8.debug("Successfully cleared query results for location", { keyTypes });
|
|
1084
1100
|
}
|
|
1085
1101
|
} catch (error) {
|
|
1086
|
-
|
|
1102
|
+
logger8.warning("Failed to handle location-based invalidation", {
|
|
1087
1103
|
keyTypes,
|
|
1088
1104
|
error: error instanceof Error ? error.message : String(error)
|
|
1089
1105
|
});
|
|
@@ -1094,7 +1110,7 @@ function isCache(instance) {
|
|
|
1094
1110
|
return instance !== null && typeof instance === "object" && "operations" in instance && "cacheMap" in instance && typeof instance.cacheMap.invalidateItemKeys === "function";
|
|
1095
1111
|
}
|
|
1096
1112
|
var handleActionCacheInvalidation = async (registry, affectedItems) => {
|
|
1097
|
-
|
|
1113
|
+
logger8.debug("Handling action cache invalidation", {
|
|
1098
1114
|
affectedItemsCount: affectedItems.length
|
|
1099
1115
|
});
|
|
1100
1116
|
const { keys, keyTypeArrays } = extractKeysAndKeyTypesFromActionResult(affectedItems);
|
|
@@ -1102,33 +1118,44 @@ var handleActionCacheInvalidation = async (registry, affectedItems) => {
|
|
|
1102
1118
|
};
|
|
1103
1119
|
|
|
1104
1120
|
// src/ops/action.ts
|
|
1105
|
-
var
|
|
1121
|
+
var logger9 = logger_default.get("action");
|
|
1106
1122
|
var action = async (key, action2, body = {}, context) => {
|
|
1123
|
+
const { coordinate } = context;
|
|
1124
|
+
logger9.default("action", { key, action: action2, body });
|
|
1125
|
+
const wrappedAction = createActionWrapper(
|
|
1126
|
+
coordinate,
|
|
1127
|
+
async (k, a, b) => {
|
|
1128
|
+
return await executeActionLogic(k, a, b, context);
|
|
1129
|
+
}
|
|
1130
|
+
);
|
|
1131
|
+
const result = await wrappedAction(key, action2, body);
|
|
1132
|
+
return [context, result[0], result[1]];
|
|
1133
|
+
};
|
|
1134
|
+
async function executeActionLogic(key, action2, body, context) {
|
|
1107
1135
|
const { api, cacheMap, pkType, registry } = context;
|
|
1108
|
-
logger10.default("action", { key, action: action2, body });
|
|
1109
1136
|
if (!isValidItemKey5(key)) {
|
|
1110
|
-
|
|
1137
|
+
logger9.error("Key for Action is not a valid ItemKey: %j", key);
|
|
1111
1138
|
throw new Error("Key for Action is not a valid ItemKey");
|
|
1112
1139
|
}
|
|
1113
|
-
|
|
1140
|
+
logger9.debug("Invalidating item key before action", { key });
|
|
1114
1141
|
cacheMap.invalidateItemKeys([key]);
|
|
1115
1142
|
const result = await api.action(key, action2, body);
|
|
1116
1143
|
const updated = result[0];
|
|
1117
1144
|
const affectedItems = result[1];
|
|
1118
1145
|
if (affectedItems && affectedItems.length > 0) {
|
|
1119
|
-
|
|
1146
|
+
logger9.debug("Handling cache invalidation for affected items", {
|
|
1120
1147
|
affectedItemsCount: affectedItems.length
|
|
1121
1148
|
});
|
|
1122
1149
|
try {
|
|
1123
1150
|
await handleActionCacheInvalidation(registry, affectedItems);
|
|
1124
1151
|
} catch (error) {
|
|
1125
|
-
|
|
1152
|
+
logger9.warning("Failed to handle cache invalidation for affected items", {
|
|
1126
1153
|
error: error instanceof Error ? error.message : String(error),
|
|
1127
1154
|
affectedItems
|
|
1128
1155
|
});
|
|
1129
1156
|
}
|
|
1130
1157
|
}
|
|
1131
|
-
|
|
1158
|
+
logger9.debug("Caching action result", { updatedKey: updated.key });
|
|
1132
1159
|
cacheMap.set(updated.key, updated);
|
|
1133
1160
|
const keyStr = JSON.stringify(updated.key);
|
|
1134
1161
|
context.ttlManager.onItemAdded(keyStr, cacheMap);
|
|
@@ -1138,19 +1165,19 @@ var action = async (key, action2, body = {}, context) => {
|
|
|
1138
1165
|
const parsedKey = JSON.parse(evictedKey);
|
|
1139
1166
|
await cacheMap.delete(parsedKey);
|
|
1140
1167
|
} catch (error) {
|
|
1141
|
-
|
|
1168
|
+
logger9.error("Failed to parse evicted key during deletion", {
|
|
1142
1169
|
evictedKey,
|
|
1143
1170
|
error: error instanceof Error ? error.message : String(error)
|
|
1144
1171
|
});
|
|
1145
1172
|
}
|
|
1146
1173
|
}
|
|
1147
|
-
|
|
1174
|
+
logger9.debug("Emitting itemUpdated event after action", {
|
|
1148
1175
|
key: updated.key,
|
|
1149
1176
|
action: action2
|
|
1150
1177
|
});
|
|
1151
1178
|
const itemEvent = CacheEventFactory.itemUpdated(updated.key, updated, null, "api");
|
|
1152
1179
|
context.eventEmitter.emit(itemEvent);
|
|
1153
|
-
|
|
1180
|
+
logger9.debug("Emitting queryInvalidatedEvent after action", {
|
|
1154
1181
|
eventType: "query_invalidated",
|
|
1155
1182
|
reason: "item_changed",
|
|
1156
1183
|
action: action2
|
|
@@ -1162,19 +1189,29 @@ var action = async (key, action2, body = {}, context) => {
|
|
|
1162
1189
|
{ source: "operation", context: { operation: "action" } }
|
|
1163
1190
|
);
|
|
1164
1191
|
context.eventEmitter.emit(queryInvalidatedEvent);
|
|
1165
|
-
return [
|
|
1166
|
-
}
|
|
1192
|
+
return [updated, affectedItems];
|
|
1193
|
+
}
|
|
1167
1194
|
|
|
1168
1195
|
// src/ops/allAction.ts
|
|
1169
1196
|
import {
|
|
1170
|
-
|
|
1197
|
+
createAllActionWrapper
|
|
1171
1198
|
} from "@fjell/core";
|
|
1172
1199
|
import { NotFoundError as NotFoundError3 } from "@fjell/http-api";
|
|
1173
|
-
var
|
|
1200
|
+
var logger10 = logger_default.get("allAction");
|
|
1174
1201
|
var allAction = async (action2, body = {}, locations = [], context) => {
|
|
1175
|
-
const {
|
|
1176
|
-
|
|
1177
|
-
|
|
1202
|
+
const { coordinate } = context;
|
|
1203
|
+
logger10.default("allAction", { action: action2, body, locations });
|
|
1204
|
+
const wrappedAllAction = createAllActionWrapper(
|
|
1205
|
+
coordinate,
|
|
1206
|
+
async (a, b, locs) => {
|
|
1207
|
+
return await executeAllActionLogic(a, b, locs ?? [], context);
|
|
1208
|
+
}
|
|
1209
|
+
);
|
|
1210
|
+
const result = await wrappedAllAction(action2, body, locations);
|
|
1211
|
+
return [context, result[0], result[1]];
|
|
1212
|
+
};
|
|
1213
|
+
async function executeAllActionLogic(action2, body, locations, context) {
|
|
1214
|
+
const { api, cacheMap, pkType, eventEmitter, registry } = context;
|
|
1178
1215
|
const existingItems = [];
|
|
1179
1216
|
if (locations && locations.length > 0) {
|
|
1180
1217
|
try {
|
|
@@ -1183,10 +1220,10 @@ var allAction = async (action2, body = {}, locations = [], context) => {
|
|
|
1183
1220
|
existingItems.push(...cachedItems);
|
|
1184
1221
|
}
|
|
1185
1222
|
} catch (error) {
|
|
1186
|
-
|
|
1223
|
+
logger10.debug("Could not retrieve existing items for comparison", { error });
|
|
1187
1224
|
}
|
|
1188
1225
|
}
|
|
1189
|
-
|
|
1226
|
+
logger10.debug("Invalidating location before allAction", { locations });
|
|
1190
1227
|
await cacheMap.invalidateLocation(locations);
|
|
1191
1228
|
let ret = [];
|
|
1192
1229
|
let affectedItems = [];
|
|
@@ -1196,7 +1233,7 @@ var allAction = async (action2, body = {}, locations = [], context) => {
|
|
|
1196
1233
|
ret = result[0];
|
|
1197
1234
|
affectedItems = result[1];
|
|
1198
1235
|
} else {
|
|
1199
|
-
|
|
1236
|
+
logger10.warning("Unexpected result format from allAction", {
|
|
1200
1237
|
resultType: typeof result,
|
|
1201
1238
|
isArray: Array.isArray(result),
|
|
1202
1239
|
resultLength: Array.isArray(result) ? result.length : "not array"
|
|
@@ -1205,19 +1242,19 @@ var allAction = async (action2, body = {}, locations = [], context) => {
|
|
|
1205
1242
|
affectedItems = [];
|
|
1206
1243
|
}
|
|
1207
1244
|
if (affectedItems && affectedItems.length > 0) {
|
|
1208
|
-
|
|
1245
|
+
logger10.debug("Handling cache invalidation for affected items", {
|
|
1209
1246
|
affectedItemsCount: affectedItems.length
|
|
1210
1247
|
});
|
|
1211
1248
|
try {
|
|
1212
1249
|
await handleActionCacheInvalidation(registry, affectedItems);
|
|
1213
1250
|
} catch (error) {
|
|
1214
|
-
|
|
1251
|
+
logger10.warning("Failed to handle cache invalidation for affected items", {
|
|
1215
1252
|
error: error instanceof Error ? error.message : String(error),
|
|
1216
1253
|
affectedItems
|
|
1217
1254
|
});
|
|
1218
1255
|
}
|
|
1219
1256
|
}
|
|
1220
|
-
|
|
1257
|
+
logger10.debug("Caching allAction results", { resultCount: ret.length });
|
|
1221
1258
|
const modifiedItems = [];
|
|
1222
1259
|
const newItems = [];
|
|
1223
1260
|
for (const v of ret) {
|
|
@@ -1239,7 +1276,7 @@ var allAction = async (action2, body = {}, locations = [], context) => {
|
|
|
1239
1276
|
}
|
|
1240
1277
|
}
|
|
1241
1278
|
for (const item of modifiedItems) {
|
|
1242
|
-
|
|
1279
|
+
logger10.debug("Emitting item_updated event for modified item", { key: item.key });
|
|
1243
1280
|
const itemEvent = CacheEventFactory.itemUpdated(
|
|
1244
1281
|
item.key,
|
|
1245
1282
|
item,
|
|
@@ -1250,7 +1287,7 @@ var allAction = async (action2, body = {}, locations = [], context) => {
|
|
|
1250
1287
|
eventEmitter.emit(itemEvent);
|
|
1251
1288
|
}
|
|
1252
1289
|
for (const item of newItems) {
|
|
1253
|
-
|
|
1290
|
+
logger10.debug("Emitting item_created event for new item", { key: item.key });
|
|
1254
1291
|
const itemEvent = CacheEventFactory.itemCreated(
|
|
1255
1292
|
item.key,
|
|
1256
1293
|
item,
|
|
@@ -1260,14 +1297,14 @@ var allAction = async (action2, body = {}, locations = [], context) => {
|
|
|
1260
1297
|
}
|
|
1261
1298
|
if (modifiedItems.length > 0) {
|
|
1262
1299
|
const modifiedKeys = modifiedItems.map((item) => item.key);
|
|
1263
|
-
|
|
1300
|
+
logger10.debug("Invalidating individual item keys for modified items", {
|
|
1264
1301
|
keyCount: modifiedKeys.length,
|
|
1265
1302
|
keys: modifiedKeys
|
|
1266
1303
|
});
|
|
1267
1304
|
await cacheMap.invalidateItemKeys(modifiedKeys);
|
|
1268
1305
|
}
|
|
1269
1306
|
await cacheMap.clearQueryResults();
|
|
1270
|
-
|
|
1307
|
+
logger10.debug("Emitting query_invalidated event after allAction", {
|
|
1271
1308
|
eventType: "query_invalidated",
|
|
1272
1309
|
reason: "item_changed",
|
|
1273
1310
|
action: action2,
|
|
@@ -1293,53 +1330,78 @@ var allAction = async (action2, body = {}, locations = [], context) => {
|
|
|
1293
1330
|
throw e;
|
|
1294
1331
|
}
|
|
1295
1332
|
}
|
|
1296
|
-
return [
|
|
1297
|
-
}
|
|
1333
|
+
return [ret, affectedItems];
|
|
1334
|
+
}
|
|
1298
1335
|
|
|
1299
1336
|
// src/ops/facet.ts
|
|
1300
|
-
|
|
1337
|
+
import {
|
|
1338
|
+
createFacetWrapper
|
|
1339
|
+
} from "@fjell/core";
|
|
1340
|
+
var logger11 = logger_default.get("facet");
|
|
1301
1341
|
var facet = async (key, facet2, params = {}, context) => {
|
|
1302
|
-
const { api } = context;
|
|
1303
|
-
|
|
1304
|
-
const
|
|
1305
|
-
|
|
1342
|
+
const { coordinate, api } = context;
|
|
1343
|
+
logger11.default("facet", { key, facet: facet2 });
|
|
1344
|
+
const wrappedFacet = createFacetWrapper(
|
|
1345
|
+
coordinate,
|
|
1346
|
+
async (k, f, p) => {
|
|
1347
|
+
return await api.facet(k, f, p ?? {});
|
|
1348
|
+
}
|
|
1349
|
+
);
|
|
1350
|
+
return await wrappedFacet(key, facet2, params);
|
|
1306
1351
|
};
|
|
1307
1352
|
|
|
1308
1353
|
// src/ops/allFacet.ts
|
|
1309
|
-
|
|
1354
|
+
import {
|
|
1355
|
+
createAllFacetWrapper
|
|
1356
|
+
} from "@fjell/core";
|
|
1357
|
+
var logger12 = logger_default.get("allFacet");
|
|
1310
1358
|
var allFacet = async (facet2, params = {}, locations = [], context) => {
|
|
1311
1359
|
const { api, coordinate } = context;
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1360
|
+
logger12.default("allFacet", { facet: facet2, params, locations });
|
|
1361
|
+
const wrappedAllFacet = createAllFacetWrapper(
|
|
1362
|
+
coordinate,
|
|
1363
|
+
async (f, p, locs) => {
|
|
1364
|
+
return await api.allFacet(f, p ?? {}, locs ?? []);
|
|
1365
|
+
}
|
|
1366
|
+
);
|
|
1367
|
+
return await wrappedAllFacet(facet2, params, locations);
|
|
1316
1368
|
};
|
|
1317
1369
|
|
|
1318
1370
|
// src/ops/find.ts
|
|
1319
1371
|
import {
|
|
1320
|
-
|
|
1372
|
+
createFindWrapper
|
|
1321
1373
|
} from "@fjell/core";
|
|
1322
|
-
var
|
|
1374
|
+
var logger13 = logger_default.get("find");
|
|
1323
1375
|
var find = async (finder, params = {}, locations = [], context) => {
|
|
1324
|
-
const {
|
|
1325
|
-
|
|
1326
|
-
|
|
1376
|
+
const { coordinate } = context;
|
|
1377
|
+
logger13.default("find", { finder, params, locations });
|
|
1378
|
+
const wrappedFind = createFindWrapper(
|
|
1379
|
+
coordinate,
|
|
1380
|
+
async (f, p, locs) => {
|
|
1381
|
+
return await executeFindLogic(f, p ?? {}, locs ?? [], context);
|
|
1382
|
+
}
|
|
1383
|
+
);
|
|
1384
|
+
const result = await wrappedFind(finder, params, locations);
|
|
1385
|
+
return [context, result];
|
|
1386
|
+
};
|
|
1387
|
+
async function executeFindLogic(finder, params, locations, context) {
|
|
1388
|
+
const { api, cacheMap, pkType, ttlManager, eventEmitter } = context;
|
|
1327
1389
|
if (context.options?.bypassCache) {
|
|
1328
|
-
|
|
1390
|
+
logger13.debug("Cache bypass enabled, fetching directly from API", { finder, params, locations });
|
|
1329
1391
|
try {
|
|
1330
1392
|
const ret2 = await api.find(finder, params, locations);
|
|
1331
|
-
|
|
1332
|
-
return
|
|
1393
|
+
logger13.debug("API response received (not cached due to bypass)", { finder, params, locations, itemCount: ret2.length });
|
|
1394
|
+
return ret2;
|
|
1333
1395
|
} catch (error) {
|
|
1334
|
-
|
|
1396
|
+
logger13.error("API request failed", { finder, params, locations, error });
|
|
1335
1397
|
throw error;
|
|
1336
1398
|
}
|
|
1337
1399
|
}
|
|
1338
1400
|
const queryHash = createFinderHash(finder, params, locations);
|
|
1339
|
-
|
|
1401
|
+
logger13.debug("Generated query hash for find", { queryHash, finder, params, locations });
|
|
1340
1402
|
const cachedItemKeys = await cacheMap.getQueryResult(queryHash);
|
|
1341
1403
|
if (cachedItemKeys) {
|
|
1342
|
-
|
|
1404
|
+
logger13.debug("Using cached query results", { cachedKeyCount: cachedItemKeys.length, queryHash });
|
|
1343
1405
|
const cachedItems = [];
|
|
1344
1406
|
let allItemsAvailable = true;
|
|
1345
1407
|
for (const itemKey of cachedItemKeys) {
|
|
@@ -1352,9 +1414,9 @@ var find = async (finder, params = {}, locations = [], context) => {
|
|
|
1352
1414
|
}
|
|
1353
1415
|
}
|
|
1354
1416
|
if (allItemsAvailable) {
|
|
1355
|
-
return
|
|
1417
|
+
return cachedItems;
|
|
1356
1418
|
} else {
|
|
1357
|
-
|
|
1419
|
+
logger13.debug("Some cached items missing, invalidating query cache");
|
|
1358
1420
|
cacheMap.deleteQueryResult(queryHash);
|
|
1359
1421
|
}
|
|
1360
1422
|
}
|
|
@@ -1371,46 +1433,62 @@ var find = async (finder, params = {}, locations = [], context) => {
|
|
|
1371
1433
|
}
|
|
1372
1434
|
const itemKeys = ret.map((item) => item.key);
|
|
1373
1435
|
cacheMap.setQueryResult(queryHash, itemKeys);
|
|
1374
|
-
|
|
1436
|
+
logger13.debug("Cached query result", { queryHash, itemKeyCount: itemKeys.length });
|
|
1375
1437
|
const event = CacheEventFactory.createQueryEvent(params, locations, ret);
|
|
1376
1438
|
eventEmitter.emit(event);
|
|
1377
|
-
return
|
|
1378
|
-
}
|
|
1439
|
+
return ret;
|
|
1440
|
+
}
|
|
1379
1441
|
|
|
1380
1442
|
// src/ops/findOne.ts
|
|
1381
1443
|
import {
|
|
1382
|
-
|
|
1444
|
+
createFindOneWrapper
|
|
1383
1445
|
} from "@fjell/core";
|
|
1384
|
-
var
|
|
1446
|
+
var logger14 = logger_default.get("findOne");
|
|
1385
1447
|
var findOne = async (finder, finderParams = {}, locations = [], context) => {
|
|
1386
|
-
const {
|
|
1387
|
-
|
|
1388
|
-
|
|
1448
|
+
const { coordinate } = context;
|
|
1449
|
+
logger14.default("findOne", { finder, finderParams, locations });
|
|
1450
|
+
const wrappedFindOne = createFindOneWrapper(
|
|
1451
|
+
coordinate,
|
|
1452
|
+
async (f, p, locs) => {
|
|
1453
|
+
return await executeFindOneLogic(f, p ?? {}, locs ?? [], context);
|
|
1454
|
+
}
|
|
1455
|
+
);
|
|
1456
|
+
const result = await wrappedFindOne(finder, finderParams, locations);
|
|
1457
|
+
return [context, result];
|
|
1458
|
+
};
|
|
1459
|
+
async function executeFindOneLogic(finder, finderParams, locations, context) {
|
|
1460
|
+
const { api, cacheMap, pkType, ttlManager, eventEmitter } = context;
|
|
1389
1461
|
if (context.options?.bypassCache) {
|
|
1390
|
-
|
|
1462
|
+
logger14.debug("Cache bypass enabled, fetching directly from API", { finder, finderParams, locations });
|
|
1391
1463
|
try {
|
|
1392
1464
|
const ret2 = await api.findOne(finder, finderParams, locations);
|
|
1393
|
-
|
|
1394
|
-
|
|
1465
|
+
if (ret2 === null) {
|
|
1466
|
+
throw new Error(`findOne returned null for finder: ${finder}`);
|
|
1467
|
+
}
|
|
1468
|
+
logger14.debug("API response received (not cached due to bypass)", { finder, finderParams, locations });
|
|
1469
|
+
return ret2;
|
|
1395
1470
|
} catch (error) {
|
|
1396
|
-
|
|
1471
|
+
logger14.error("API request failed", { finder, finderParams, locations, error });
|
|
1397
1472
|
throw error;
|
|
1398
1473
|
}
|
|
1399
1474
|
}
|
|
1400
1475
|
const queryHash = createFinderHash(finder, finderParams, locations);
|
|
1401
|
-
|
|
1476
|
+
logger14.debug("Generated query hash for findOne", { queryHash });
|
|
1402
1477
|
const cachedItemKeys = await cacheMap.getQueryResult(queryHash);
|
|
1403
1478
|
if (cachedItemKeys && cachedItemKeys.length > 0) {
|
|
1404
|
-
|
|
1479
|
+
logger14.debug("Using cached query results", { cachedKeyCount: cachedItemKeys.length });
|
|
1405
1480
|
const item = await cacheMap.get(cachedItemKeys[0]);
|
|
1406
1481
|
if (item) {
|
|
1407
|
-
return
|
|
1482
|
+
return item;
|
|
1408
1483
|
} else {
|
|
1409
|
-
|
|
1484
|
+
logger14.debug("Cached item missing, invalidating query cache");
|
|
1410
1485
|
cacheMap.deleteQueryResult(queryHash);
|
|
1411
1486
|
}
|
|
1412
1487
|
}
|
|
1413
1488
|
const ret = await api.findOne(finder, finderParams, locations);
|
|
1489
|
+
if (ret === null) {
|
|
1490
|
+
throw new Error(`findOne returned null for finder: ${finder}`);
|
|
1491
|
+
}
|
|
1414
1492
|
cacheMap.set(ret.key, ret);
|
|
1415
1493
|
const keyStr = JSON.stringify(ret.key);
|
|
1416
1494
|
ttlManager.onItemAdded(keyStr, cacheMap);
|
|
@@ -1420,19 +1498,18 @@ var findOne = async (finder, finderParams = {}, locations = [], context) => {
|
|
|
1420
1498
|
await cacheMap.delete(parsedKey);
|
|
1421
1499
|
}
|
|
1422
1500
|
cacheMap.setQueryResult(queryHash, [ret.key]);
|
|
1423
|
-
|
|
1501
|
+
logger14.debug("Cached query result", { queryHash, itemKey: ret.key });
|
|
1424
1502
|
const event = CacheEventFactory.createQueryEvent(finderParams, locations, [ret]);
|
|
1425
1503
|
eventEmitter.emit(event);
|
|
1426
|
-
return
|
|
1427
|
-
}
|
|
1504
|
+
return ret;
|
|
1505
|
+
}
|
|
1428
1506
|
|
|
1429
1507
|
// src/ops/set.ts
|
|
1430
1508
|
import {
|
|
1431
1509
|
isItemKeyEqual,
|
|
1432
|
-
isValidItemKey as isValidItemKey6
|
|
1433
|
-
validatePK as validatePK11
|
|
1510
|
+
isValidItemKey as isValidItemKey6
|
|
1434
1511
|
} from "@fjell/core";
|
|
1435
|
-
var
|
|
1512
|
+
var logger15 = logger_default.get("set");
|
|
1436
1513
|
var normalizeKeyValue2 = (value) => {
|
|
1437
1514
|
return String(value);
|
|
1438
1515
|
};
|
|
@@ -1482,14 +1559,13 @@ var normalizeKey = (key) => {
|
|
|
1482
1559
|
};
|
|
1483
1560
|
var set = async (key, v, context) => {
|
|
1484
1561
|
const { cacheMap, pkType, ttlManager, evictionManager, eventEmitter } = context;
|
|
1485
|
-
|
|
1562
|
+
logger15.default("set", { key, v });
|
|
1486
1563
|
if (!isValidItemKey6(key)) {
|
|
1487
|
-
|
|
1564
|
+
logger15.error("Key for Set is not a valid ItemKey: %j", key);
|
|
1488
1565
|
throw new Error("Key for Set is not a valid ItemKey");
|
|
1489
1566
|
}
|
|
1490
|
-
validatePK11(v, pkType);
|
|
1491
1567
|
if (!isItemKeyEqualNormalized(key, v.key)) {
|
|
1492
|
-
|
|
1568
|
+
logger15.error("Key does not match item key: %j != %j", key, v.key);
|
|
1493
1569
|
throw new Error("Key does not match item key");
|
|
1494
1570
|
}
|
|
1495
1571
|
const previousItem = await cacheMap.get(key);
|
|
@@ -1515,7 +1591,7 @@ var set = async (key, v, context) => {
|
|
|
1515
1591
|
}
|
|
1516
1592
|
const event = CacheEventFactory.itemSet(key, v, previousItem);
|
|
1517
1593
|
eventEmitter.emit(event);
|
|
1518
|
-
return [context,
|
|
1594
|
+
return [context, v];
|
|
1519
1595
|
};
|
|
1520
1596
|
|
|
1521
1597
|
// src/memory/MemoryCacheMap.ts
|
|
@@ -1533,7 +1609,7 @@ var CacheMap = class {
|
|
|
1533
1609
|
};
|
|
1534
1610
|
|
|
1535
1611
|
// src/memory/MemoryCacheMap.ts
|
|
1536
|
-
var
|
|
1612
|
+
var logger16 = logger_default.get("MemoryCacheMap");
|
|
1537
1613
|
var MemoryCacheMap = class _MemoryCacheMap extends CacheMap {
|
|
1538
1614
|
implementationType = "memory/memory";
|
|
1539
1615
|
map = {};
|
|
@@ -1551,13 +1627,13 @@ var MemoryCacheMap = class _MemoryCacheMap extends CacheMap {
|
|
|
1551
1627
|
const key = JSON.parse(keyStr);
|
|
1552
1628
|
this.set(key, value);
|
|
1553
1629
|
} catch (error) {
|
|
1554
|
-
|
|
1630
|
+
logger16.error("Failed to parse initial data key", { keyStr, error });
|
|
1555
1631
|
}
|
|
1556
1632
|
}
|
|
1557
1633
|
}
|
|
1558
1634
|
}
|
|
1559
1635
|
async get(key) {
|
|
1560
|
-
|
|
1636
|
+
logger16.trace("get", { key });
|
|
1561
1637
|
const hashedKey = this.normalizedHashFunction(key);
|
|
1562
1638
|
const entry = this.map[hashedKey];
|
|
1563
1639
|
if (entry && this.normalizedHashFunction(entry.originalKey) === hashedKey) {
|
|
@@ -1572,7 +1648,7 @@ var MemoryCacheMap = class _MemoryCacheMap extends CacheMap {
|
|
|
1572
1648
|
return null;
|
|
1573
1649
|
}
|
|
1574
1650
|
async set(key, value) {
|
|
1575
|
-
|
|
1651
|
+
logger16.trace("set", { key, value });
|
|
1576
1652
|
const hashedKey = this.normalizedHashFunction(key);
|
|
1577
1653
|
const keyStr = JSON.stringify(key);
|
|
1578
1654
|
this.map[hashedKey] = { originalKey: key, value };
|
|
@@ -1599,7 +1675,7 @@ var MemoryCacheMap = class _MemoryCacheMap extends CacheMap {
|
|
|
1599
1675
|
return !!entry && this.normalizedHashFunction(entry.originalKey) === hashedKey;
|
|
1600
1676
|
}
|
|
1601
1677
|
async delete(key) {
|
|
1602
|
-
|
|
1678
|
+
logger16.trace("delete", { key });
|
|
1603
1679
|
const hashedKey = this.normalizedHashFunction(key);
|
|
1604
1680
|
const entry = this.map[hashedKey];
|
|
1605
1681
|
if (entry && this.normalizedHashFunction(entry.originalKey) === hashedKey) {
|
|
@@ -1628,10 +1704,10 @@ var MemoryCacheMap = class _MemoryCacheMap extends CacheMap {
|
|
|
1628
1704
|
async allIn(locations) {
|
|
1629
1705
|
const allValues = await this.values();
|
|
1630
1706
|
if (locations.length === 0) {
|
|
1631
|
-
|
|
1707
|
+
logger16.debug("Returning all items, LocKeys is empty");
|
|
1632
1708
|
return allValues;
|
|
1633
1709
|
} else {
|
|
1634
|
-
|
|
1710
|
+
logger16.debug("allIn", { locations, count: allValues.length });
|
|
1635
1711
|
return allValues.filter((item) => {
|
|
1636
1712
|
const key = item.key;
|
|
1637
1713
|
if (key && isComKey(key)) {
|
|
@@ -1643,12 +1719,12 @@ var MemoryCacheMap = class _MemoryCacheMap extends CacheMap {
|
|
|
1643
1719
|
}
|
|
1644
1720
|
}
|
|
1645
1721
|
async contains(query, locations) {
|
|
1646
|
-
|
|
1722
|
+
logger16.debug("contains", { query, locations });
|
|
1647
1723
|
const items = await this.allIn(locations);
|
|
1648
1724
|
return items.some((item) => isQueryMatch(item, query));
|
|
1649
1725
|
}
|
|
1650
1726
|
async queryIn(query, locations = []) {
|
|
1651
|
-
|
|
1727
|
+
logger16.debug("queryIn", { query, locations });
|
|
1652
1728
|
const items = await this.allIn(locations);
|
|
1653
1729
|
return items.filter((item) => isQueryMatch(item, query));
|
|
1654
1730
|
}
|
|
@@ -1671,7 +1747,7 @@ var MemoryCacheMap = class _MemoryCacheMap extends CacheMap {
|
|
|
1671
1747
|
}
|
|
1672
1748
|
// Query result caching methods implementation
|
|
1673
1749
|
async setQueryResult(queryHash, itemKeys) {
|
|
1674
|
-
|
|
1750
|
+
logger16.trace("setQueryResult", { queryHash, itemKeys });
|
|
1675
1751
|
const entry = {
|
|
1676
1752
|
itemKeys: [...itemKeys]
|
|
1677
1753
|
// Create a copy to avoid external mutations
|
|
@@ -1679,7 +1755,7 @@ var MemoryCacheMap = class _MemoryCacheMap extends CacheMap {
|
|
|
1679
1755
|
this.queryResultCache[queryHash] = entry;
|
|
1680
1756
|
}
|
|
1681
1757
|
async getQueryResult(queryHash) {
|
|
1682
|
-
|
|
1758
|
+
logger16.trace("getQueryResult", { queryHash });
|
|
1683
1759
|
const entry = this.queryResultCache[queryHash];
|
|
1684
1760
|
if (!entry) {
|
|
1685
1761
|
return null;
|
|
@@ -1691,11 +1767,11 @@ var MemoryCacheMap = class _MemoryCacheMap extends CacheMap {
|
|
|
1691
1767
|
return !!entry;
|
|
1692
1768
|
}
|
|
1693
1769
|
async deleteQueryResult(queryHash) {
|
|
1694
|
-
|
|
1770
|
+
logger16.trace("deleteQueryResult", { queryHash });
|
|
1695
1771
|
delete this.queryResultCache[queryHash];
|
|
1696
1772
|
}
|
|
1697
1773
|
async invalidateItemKeys(keys) {
|
|
1698
|
-
|
|
1774
|
+
logger16.debug("invalidateItemKeys", { keys });
|
|
1699
1775
|
if (keys.length === 0) {
|
|
1700
1776
|
return;
|
|
1701
1777
|
}
|
|
@@ -1726,14 +1802,14 @@ var MemoryCacheMap = class _MemoryCacheMap extends CacheMap {
|
|
|
1726
1802
|
queriesToRemove.forEach((queryHash) => {
|
|
1727
1803
|
this.deleteQueryResult(queryHash);
|
|
1728
1804
|
});
|
|
1729
|
-
|
|
1805
|
+
logger16.debug("Selectively invalidated queries referencing affected keys", {
|
|
1730
1806
|
affectedKeys: keys.length,
|
|
1731
1807
|
queriesRemoved: queriesToRemove.length,
|
|
1732
1808
|
totalQueries: Object.keys(this.queryResultCache).length
|
|
1733
1809
|
});
|
|
1734
1810
|
}
|
|
1735
1811
|
async invalidateLocation(locations) {
|
|
1736
|
-
|
|
1812
|
+
logger16.debug("invalidateLocation", { locations });
|
|
1737
1813
|
let keysToInvalidate = [];
|
|
1738
1814
|
if (locations.length === 0) {
|
|
1739
1815
|
const allKeys = await this.keys();
|
|
@@ -1746,7 +1822,7 @@ var MemoryCacheMap = class _MemoryCacheMap extends CacheMap {
|
|
|
1746
1822
|
await this.invalidateItemKeys(keysToInvalidate);
|
|
1747
1823
|
}
|
|
1748
1824
|
async clearQueryResults() {
|
|
1749
|
-
|
|
1825
|
+
logger16.trace("clearQueryResults");
|
|
1750
1826
|
this.queryResultCache = {};
|
|
1751
1827
|
}
|
|
1752
1828
|
// CacheMapMetadataProvider implementation
|
|
@@ -1788,7 +1864,7 @@ import {
|
|
|
1788
1864
|
isComKey as isComKey2,
|
|
1789
1865
|
isQueryMatch as isQueryMatch2
|
|
1790
1866
|
} from "@fjell/core";
|
|
1791
|
-
var
|
|
1867
|
+
var logger17 = logger_default.get("EnhancedMemoryCacheMap");
|
|
1792
1868
|
var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
1793
1869
|
implementationType = "memory/enhanced";
|
|
1794
1870
|
map = {};
|
|
@@ -1807,11 +1883,11 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
1807
1883
|
this.normalizedHashFunction = createNormalizedHashFunction();
|
|
1808
1884
|
if (sizeConfig?.maxSizeBytes) {
|
|
1809
1885
|
this.maxSizeBytes = parseSizeString(sizeConfig.maxSizeBytes);
|
|
1810
|
-
|
|
1886
|
+
logger17.debug("Cache size limit set", { maxSizeBytes: this.maxSizeBytes });
|
|
1811
1887
|
}
|
|
1812
1888
|
if (sizeConfig?.maxItems) {
|
|
1813
1889
|
this.maxItems = sizeConfig.maxItems;
|
|
1814
|
-
|
|
1890
|
+
logger17.debug("Cache item limit set", { maxItems: this.maxItems });
|
|
1815
1891
|
}
|
|
1816
1892
|
if (initialData) {
|
|
1817
1893
|
for (const [keyStr, value] of Object.entries(initialData)) {
|
|
@@ -1819,13 +1895,13 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
1819
1895
|
const key = JSON.parse(keyStr);
|
|
1820
1896
|
this.set(key, value);
|
|
1821
1897
|
} catch (error) {
|
|
1822
|
-
|
|
1898
|
+
logger17.error("Failed to parse initial data key", { keyStr, error });
|
|
1823
1899
|
}
|
|
1824
1900
|
}
|
|
1825
1901
|
}
|
|
1826
1902
|
}
|
|
1827
1903
|
async get(key) {
|
|
1828
|
-
|
|
1904
|
+
logger17.trace("get", { key });
|
|
1829
1905
|
const hashedKey = this.normalizedHashFunction(key);
|
|
1830
1906
|
const entry = this.map[hashedKey];
|
|
1831
1907
|
if (entry && this.normalizedHashFunction(entry.originalKey) === hashedKey && entry.value !== null) {
|
|
@@ -1834,7 +1910,7 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
1834
1910
|
return null;
|
|
1835
1911
|
}
|
|
1836
1912
|
async set(key, value) {
|
|
1837
|
-
|
|
1913
|
+
logger17.trace("set", { key, value });
|
|
1838
1914
|
const hashedKey = this.normalizedHashFunction(key);
|
|
1839
1915
|
const estimatedSize = estimateValueSize(value);
|
|
1840
1916
|
const existingEntry = this.map[hashedKey];
|
|
@@ -1845,7 +1921,7 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
1845
1921
|
const oldValue = existingEntry.value;
|
|
1846
1922
|
existingEntry.value = value;
|
|
1847
1923
|
existingEntry.metadata.estimatedSize = estimatedSize;
|
|
1848
|
-
|
|
1924
|
+
logger17.trace("Updated existing cache entry", {
|
|
1849
1925
|
key: hashedKey,
|
|
1850
1926
|
sizeDiff,
|
|
1851
1927
|
currentSize: this.currentSizeBytes,
|
|
@@ -1866,7 +1942,7 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
1866
1942
|
};
|
|
1867
1943
|
this.currentSizeBytes += estimatedSize;
|
|
1868
1944
|
this.currentItemCount++;
|
|
1869
|
-
|
|
1945
|
+
logger17.trace("Added new cache entry", {
|
|
1870
1946
|
key: hashedKey,
|
|
1871
1947
|
size: estimatedSize,
|
|
1872
1948
|
currentSize: this.currentSizeBytes,
|
|
@@ -1883,14 +1959,14 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
1883
1959
|
this.deleteInternal(key, true, "filter");
|
|
1884
1960
|
}
|
|
1885
1961
|
deleteInternal(key, invalidateQueries = false, invalidationMode = "remove") {
|
|
1886
|
-
|
|
1962
|
+
logger17.trace("delete", { key });
|
|
1887
1963
|
const hashedKey = this.normalizedHashFunction(key);
|
|
1888
1964
|
const entry = this.map[hashedKey];
|
|
1889
1965
|
if (entry && this.normalizedHashFunction(entry.originalKey) === hashedKey) {
|
|
1890
1966
|
this.currentSizeBytes -= entry.metadata.estimatedSize;
|
|
1891
1967
|
this.currentItemCount--;
|
|
1892
1968
|
delete this.map[hashedKey];
|
|
1893
|
-
|
|
1969
|
+
logger17.trace("Deleted cache entry", {
|
|
1894
1970
|
key: hashedKey,
|
|
1895
1971
|
freedSize: entry.metadata.estimatedSize,
|
|
1896
1972
|
currentSize: this.currentSizeBytes,
|
|
@@ -1912,7 +1988,7 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
1912
1988
|
return Object.values(this.map).filter((entry) => entry.value !== null).map((entry) => entry.value);
|
|
1913
1989
|
}
|
|
1914
1990
|
async clear() {
|
|
1915
|
-
|
|
1991
|
+
logger17.debug("Clearing cache", {
|
|
1916
1992
|
itemsCleared: this.currentItemCount,
|
|
1917
1993
|
bytesFreed: this.currentSizeBytes
|
|
1918
1994
|
});
|
|
@@ -1923,10 +1999,10 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
1923
1999
|
async allIn(locations) {
|
|
1924
2000
|
const allValues = await this.values();
|
|
1925
2001
|
if (locations.length === 0) {
|
|
1926
|
-
|
|
2002
|
+
logger17.debug("Returning all items, LocKeys is empty");
|
|
1927
2003
|
return allValues;
|
|
1928
2004
|
} else {
|
|
1929
|
-
|
|
2005
|
+
logger17.debug("allIn", { locations, count: allValues.length });
|
|
1930
2006
|
return allValues.filter((item) => {
|
|
1931
2007
|
const key = item.key;
|
|
1932
2008
|
if (key && isComKey2(key)) {
|
|
@@ -1937,12 +2013,12 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
1937
2013
|
}
|
|
1938
2014
|
}
|
|
1939
2015
|
async contains(query, locations) {
|
|
1940
|
-
|
|
2016
|
+
logger17.debug("contains", { query, locations });
|
|
1941
2017
|
const items = await this.allIn(locations);
|
|
1942
2018
|
return items.some((item) => isQueryMatch2(item, query));
|
|
1943
2019
|
}
|
|
1944
2020
|
async queryIn(query, locations = []) {
|
|
1945
|
-
|
|
2021
|
+
logger17.debug("queryIn", { query, locations });
|
|
1946
2022
|
const items = await this.allIn(locations);
|
|
1947
2023
|
return items.filter((item) => isQueryMatch2(item, query));
|
|
1948
2024
|
}
|
|
@@ -1988,7 +2064,7 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
1988
2064
|
}
|
|
1989
2065
|
// Query result caching methods
|
|
1990
2066
|
async setQueryResult(queryHash, itemKeys) {
|
|
1991
|
-
|
|
2067
|
+
logger17.trace("setQueryResult", { queryHash, itemKeys });
|
|
1992
2068
|
if (queryHash in this.queryResultCache) {
|
|
1993
2069
|
this.removeQueryResultFromSizeTracking(queryHash);
|
|
1994
2070
|
}
|
|
@@ -2000,7 +2076,7 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
2000
2076
|
this.addQueryResultToSizeTracking(queryHash, entry);
|
|
2001
2077
|
}
|
|
2002
2078
|
async getQueryResult(queryHash) {
|
|
2003
|
-
|
|
2079
|
+
logger17.trace("getQueryResult", { queryHash });
|
|
2004
2080
|
const entry = this.queryResultCache[queryHash];
|
|
2005
2081
|
if (!entry) {
|
|
2006
2082
|
return null;
|
|
@@ -2022,7 +2098,7 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
2022
2098
|
this.queryResultsCacheSize = 0;
|
|
2023
2099
|
}
|
|
2024
2100
|
async invalidateItemKeys(keys) {
|
|
2025
|
-
|
|
2101
|
+
logger17.debug("invalidateItemKeys", { keys });
|
|
2026
2102
|
if (keys.length === 0) {
|
|
2027
2103
|
return;
|
|
2028
2104
|
}
|
|
@@ -2072,7 +2148,7 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
2072
2148
|
});
|
|
2073
2149
|
}
|
|
2074
2150
|
async invalidateLocation(locations) {
|
|
2075
|
-
|
|
2151
|
+
logger17.debug("invalidateLocation", { locations });
|
|
2076
2152
|
let keysToInvalidate = [];
|
|
2077
2153
|
if (locations.length === 0) {
|
|
2078
2154
|
const allKeys = await this.keys();
|
|
@@ -2092,7 +2168,7 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
2092
2168
|
const itemKeysSize = estimateValueSize(entry.itemKeys);
|
|
2093
2169
|
const totalSize = hashSize + itemKeysSize;
|
|
2094
2170
|
this.queryResultsCacheSize += totalSize;
|
|
2095
|
-
|
|
2171
|
+
logger17.trace("Added query result to size tracking", {
|
|
2096
2172
|
queryHash,
|
|
2097
2173
|
estimatedSize: totalSize,
|
|
2098
2174
|
totalQueryCacheSize: this.queryResultsCacheSize
|
|
@@ -2108,7 +2184,7 @@ var EnhancedMemoryCacheMap = class _EnhancedMemoryCacheMap extends CacheMap {
|
|
|
2108
2184
|
const itemKeysSize = estimateValueSize(entry.itemKeys);
|
|
2109
2185
|
const totalSize = hashSize + itemKeysSize;
|
|
2110
2186
|
this.queryResultsCacheSize = Math.max(0, this.queryResultsCacheSize - totalSize);
|
|
2111
|
-
|
|
2187
|
+
logger17.trace("Removed query result from size tracking", {
|
|
2112
2188
|
queryHash,
|
|
2113
2189
|
estimatedSize: totalSize,
|
|
2114
2190
|
totalQueryCacheSize: this.queryResultsCacheSize
|
|
@@ -2193,7 +2269,7 @@ import {
|
|
|
2193
2269
|
isComKey as isComKey3,
|
|
2194
2270
|
isQueryMatch as isQueryMatch3
|
|
2195
2271
|
} from "@fjell/core";
|
|
2196
|
-
var
|
|
2272
|
+
var logger18 = logger_default.get("LocalStorageCacheMap");
|
|
2197
2273
|
var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
2198
2274
|
implementationType = "browser/localStorage";
|
|
2199
2275
|
keyPrefix;
|
|
@@ -2224,7 +2300,7 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2224
2300
|
}
|
|
2225
2301
|
return keys;
|
|
2226
2302
|
} catch (error) {
|
|
2227
|
-
|
|
2303
|
+
logger18.error("Error getting keys by prefix from localStorage", { prefix, error });
|
|
2228
2304
|
throw error;
|
|
2229
2305
|
}
|
|
2230
2306
|
}
|
|
@@ -2232,12 +2308,12 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2232
2308
|
try {
|
|
2233
2309
|
const allEntries = this.collectCacheEntries();
|
|
2234
2310
|
if (allEntries.length === 0) {
|
|
2235
|
-
|
|
2311
|
+
logger18.debug("No entries to clean up");
|
|
2236
2312
|
return false;
|
|
2237
2313
|
}
|
|
2238
2314
|
return this.removeOldestEntries(allEntries, aggressive);
|
|
2239
2315
|
} catch (error) {
|
|
2240
|
-
|
|
2316
|
+
logger18.error("Failed to cleanup old localStorage entries", { error });
|
|
2241
2317
|
return false;
|
|
2242
2318
|
}
|
|
2243
2319
|
}
|
|
@@ -2263,7 +2339,7 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2263
2339
|
}
|
|
2264
2340
|
}
|
|
2265
2341
|
} catch (error) {
|
|
2266
|
-
|
|
2342
|
+
logger18.debug("Found corrupted entry during cleanup", { key, error });
|
|
2267
2343
|
allEntries.push({ key, timestamp: 0, size: 0 });
|
|
2268
2344
|
}
|
|
2269
2345
|
}
|
|
@@ -2282,12 +2358,12 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2282
2358
|
removedCount++;
|
|
2283
2359
|
removedSize += allEntries[i].size;
|
|
2284
2360
|
} catch (error) {
|
|
2285
|
-
|
|
2361
|
+
logger18.error("Failed to remove entry during cleanup", { key: allEntries[i].key, error });
|
|
2286
2362
|
}
|
|
2287
2363
|
}
|
|
2288
2364
|
if (removedCount > 0) {
|
|
2289
2365
|
const cleanupType = aggressive ? "aggressive" : "normal";
|
|
2290
|
-
|
|
2366
|
+
logger18.info(`Cleaned up ${removedCount} old localStorage entries (${removedSize} bytes) using ${cleanupType} cleanup to free space`);
|
|
2291
2367
|
}
|
|
2292
2368
|
return removedCount > 0;
|
|
2293
2369
|
}
|
|
@@ -2295,7 +2371,7 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2295
2371
|
return this.getAllKeysStartingWith(`${this.keyPrefix}:`);
|
|
2296
2372
|
}
|
|
2297
2373
|
async get(key) {
|
|
2298
|
-
|
|
2374
|
+
logger18.trace("get", { key });
|
|
2299
2375
|
try {
|
|
2300
2376
|
const storageKey = this.getStorageKey(key);
|
|
2301
2377
|
let stored = localStorage.getItem(storageKey);
|
|
@@ -2310,18 +2386,18 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2310
2386
|
return parsed.value;
|
|
2311
2387
|
}
|
|
2312
2388
|
} catch (parseError) {
|
|
2313
|
-
|
|
2389
|
+
logger18.debug("Failed to parse stored value", { key, error: parseError });
|
|
2314
2390
|
return null;
|
|
2315
2391
|
}
|
|
2316
2392
|
}
|
|
2317
2393
|
return null;
|
|
2318
2394
|
} catch (error) {
|
|
2319
|
-
|
|
2395
|
+
logger18.error("Error retrieving from localStorage", { key, error });
|
|
2320
2396
|
return null;
|
|
2321
2397
|
}
|
|
2322
2398
|
}
|
|
2323
2399
|
async set(key, value) {
|
|
2324
|
-
|
|
2400
|
+
logger18.trace("set", { key, value });
|
|
2325
2401
|
for (let attempt = 0; attempt < this.MAX_RETRY_ATTEMPTS; attempt++) {
|
|
2326
2402
|
try {
|
|
2327
2403
|
const storageKey = this.getStorageKey(key);
|
|
@@ -2332,12 +2408,12 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2332
2408
|
};
|
|
2333
2409
|
localStorage.setItem(storageKey, JSON.stringify(toStore));
|
|
2334
2410
|
if (attempt > 0) {
|
|
2335
|
-
|
|
2411
|
+
logger18.info(`Successfully stored item after ${attempt} retries`);
|
|
2336
2412
|
}
|
|
2337
2413
|
return;
|
|
2338
2414
|
} catch (error) {
|
|
2339
2415
|
const isLastAttempt = attempt === this.MAX_RETRY_ATTEMPTS - 1;
|
|
2340
|
-
|
|
2416
|
+
logger18.error(`Error storing to localStorage (attempt ${attempt + 1}/${this.MAX_RETRY_ATTEMPTS})`, {
|
|
2341
2417
|
key,
|
|
2342
2418
|
value,
|
|
2343
2419
|
error,
|
|
@@ -2364,30 +2440,30 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2364
2440
|
const parsed = JSON.parse(stored);
|
|
2365
2441
|
return this.normalizedHashFunction(parsed.originalKey) === this.normalizedHashFunction(key);
|
|
2366
2442
|
} catch (parseError) {
|
|
2367
|
-
|
|
2443
|
+
logger18.debug("Failed to parse stored value in includesKey", { key, error: parseError });
|
|
2368
2444
|
return false;
|
|
2369
2445
|
}
|
|
2370
2446
|
}
|
|
2371
2447
|
return false;
|
|
2372
2448
|
} catch (error) {
|
|
2373
|
-
|
|
2449
|
+
logger18.error("Error checking key in localStorage", { key, error });
|
|
2374
2450
|
return false;
|
|
2375
2451
|
}
|
|
2376
2452
|
}
|
|
2377
2453
|
async delete(key) {
|
|
2378
|
-
|
|
2454
|
+
logger18.trace("delete", { key });
|
|
2379
2455
|
try {
|
|
2380
2456
|
const storageKey = this.getStorageKey(key);
|
|
2381
2457
|
localStorage.removeItem(storageKey);
|
|
2382
2458
|
} catch (error) {
|
|
2383
|
-
|
|
2459
|
+
logger18.error("Error deleting from localStorage", { key, error });
|
|
2384
2460
|
throw error;
|
|
2385
2461
|
}
|
|
2386
2462
|
}
|
|
2387
2463
|
async allIn(locations) {
|
|
2388
2464
|
const allKeys = this.keys();
|
|
2389
2465
|
if (locations.length === 0) {
|
|
2390
|
-
|
|
2466
|
+
logger18.debug("Returning all items, LocKeys is empty");
|
|
2391
2467
|
const items = [];
|
|
2392
2468
|
for (const key of await allKeys) {
|
|
2393
2469
|
const item = await this.get(key);
|
|
@@ -2399,14 +2475,14 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2399
2475
|
} else {
|
|
2400
2476
|
const locKeys = locations;
|
|
2401
2477
|
const resolvedKeys = await allKeys;
|
|
2402
|
-
|
|
2478
|
+
logger18.debug("allIn", { locKeys, keys: resolvedKeys.length });
|
|
2403
2479
|
const filteredKeys = resolvedKeys.filter((key) => key && isComKey3(key)).filter((key) => {
|
|
2404
|
-
const
|
|
2405
|
-
|
|
2480
|
+
const ComKey16 = key;
|
|
2481
|
+
logger18.debug("Comparing Location Keys", {
|
|
2406
2482
|
locKeys,
|
|
2407
|
-
ComKey:
|
|
2483
|
+
ComKey: ComKey16
|
|
2408
2484
|
});
|
|
2409
|
-
return isLocKeyArrayEqual(locKeys,
|
|
2485
|
+
return isLocKeyArrayEqual(locKeys, ComKey16.loc);
|
|
2410
2486
|
});
|
|
2411
2487
|
const items = [];
|
|
2412
2488
|
for (const key of filteredKeys) {
|
|
@@ -2419,12 +2495,12 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2419
2495
|
}
|
|
2420
2496
|
}
|
|
2421
2497
|
async contains(query, locations) {
|
|
2422
|
-
|
|
2498
|
+
logger18.debug("contains", { query, locations });
|
|
2423
2499
|
const items = await this.allIn(locations);
|
|
2424
2500
|
return items.some((item) => isQueryMatch3(item, query));
|
|
2425
2501
|
}
|
|
2426
2502
|
async queryIn(query, locations = []) {
|
|
2427
|
-
|
|
2503
|
+
logger18.debug("queryIn", { query, locations });
|
|
2428
2504
|
const items = await this.allIn(locations);
|
|
2429
2505
|
return items.filter((item) => isQueryMatch3(item, query));
|
|
2430
2506
|
}
|
|
@@ -2438,7 +2514,7 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2438
2514
|
return JSON.parse(stored);
|
|
2439
2515
|
}
|
|
2440
2516
|
} catch (parseError) {
|
|
2441
|
-
|
|
2517
|
+
logger18.debug("Skipping corrupted localStorage entry", { storageKey, error: parseError });
|
|
2442
2518
|
}
|
|
2443
2519
|
return null;
|
|
2444
2520
|
}
|
|
@@ -2453,7 +2529,7 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2453
2529
|
}
|
|
2454
2530
|
}
|
|
2455
2531
|
} catch (error) {
|
|
2456
|
-
|
|
2532
|
+
logger18.error("Error getting keys from localStorage", { error });
|
|
2457
2533
|
}
|
|
2458
2534
|
return keys;
|
|
2459
2535
|
}
|
|
@@ -2468,25 +2544,25 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2468
2544
|
}
|
|
2469
2545
|
}
|
|
2470
2546
|
} catch (error) {
|
|
2471
|
-
|
|
2547
|
+
logger18.error("Error getting values from localStorage", { error });
|
|
2472
2548
|
}
|
|
2473
2549
|
return values;
|
|
2474
2550
|
}
|
|
2475
2551
|
async clear() {
|
|
2476
|
-
|
|
2552
|
+
logger18.debug("Clearing localStorage cache");
|
|
2477
2553
|
try {
|
|
2478
2554
|
const storageKeys = this.getAllStorageKeys();
|
|
2479
2555
|
for (const storageKey of storageKeys) {
|
|
2480
2556
|
localStorage.removeItem(storageKey);
|
|
2481
2557
|
}
|
|
2482
2558
|
} catch (error) {
|
|
2483
|
-
|
|
2559
|
+
logger18.error("Error clearing localStorage cache", { error });
|
|
2484
2560
|
throw error;
|
|
2485
2561
|
}
|
|
2486
2562
|
}
|
|
2487
2563
|
// Query result caching methods implementation
|
|
2488
2564
|
async setQueryResult(queryHash, itemKeys) {
|
|
2489
|
-
|
|
2565
|
+
logger18.trace("setQueryResult", { queryHash, itemKeys });
|
|
2490
2566
|
const queryKey = `${this.keyPrefix}:query:${queryHash}`;
|
|
2491
2567
|
const entry = {
|
|
2492
2568
|
itemKeys
|
|
@@ -2494,11 +2570,11 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2494
2570
|
try {
|
|
2495
2571
|
localStorage.setItem(queryKey, JSON.stringify(entry));
|
|
2496
2572
|
} catch (error) {
|
|
2497
|
-
|
|
2573
|
+
logger18.error("Failed to store query result in localStorage", { queryHash, error });
|
|
2498
2574
|
}
|
|
2499
2575
|
}
|
|
2500
2576
|
async getQueryResult(queryHash) {
|
|
2501
|
-
|
|
2577
|
+
logger18.trace("getQueryResult", { queryHash });
|
|
2502
2578
|
const queryKey = `${this.keyPrefix}:query:${queryHash}`;
|
|
2503
2579
|
try {
|
|
2504
2580
|
const data = localStorage.getItem(queryKey);
|
|
@@ -2511,7 +2587,7 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2511
2587
|
}
|
|
2512
2588
|
return entry.itemKeys || null;
|
|
2513
2589
|
} catch (error) {
|
|
2514
|
-
|
|
2590
|
+
logger18.error("Failed to retrieve query result from localStorage", { queryHash, error });
|
|
2515
2591
|
return null;
|
|
2516
2592
|
}
|
|
2517
2593
|
}
|
|
@@ -2520,21 +2596,21 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2520
2596
|
try {
|
|
2521
2597
|
return localStorage.getItem(queryKey) !== null;
|
|
2522
2598
|
} catch (error) {
|
|
2523
|
-
|
|
2599
|
+
logger18.error("Failed to check query result in localStorage", { queryHash, error });
|
|
2524
2600
|
return false;
|
|
2525
2601
|
}
|
|
2526
2602
|
}
|
|
2527
2603
|
async deleteQueryResult(queryHash) {
|
|
2528
|
-
|
|
2604
|
+
logger18.trace("deleteQueryResult", { queryHash });
|
|
2529
2605
|
const queryKey = `${this.keyPrefix}:query:${queryHash}`;
|
|
2530
2606
|
try {
|
|
2531
2607
|
localStorage.removeItem(queryKey);
|
|
2532
2608
|
} catch (error) {
|
|
2533
|
-
|
|
2609
|
+
logger18.error("Failed to delete query result from localStorage", { queryHash, error });
|
|
2534
2610
|
}
|
|
2535
2611
|
}
|
|
2536
2612
|
async invalidateItemKeys(keys) {
|
|
2537
|
-
|
|
2613
|
+
logger18.debug("invalidateItemKeys", { keys });
|
|
2538
2614
|
if (keys.length === 0) {
|
|
2539
2615
|
return;
|
|
2540
2616
|
}
|
|
@@ -2572,24 +2648,24 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2572
2648
|
}
|
|
2573
2649
|
}
|
|
2574
2650
|
} catch (error) {
|
|
2575
|
-
|
|
2651
|
+
logger18.debug("Failed to parse query result", { queryKey, error });
|
|
2576
2652
|
}
|
|
2577
2653
|
}
|
|
2578
2654
|
queriesToRemove.forEach((queryKey) => {
|
|
2579
2655
|
localStorage.removeItem(queryKey);
|
|
2580
2656
|
});
|
|
2581
|
-
|
|
2657
|
+
logger18.debug("Selectively invalidated queries referencing affected keys", {
|
|
2582
2658
|
affectedKeys: keys.length,
|
|
2583
2659
|
queriesRemoved: queriesToRemove.length,
|
|
2584
2660
|
totalQueries: queryKeys.length
|
|
2585
2661
|
});
|
|
2586
2662
|
} catch (error) {
|
|
2587
|
-
|
|
2663
|
+
logger18.error("Error during selective query invalidation, falling back to clearing all queries", { error });
|
|
2588
2664
|
await this.clearQueryResults();
|
|
2589
2665
|
}
|
|
2590
2666
|
}
|
|
2591
2667
|
async invalidateLocation(locations) {
|
|
2592
|
-
|
|
2668
|
+
logger18.debug("invalidateLocation", { locations });
|
|
2593
2669
|
let keysToInvalidate = [];
|
|
2594
2670
|
if (locations.length === 0) {
|
|
2595
2671
|
const allKeys = await this.keys();
|
|
@@ -2604,7 +2680,7 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2604
2680
|
}
|
|
2605
2681
|
}
|
|
2606
2682
|
async clearQueryResults() {
|
|
2607
|
-
|
|
2683
|
+
logger18.trace("clearQueryResults");
|
|
2608
2684
|
const queryPrefix = `${this.keyPrefix}:query:`;
|
|
2609
2685
|
try {
|
|
2610
2686
|
const keysToRemove = this.getAllKeysStartingWith(queryPrefix);
|
|
@@ -2612,11 +2688,11 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2612
2688
|
try {
|
|
2613
2689
|
localStorage.removeItem(key);
|
|
2614
2690
|
} catch (error) {
|
|
2615
|
-
|
|
2691
|
+
logger18.error("Failed to remove query result from localStorage", { key, error });
|
|
2616
2692
|
}
|
|
2617
2693
|
}
|
|
2618
2694
|
} catch (error) {
|
|
2619
|
-
|
|
2695
|
+
logger18.error("Failed to clear query results from localStorage", { error });
|
|
2620
2696
|
}
|
|
2621
2697
|
}
|
|
2622
2698
|
// CacheMapMetadataProvider implementation
|
|
@@ -2628,13 +2704,13 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2628
2704
|
try {
|
|
2629
2705
|
return JSON.parse(stored);
|
|
2630
2706
|
} catch (e) {
|
|
2631
|
-
|
|
2707
|
+
logger18.debug("Invalid metadata JSON, treating as null", { key, error: e });
|
|
2632
2708
|
return null;
|
|
2633
2709
|
}
|
|
2634
2710
|
}
|
|
2635
2711
|
return null;
|
|
2636
2712
|
} catch (error) {
|
|
2637
|
-
|
|
2713
|
+
logger18.error("Error getting metadata from localStorage", { key, error });
|
|
2638
2714
|
throw error;
|
|
2639
2715
|
}
|
|
2640
2716
|
}
|
|
@@ -2644,12 +2720,12 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2644
2720
|
const metadataKey = `${this.keyPrefix}:metadata:${key}`;
|
|
2645
2721
|
localStorage.setItem(metadataKey, JSON.stringify(metadata));
|
|
2646
2722
|
if (attempt > 0) {
|
|
2647
|
-
|
|
2723
|
+
logger18.info(`Successfully stored metadata after ${attempt} retries`);
|
|
2648
2724
|
}
|
|
2649
2725
|
return;
|
|
2650
2726
|
} catch (error) {
|
|
2651
2727
|
const isLastAttempt = attempt === this.MAX_RETRY_ATTEMPTS - 1;
|
|
2652
|
-
|
|
2728
|
+
logger18.error(`Error storing metadata to localStorage (attempt ${attempt + 1}/${this.MAX_RETRY_ATTEMPTS})`, {
|
|
2653
2729
|
key,
|
|
2654
2730
|
error,
|
|
2655
2731
|
isLastAttempt
|
|
@@ -2671,7 +2747,7 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2671
2747
|
const metadataKey = `${this.keyPrefix}:metadata:${key}`;
|
|
2672
2748
|
localStorage.removeItem(metadataKey);
|
|
2673
2749
|
} catch (error) {
|
|
2674
|
-
|
|
2750
|
+
logger18.error("Error deleting metadata from localStorage", { key, error });
|
|
2675
2751
|
throw error;
|
|
2676
2752
|
}
|
|
2677
2753
|
}
|
|
@@ -2690,11 +2766,11 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2690
2766
|
metadata.set(metadataKey, parsed);
|
|
2691
2767
|
}
|
|
2692
2768
|
} catch (error) {
|
|
2693
|
-
|
|
2769
|
+
logger18.debug("Skipping invalid metadata entry", { key, error });
|
|
2694
2770
|
}
|
|
2695
2771
|
}
|
|
2696
2772
|
} catch (error) {
|
|
2697
|
-
|
|
2773
|
+
logger18.error("Error getting metadata from localStorage", { error });
|
|
2698
2774
|
throw error;
|
|
2699
2775
|
}
|
|
2700
2776
|
return metadata;
|
|
@@ -2705,7 +2781,7 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2705
2781
|
const keysToDelete = this.getAllKeysStartingWith(metadataPrefix);
|
|
2706
2782
|
keysToDelete.forEach((key) => localStorage.removeItem(key));
|
|
2707
2783
|
} catch (error) {
|
|
2708
|
-
|
|
2784
|
+
logger18.error("Error clearing metadata from localStorage", { error });
|
|
2709
2785
|
throw error;
|
|
2710
2786
|
}
|
|
2711
2787
|
}
|
|
@@ -2732,16 +2808,16 @@ var LocalStorageCacheMap = class _LocalStorageCacheMap extends CacheMap {
|
|
|
2732
2808
|
itemCount++;
|
|
2733
2809
|
}
|
|
2734
2810
|
} catch (error) {
|
|
2735
|
-
|
|
2811
|
+
logger18.debug("Invalid entry in getCurrentSize", { key, error });
|
|
2736
2812
|
}
|
|
2737
2813
|
}
|
|
2738
2814
|
} catch (error) {
|
|
2739
|
-
|
|
2815
|
+
logger18.debug("Size calculation failed, using string length", { key, error });
|
|
2740
2816
|
sizeBytes += value.length;
|
|
2741
2817
|
}
|
|
2742
2818
|
}
|
|
2743
2819
|
} catch (error) {
|
|
2744
|
-
|
|
2820
|
+
logger18.error("Error calculating size from localStorage", { error });
|
|
2745
2821
|
throw error;
|
|
2746
2822
|
}
|
|
2747
2823
|
return { itemCount, sizeBytes };
|
|
@@ -2762,7 +2838,7 @@ import {
|
|
|
2762
2838
|
isQueryMatch as isQueryMatch4
|
|
2763
2839
|
} from "@fjell/core";
|
|
2764
2840
|
import safeStringify2 from "fast-safe-stringify";
|
|
2765
|
-
var
|
|
2841
|
+
var logger19 = logger_default.get("SessionStorageCacheMap");
|
|
2766
2842
|
var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
2767
2843
|
implementationType = "browser/sessionStorage";
|
|
2768
2844
|
keyPrefix;
|
|
@@ -2790,7 +2866,7 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
2790
2866
|
}
|
|
2791
2867
|
}
|
|
2792
2868
|
} catch (error) {
|
|
2793
|
-
|
|
2869
|
+
logger19.error("Error getting keys from sessionStorage", { error });
|
|
2794
2870
|
}
|
|
2795
2871
|
return keys;
|
|
2796
2872
|
}
|
|
@@ -2813,7 +2889,7 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
2813
2889
|
}
|
|
2814
2890
|
}
|
|
2815
2891
|
async get(key) {
|
|
2816
|
-
|
|
2892
|
+
logger19.trace("get", { key });
|
|
2817
2893
|
try {
|
|
2818
2894
|
const currentHash = this.normalizedHashFunction(key);
|
|
2819
2895
|
if (this.hasCollisionForHash(currentHash)) {
|
|
@@ -2833,14 +2909,14 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
2833
2909
|
}
|
|
2834
2910
|
return null;
|
|
2835
2911
|
} catch (error) {
|
|
2836
|
-
|
|
2912
|
+
logger19.error("Error retrieving from sessionStorage", { key, error });
|
|
2837
2913
|
return null;
|
|
2838
2914
|
}
|
|
2839
2915
|
}
|
|
2840
2916
|
async set(key, value) {
|
|
2841
2917
|
try {
|
|
2842
2918
|
const storageKey = this.getStorageKey(key);
|
|
2843
|
-
|
|
2919
|
+
logger19.trace("set", { storageKey });
|
|
2844
2920
|
const toStore = {
|
|
2845
2921
|
originalKey: key,
|
|
2846
2922
|
value,
|
|
@@ -2850,7 +2926,7 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
2850
2926
|
const jsonString = safeStringify2(toStore);
|
|
2851
2927
|
sessionStorage.setItem(storageKey, jsonString);
|
|
2852
2928
|
} catch (error) {
|
|
2853
|
-
|
|
2929
|
+
logger19.error("Error storing to sessionStorage", { errorMessage: error?.message });
|
|
2854
2930
|
throw new Error(`Failed to store item in sessionStorage: ${error}`);
|
|
2855
2931
|
}
|
|
2856
2932
|
}
|
|
@@ -2871,23 +2947,23 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
2871
2947
|
}
|
|
2872
2948
|
return false;
|
|
2873
2949
|
} catch (error) {
|
|
2874
|
-
|
|
2950
|
+
logger19.error("Error checking key in sessionStorage", { key, error });
|
|
2875
2951
|
return false;
|
|
2876
2952
|
}
|
|
2877
2953
|
}
|
|
2878
2954
|
async delete(key) {
|
|
2879
|
-
|
|
2955
|
+
logger19.trace("delete", { key });
|
|
2880
2956
|
try {
|
|
2881
2957
|
const storageKey = this.getStorageKey(key);
|
|
2882
2958
|
sessionStorage.removeItem(storageKey);
|
|
2883
2959
|
} catch (error) {
|
|
2884
|
-
|
|
2960
|
+
logger19.error("Error deleting from sessionStorage", { key, error });
|
|
2885
2961
|
}
|
|
2886
2962
|
}
|
|
2887
2963
|
async allIn(locations) {
|
|
2888
2964
|
const allKeys = this.keys();
|
|
2889
2965
|
if (locations.length === 0) {
|
|
2890
|
-
|
|
2966
|
+
logger19.debug("Returning all items, LocKeys is empty");
|
|
2891
2967
|
const items = [];
|
|
2892
2968
|
for (const key of await allKeys) {
|
|
2893
2969
|
const item = await this.get(key);
|
|
@@ -2899,14 +2975,14 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
2899
2975
|
} else {
|
|
2900
2976
|
const locKeys = locations;
|
|
2901
2977
|
const resolvedKeys = await allKeys;
|
|
2902
|
-
|
|
2978
|
+
logger19.debug("allIn", { locKeys, keys: resolvedKeys.length });
|
|
2903
2979
|
const filteredKeys = resolvedKeys.filter((key) => key && isComKey4(key)).filter((key) => {
|
|
2904
|
-
const
|
|
2905
|
-
|
|
2980
|
+
const ComKey16 = key;
|
|
2981
|
+
logger19.debug("Comparing Location Keys", {
|
|
2906
2982
|
locKeys,
|
|
2907
|
-
ComKey:
|
|
2983
|
+
ComKey: ComKey16
|
|
2908
2984
|
});
|
|
2909
|
-
return isLocKeyArrayEqual(locKeys,
|
|
2985
|
+
return isLocKeyArrayEqual(locKeys, ComKey16.loc);
|
|
2910
2986
|
});
|
|
2911
2987
|
const items = [];
|
|
2912
2988
|
for (const key of filteredKeys) {
|
|
@@ -2919,12 +2995,12 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
2919
2995
|
}
|
|
2920
2996
|
}
|
|
2921
2997
|
async contains(query, locations) {
|
|
2922
|
-
|
|
2998
|
+
logger19.debug("contains", { query, locations });
|
|
2923
2999
|
const items = await this.allIn(locations);
|
|
2924
3000
|
return items.some((item) => isQueryMatch4(item, query));
|
|
2925
3001
|
}
|
|
2926
3002
|
async queryIn(query, locations = []) {
|
|
2927
|
-
|
|
3003
|
+
logger19.debug("queryIn", { query, locations });
|
|
2928
3004
|
const items = await this.allIn(locations);
|
|
2929
3005
|
return items.filter((item) => isQueryMatch4(item, query));
|
|
2930
3006
|
}
|
|
@@ -2944,11 +3020,11 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
2944
3020
|
keys.push(parsed.originalKey);
|
|
2945
3021
|
}
|
|
2946
3022
|
} catch (itemError) {
|
|
2947
|
-
|
|
3023
|
+
logger19.trace("Skipping invalid storage item", { storageKey, error: itemError });
|
|
2948
3024
|
}
|
|
2949
3025
|
}
|
|
2950
3026
|
} catch (error) {
|
|
2951
|
-
|
|
3027
|
+
logger19.error("Error getting keys from sessionStorage", { error });
|
|
2952
3028
|
}
|
|
2953
3029
|
return keys;
|
|
2954
3030
|
}
|
|
@@ -2965,28 +3041,28 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
2965
3041
|
values.push(parsed.value);
|
|
2966
3042
|
}
|
|
2967
3043
|
} catch (itemError) {
|
|
2968
|
-
|
|
3044
|
+
logger19.trace("Skipping invalid storage item for values", { storageKey, error: itemError });
|
|
2969
3045
|
}
|
|
2970
3046
|
}
|
|
2971
3047
|
} catch (error) {
|
|
2972
|
-
|
|
3048
|
+
logger19.error("Error getting values from sessionStorage", { error });
|
|
2973
3049
|
}
|
|
2974
3050
|
return values;
|
|
2975
3051
|
}
|
|
2976
3052
|
async clear() {
|
|
2977
|
-
|
|
3053
|
+
logger19.debug("Clearing sessionStorage cache");
|
|
2978
3054
|
try {
|
|
2979
3055
|
const storageKeys = this.getAllStorageKeys();
|
|
2980
3056
|
for (const storageKey of storageKeys) {
|
|
2981
3057
|
sessionStorage.removeItem(storageKey);
|
|
2982
3058
|
}
|
|
2983
3059
|
} catch (error) {
|
|
2984
|
-
|
|
3060
|
+
logger19.error("Error clearing sessionStorage cache", { error });
|
|
2985
3061
|
}
|
|
2986
3062
|
}
|
|
2987
3063
|
// Query result caching methods implementation
|
|
2988
3064
|
async setQueryResult(queryHash, itemKeys) {
|
|
2989
|
-
|
|
3065
|
+
logger19.trace("setQueryResult", { queryHash, itemKeys });
|
|
2990
3066
|
const queryKey = `${this.keyPrefix}:query:${queryHash}`;
|
|
2991
3067
|
const entry = {
|
|
2992
3068
|
itemKeys
|
|
@@ -2995,11 +3071,11 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
2995
3071
|
const jsonString = safeStringify2(entry);
|
|
2996
3072
|
sessionStorage.setItem(queryKey, jsonString);
|
|
2997
3073
|
} catch (error) {
|
|
2998
|
-
|
|
3074
|
+
logger19.error("Failed to store query result in sessionStorage", { queryHash, error });
|
|
2999
3075
|
}
|
|
3000
3076
|
}
|
|
3001
3077
|
async getQueryResult(queryHash) {
|
|
3002
|
-
|
|
3078
|
+
logger19.trace("getQueryResult", { queryHash });
|
|
3003
3079
|
const queryKey = `${this.keyPrefix}:query:${queryHash}`;
|
|
3004
3080
|
try {
|
|
3005
3081
|
const data = sessionStorage.getItem(queryKey);
|
|
@@ -3012,7 +3088,7 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
3012
3088
|
}
|
|
3013
3089
|
return entry.itemKeys || null;
|
|
3014
3090
|
} catch (error) {
|
|
3015
|
-
|
|
3091
|
+
logger19.error("Failed to retrieve query result from sessionStorage", { queryHash, error });
|
|
3016
3092
|
return null;
|
|
3017
3093
|
}
|
|
3018
3094
|
}
|
|
@@ -3021,21 +3097,21 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
3021
3097
|
try {
|
|
3022
3098
|
return sessionStorage.getItem(queryKey) !== null;
|
|
3023
3099
|
} catch (error) {
|
|
3024
|
-
|
|
3100
|
+
logger19.error("Failed to check query result in sessionStorage", { queryHash, error });
|
|
3025
3101
|
return false;
|
|
3026
3102
|
}
|
|
3027
3103
|
}
|
|
3028
3104
|
async deleteQueryResult(queryHash) {
|
|
3029
|
-
|
|
3105
|
+
logger19.trace("deleteQueryResult", { queryHash });
|
|
3030
3106
|
const queryKey = `${this.keyPrefix}:query:${queryHash}`;
|
|
3031
3107
|
try {
|
|
3032
3108
|
sessionStorage.removeItem(queryKey);
|
|
3033
3109
|
} catch (error) {
|
|
3034
|
-
|
|
3110
|
+
logger19.error("Failed to delete query result from sessionStorage", { queryHash, error });
|
|
3035
3111
|
}
|
|
3036
3112
|
}
|
|
3037
3113
|
async clearQueryResults() {
|
|
3038
|
-
|
|
3114
|
+
logger19.trace("clearQueryResults");
|
|
3039
3115
|
const queryPrefix = `${this.keyPrefix}:query:`;
|
|
3040
3116
|
try {
|
|
3041
3117
|
const keysToRemove = [];
|
|
@@ -3047,7 +3123,7 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
3047
3123
|
}
|
|
3048
3124
|
keysToRemove.forEach((key) => sessionStorage.removeItem(key));
|
|
3049
3125
|
} catch (error) {
|
|
3050
|
-
|
|
3126
|
+
logger19.error("Failed to clear query results from sessionStorage", { error });
|
|
3051
3127
|
}
|
|
3052
3128
|
}
|
|
3053
3129
|
// CacheMapMetadataProvider implementation
|
|
@@ -3094,7 +3170,7 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
3094
3170
|
}
|
|
3095
3171
|
return metadata;
|
|
3096
3172
|
} catch (error) {
|
|
3097
|
-
|
|
3173
|
+
logger19.error("Error getting all metadata from sessionStorage", { error });
|
|
3098
3174
|
return metadata;
|
|
3099
3175
|
}
|
|
3100
3176
|
}
|
|
@@ -3114,7 +3190,7 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
3114
3190
|
}
|
|
3115
3191
|
// Invalidation methods
|
|
3116
3192
|
async invalidateItemKeys(keys) {
|
|
3117
|
-
|
|
3193
|
+
logger19.debug("invalidateItemKeys", { keys });
|
|
3118
3194
|
if (keys.length === 0) {
|
|
3119
3195
|
return;
|
|
3120
3196
|
}
|
|
@@ -3158,24 +3234,24 @@ var SessionStorageCacheMap = class _SessionStorageCacheMap extends CacheMap {
|
|
|
3158
3234
|
}
|
|
3159
3235
|
}
|
|
3160
3236
|
} catch (error) {
|
|
3161
|
-
|
|
3237
|
+
logger19.debug("Failed to parse query result", { queryKey, error });
|
|
3162
3238
|
}
|
|
3163
3239
|
}
|
|
3164
3240
|
queriesToRemove.forEach((queryKey) => {
|
|
3165
3241
|
sessionStorage.removeItem(queryKey);
|
|
3166
3242
|
});
|
|
3167
|
-
|
|
3243
|
+
logger19.debug("Selectively invalidated queries referencing affected keys", {
|
|
3168
3244
|
affectedKeys: keys.length,
|
|
3169
3245
|
queriesRemoved: queriesToRemove.length,
|
|
3170
3246
|
totalQueries: queryKeys.length
|
|
3171
3247
|
});
|
|
3172
3248
|
} catch (error) {
|
|
3173
|
-
|
|
3249
|
+
logger19.error("Error during selective query invalidation, falling back to clearing all queries", { error });
|
|
3174
3250
|
await this.clearQueryResults();
|
|
3175
3251
|
}
|
|
3176
3252
|
}
|
|
3177
3253
|
async invalidateLocation(locations) {
|
|
3178
|
-
|
|
3254
|
+
logger19.debug("invalidateLocation", { locations });
|
|
3179
3255
|
let keysToInvalidate = [];
|
|
3180
3256
|
if (locations.length === 0) {
|
|
3181
3257
|
const allKeys = await this.keys();
|
|
@@ -3241,7 +3317,7 @@ import {
|
|
|
3241
3317
|
isQueryMatch as isQueryMatch5
|
|
3242
3318
|
} from "@fjell/core";
|
|
3243
3319
|
import safeStringify3 from "fast-safe-stringify";
|
|
3244
|
-
var
|
|
3320
|
+
var logger20 = logger_default.get("AsyncIndexDBCacheMap");
|
|
3245
3321
|
var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
3246
3322
|
types;
|
|
3247
3323
|
dbName;
|
|
@@ -3267,19 +3343,19 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3267
3343
|
}
|
|
3268
3344
|
const request = indexedDB.open(this.dbName, this.version);
|
|
3269
3345
|
request.onerror = () => {
|
|
3270
|
-
|
|
3346
|
+
logger20.error("Error opening IndexedDB", { error: request.error });
|
|
3271
3347
|
reject(request.error);
|
|
3272
3348
|
};
|
|
3273
3349
|
request.onsuccess = () => {
|
|
3274
|
-
|
|
3350
|
+
logger20.debug("IndexedDB opened successfully");
|
|
3275
3351
|
resolve(request.result);
|
|
3276
3352
|
};
|
|
3277
3353
|
request.onupgradeneeded = (event) => {
|
|
3278
|
-
|
|
3354
|
+
logger20.debug("IndexedDB upgrade needed");
|
|
3279
3355
|
const db = event.target.result;
|
|
3280
3356
|
if (!db.objectStoreNames.contains(this.storeName)) {
|
|
3281
3357
|
db.createObjectStore(this.storeName);
|
|
3282
|
-
|
|
3358
|
+
logger20.debug("Created object store", { storeName: this.storeName });
|
|
3283
3359
|
}
|
|
3284
3360
|
};
|
|
3285
3361
|
});
|
|
@@ -3290,7 +3366,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3290
3366
|
return this.normalizedHashFunction(key);
|
|
3291
3367
|
}
|
|
3292
3368
|
async get(key) {
|
|
3293
|
-
|
|
3369
|
+
logger20.trace("get", { key });
|
|
3294
3370
|
try {
|
|
3295
3371
|
const db = await this.getDB();
|
|
3296
3372
|
const transaction = db.transaction([this.storeName], "readonly");
|
|
@@ -3299,7 +3375,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3299
3375
|
return new Promise((resolve, reject) => {
|
|
3300
3376
|
const request = store.get(storageKey);
|
|
3301
3377
|
request.onerror = () => {
|
|
3302
|
-
|
|
3378
|
+
logger20.error("Error getting from IndexedDB", { key, error: request.error });
|
|
3303
3379
|
reject(request.error);
|
|
3304
3380
|
};
|
|
3305
3381
|
request.onsuccess = () => {
|
|
@@ -3312,7 +3388,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3312
3388
|
};
|
|
3313
3389
|
});
|
|
3314
3390
|
} catch (error) {
|
|
3315
|
-
|
|
3391
|
+
logger20.error("Error in IndexedDB get operation", { key, error });
|
|
3316
3392
|
return null;
|
|
3317
3393
|
}
|
|
3318
3394
|
}
|
|
@@ -3320,7 +3396,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3320
3396
|
* Get both the value and metadata for an item
|
|
3321
3397
|
*/
|
|
3322
3398
|
async getWithMetadata(key) {
|
|
3323
|
-
|
|
3399
|
+
logger20.trace("getWithMetadata", { key });
|
|
3324
3400
|
try {
|
|
3325
3401
|
const db = await this.getDB();
|
|
3326
3402
|
const transaction = db.transaction([this.storeName], "readonly");
|
|
@@ -3329,7 +3405,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3329
3405
|
return new Promise((resolve, reject) => {
|
|
3330
3406
|
const request = store.get(storageKey);
|
|
3331
3407
|
request.onerror = () => {
|
|
3332
|
-
|
|
3408
|
+
logger20.error("Error getting from IndexedDB", { key, error: request.error });
|
|
3333
3409
|
reject(request.error);
|
|
3334
3410
|
};
|
|
3335
3411
|
request.onsuccess = () => {
|
|
@@ -3345,12 +3421,12 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3345
3421
|
};
|
|
3346
3422
|
});
|
|
3347
3423
|
} catch (error) {
|
|
3348
|
-
|
|
3424
|
+
logger20.error("Error in IndexedDB getWithMetadata operation", { key, error });
|
|
3349
3425
|
return null;
|
|
3350
3426
|
}
|
|
3351
3427
|
}
|
|
3352
3428
|
async set(key, value, metadata) {
|
|
3353
|
-
|
|
3429
|
+
logger20.trace("set", { key, value, hasMetadata: !!metadata });
|
|
3354
3430
|
try {
|
|
3355
3431
|
const db = await this.getDB();
|
|
3356
3432
|
const transaction = db.transaction([this.storeName], "readwrite");
|
|
@@ -3365,7 +3441,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3365
3441
|
return new Promise((resolve, reject) => {
|
|
3366
3442
|
const request = store.put(storedItem, storageKey);
|
|
3367
3443
|
request.onerror = () => {
|
|
3368
|
-
|
|
3444
|
+
logger20.error("Error setting in IndexedDB", { key, value, error: request.error });
|
|
3369
3445
|
reject(request.error);
|
|
3370
3446
|
};
|
|
3371
3447
|
request.onsuccess = () => {
|
|
@@ -3373,7 +3449,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3373
3449
|
};
|
|
3374
3450
|
});
|
|
3375
3451
|
} catch (error) {
|
|
3376
|
-
|
|
3452
|
+
logger20.error("Error in IndexedDB set operation", { key, value, error });
|
|
3377
3453
|
throw new Error(`Failed to store item in IndexedDB: ${error}`);
|
|
3378
3454
|
}
|
|
3379
3455
|
}
|
|
@@ -3381,16 +3457,16 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3381
3457
|
* Update only the metadata for an existing item
|
|
3382
3458
|
*/
|
|
3383
3459
|
async setMetadata(key, metadata) {
|
|
3384
|
-
|
|
3460
|
+
logger20.trace("setMetadata", { key, metadata });
|
|
3385
3461
|
try {
|
|
3386
3462
|
const existing = await this.getWithMetadata(key);
|
|
3387
3463
|
if (existing) {
|
|
3388
3464
|
await this.set(key, existing.value, metadata);
|
|
3389
3465
|
} else {
|
|
3390
|
-
|
|
3466
|
+
logger20.warning("Attempted to set metadata for non-existent item", { key });
|
|
3391
3467
|
}
|
|
3392
3468
|
} catch (error) {
|
|
3393
|
-
|
|
3469
|
+
logger20.error("Error in IndexedDB setMetadata operation", { key, error });
|
|
3394
3470
|
throw new Error(`Failed to update metadata in IndexedDB: ${error}`);
|
|
3395
3471
|
}
|
|
3396
3472
|
}
|
|
@@ -3403,7 +3479,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3403
3479
|
return new Promise((resolve, reject) => {
|
|
3404
3480
|
const request = store.get(storageKey);
|
|
3405
3481
|
request.onerror = () => {
|
|
3406
|
-
|
|
3482
|
+
logger20.error("Error checking key in IndexedDB", { key, error: request.error });
|
|
3407
3483
|
reject(request.error);
|
|
3408
3484
|
};
|
|
3409
3485
|
request.onsuccess = () => {
|
|
@@ -3417,12 +3493,12 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3417
3493
|
};
|
|
3418
3494
|
});
|
|
3419
3495
|
} catch (error) {
|
|
3420
|
-
|
|
3496
|
+
logger20.error("Error in IndexedDB includesKey operation", { key, error });
|
|
3421
3497
|
return false;
|
|
3422
3498
|
}
|
|
3423
3499
|
}
|
|
3424
3500
|
async delete(key) {
|
|
3425
|
-
|
|
3501
|
+
logger20.trace("delete", { key });
|
|
3426
3502
|
try {
|
|
3427
3503
|
const db = await this.getDB();
|
|
3428
3504
|
const transaction = db.transaction([this.storeName], "readwrite");
|
|
@@ -3431,7 +3507,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3431
3507
|
return new Promise((resolve, reject) => {
|
|
3432
3508
|
const request = store.delete(storageKey);
|
|
3433
3509
|
request.onerror = () => {
|
|
3434
|
-
|
|
3510
|
+
logger20.error("Error deleting from IndexedDB", { key, error: request.error });
|
|
3435
3511
|
reject(request.error);
|
|
3436
3512
|
};
|
|
3437
3513
|
request.onsuccess = () => {
|
|
@@ -3439,26 +3515,26 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3439
3515
|
};
|
|
3440
3516
|
});
|
|
3441
3517
|
} catch (error) {
|
|
3442
|
-
|
|
3518
|
+
logger20.error("Error in IndexedDB delete operation", { key, error });
|
|
3443
3519
|
}
|
|
3444
3520
|
}
|
|
3445
3521
|
async allIn(locations) {
|
|
3446
3522
|
const allKeys = await this.keys();
|
|
3447
3523
|
if (locations.length === 0) {
|
|
3448
|
-
|
|
3524
|
+
logger20.debug("Returning all items, LocKeys is empty");
|
|
3449
3525
|
const promises = allKeys.map((key) => this.get(key));
|
|
3450
3526
|
const results = await Promise.all(promises);
|
|
3451
3527
|
return results.filter((item) => item !== null);
|
|
3452
3528
|
} else {
|
|
3453
3529
|
const locKeys = locations;
|
|
3454
|
-
|
|
3530
|
+
logger20.debug("allIn", { locKeys, keys: allKeys.length });
|
|
3455
3531
|
const filteredKeys = allKeys.filter((key) => key && isComKey5(key)).filter((key) => {
|
|
3456
|
-
const
|
|
3457
|
-
|
|
3532
|
+
const ComKey16 = key;
|
|
3533
|
+
logger20.debug("Comparing Location Keys", {
|
|
3458
3534
|
locKeys,
|
|
3459
|
-
ComKey:
|
|
3535
|
+
ComKey: ComKey16
|
|
3460
3536
|
});
|
|
3461
|
-
return isLocKeyArrayEqual(locKeys,
|
|
3537
|
+
return isLocKeyArrayEqual(locKeys, ComKey16.loc);
|
|
3462
3538
|
});
|
|
3463
3539
|
const promises = filteredKeys.map((key) => this.get(key));
|
|
3464
3540
|
const results = await Promise.all(promises);
|
|
@@ -3466,12 +3542,12 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3466
3542
|
}
|
|
3467
3543
|
}
|
|
3468
3544
|
async contains(query, locations) {
|
|
3469
|
-
|
|
3545
|
+
logger20.debug("contains", { query, locations });
|
|
3470
3546
|
const items = await this.allIn(locations);
|
|
3471
3547
|
return items.some((item) => isQueryMatch5(item, query));
|
|
3472
3548
|
}
|
|
3473
3549
|
async queryIn(query, locations = []) {
|
|
3474
|
-
|
|
3550
|
+
logger20.debug("queryIn", { query, locations });
|
|
3475
3551
|
const items = await this.allIn(locations);
|
|
3476
3552
|
return items.filter((item) => isQueryMatch5(item, query));
|
|
3477
3553
|
}
|
|
@@ -3487,7 +3563,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3487
3563
|
return new Promise((resolve, reject) => {
|
|
3488
3564
|
const request = store.openCursor();
|
|
3489
3565
|
request.onerror = () => {
|
|
3490
|
-
|
|
3566
|
+
logger20.error("Error getting keys from IndexedDB", { error: request.error });
|
|
3491
3567
|
reject(request.error);
|
|
3492
3568
|
};
|
|
3493
3569
|
request.onsuccess = (event) => {
|
|
@@ -3502,7 +3578,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3502
3578
|
};
|
|
3503
3579
|
});
|
|
3504
3580
|
} catch (error) {
|
|
3505
|
-
|
|
3581
|
+
logger20.error("Error in IndexedDB keys operation", { error });
|
|
3506
3582
|
return [];
|
|
3507
3583
|
}
|
|
3508
3584
|
}
|
|
@@ -3518,7 +3594,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3518
3594
|
return new Promise((resolve, reject) => {
|
|
3519
3595
|
const request = store.openCursor();
|
|
3520
3596
|
request.onerror = () => {
|
|
3521
|
-
|
|
3597
|
+
logger20.error("Error getting metadata from IndexedDB", { error: request.error });
|
|
3522
3598
|
reject(request.error);
|
|
3523
3599
|
};
|
|
3524
3600
|
request.onsuccess = (event) => {
|
|
@@ -3536,7 +3612,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3536
3612
|
};
|
|
3537
3613
|
});
|
|
3538
3614
|
} catch (error) {
|
|
3539
|
-
|
|
3615
|
+
logger20.error("Error in IndexedDB getAllMetadata operation", { error });
|
|
3540
3616
|
return metadataMap;
|
|
3541
3617
|
}
|
|
3542
3618
|
}
|
|
@@ -3549,7 +3625,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3549
3625
|
return new Promise((resolve, reject) => {
|
|
3550
3626
|
const request = store.openCursor();
|
|
3551
3627
|
request.onerror = () => {
|
|
3552
|
-
|
|
3628
|
+
logger20.error("Error getting values from IndexedDB", { error: request.error });
|
|
3553
3629
|
reject(request.error);
|
|
3554
3630
|
};
|
|
3555
3631
|
request.onsuccess = (event) => {
|
|
@@ -3564,12 +3640,12 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3564
3640
|
};
|
|
3565
3641
|
});
|
|
3566
3642
|
} catch (error) {
|
|
3567
|
-
|
|
3643
|
+
logger20.error("Error in IndexedDB values operation", { error });
|
|
3568
3644
|
return [];
|
|
3569
3645
|
}
|
|
3570
3646
|
}
|
|
3571
3647
|
async clear() {
|
|
3572
|
-
|
|
3648
|
+
logger20.debug("Clearing IndexedDB cache");
|
|
3573
3649
|
try {
|
|
3574
3650
|
const db = await this.getDB();
|
|
3575
3651
|
const transaction = db.transaction([this.storeName], "readwrite");
|
|
@@ -3577,7 +3653,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3577
3653
|
return new Promise((resolve, reject) => {
|
|
3578
3654
|
const request = store.clear();
|
|
3579
3655
|
request.onerror = () => {
|
|
3580
|
-
|
|
3656
|
+
logger20.error("Error clearing IndexedDB cache", { error: request.error });
|
|
3581
3657
|
reject(request.error);
|
|
3582
3658
|
};
|
|
3583
3659
|
request.onsuccess = () => {
|
|
@@ -3585,17 +3661,17 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3585
3661
|
};
|
|
3586
3662
|
});
|
|
3587
3663
|
} catch (error) {
|
|
3588
|
-
|
|
3664
|
+
logger20.error("Error in IndexedDB clear operation", { error });
|
|
3589
3665
|
}
|
|
3590
3666
|
}
|
|
3591
3667
|
// Async Query result caching methods
|
|
3592
3668
|
async setQueryResult(queryHash, itemKeys) {
|
|
3593
|
-
|
|
3669
|
+
logger20.trace("setQueryResult", { queryHash, itemKeys });
|
|
3594
3670
|
try {
|
|
3595
3671
|
return new Promise((resolve, reject) => {
|
|
3596
3672
|
const request = indexedDB.open(this.dbName, this.version);
|
|
3597
3673
|
request.onerror = () => {
|
|
3598
|
-
|
|
3674
|
+
logger20.error("Failed to open database for setQueryResult", { error: request.error });
|
|
3599
3675
|
reject(request.error);
|
|
3600
3676
|
};
|
|
3601
3677
|
request.onsuccess = () => {
|
|
@@ -3608,7 +3684,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3608
3684
|
const queryKey = `query:${queryHash}`;
|
|
3609
3685
|
const putRequest = store.put(safeStringify3(entry), queryKey);
|
|
3610
3686
|
putRequest.onerror = () => {
|
|
3611
|
-
|
|
3687
|
+
logger20.error("Failed to store query result", { queryHash, error: putRequest.error });
|
|
3612
3688
|
reject(putRequest.error);
|
|
3613
3689
|
};
|
|
3614
3690
|
putRequest.onsuccess = () => {
|
|
@@ -3617,17 +3693,17 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3617
3693
|
};
|
|
3618
3694
|
});
|
|
3619
3695
|
} catch (error) {
|
|
3620
|
-
|
|
3696
|
+
logger20.error("Error in setQueryResult", { queryHash, error });
|
|
3621
3697
|
throw error;
|
|
3622
3698
|
}
|
|
3623
3699
|
}
|
|
3624
3700
|
async getQueryResult(queryHash) {
|
|
3625
|
-
|
|
3701
|
+
logger20.trace("getQueryResult", { queryHash });
|
|
3626
3702
|
try {
|
|
3627
3703
|
return new Promise((resolve, reject) => {
|
|
3628
3704
|
const request = indexedDB.open(this.dbName, this.version);
|
|
3629
3705
|
request.onerror = () => {
|
|
3630
|
-
|
|
3706
|
+
logger20.error("Failed to open database for getQueryResult", { error: request.error });
|
|
3631
3707
|
reject(request.error);
|
|
3632
3708
|
};
|
|
3633
3709
|
request.onsuccess = () => {
|
|
@@ -3637,7 +3713,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3637
3713
|
const queryKey = `query:${queryHash}`;
|
|
3638
3714
|
const getRequest = store.get(queryKey);
|
|
3639
3715
|
getRequest.onerror = () => {
|
|
3640
|
-
|
|
3716
|
+
logger20.error("Failed to retrieve query result", { queryHash, error: getRequest.error });
|
|
3641
3717
|
reject(getRequest.error);
|
|
3642
3718
|
};
|
|
3643
3719
|
getRequest.onsuccess = () => {
|
|
@@ -3654,34 +3730,34 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3654
3730
|
}
|
|
3655
3731
|
resolve(entry.itemKeys || null);
|
|
3656
3732
|
} catch (parseError) {
|
|
3657
|
-
|
|
3733
|
+
logger20.error("Failed to parse query result", { queryHash, error: parseError });
|
|
3658
3734
|
resolve(null);
|
|
3659
3735
|
}
|
|
3660
3736
|
};
|
|
3661
3737
|
};
|
|
3662
3738
|
});
|
|
3663
3739
|
} catch (error) {
|
|
3664
|
-
|
|
3740
|
+
logger20.error("Error in getQueryResult", { queryHash, error });
|
|
3665
3741
|
return null;
|
|
3666
3742
|
}
|
|
3667
3743
|
}
|
|
3668
3744
|
async hasQueryResult(queryHash) {
|
|
3669
|
-
|
|
3745
|
+
logger20.trace("hasQueryResult", { queryHash });
|
|
3670
3746
|
try {
|
|
3671
3747
|
const result = await this.getQueryResult(queryHash);
|
|
3672
3748
|
return result !== null;
|
|
3673
3749
|
} catch (error) {
|
|
3674
|
-
|
|
3750
|
+
logger20.error("Error in hasQueryResult", { queryHash, error });
|
|
3675
3751
|
return false;
|
|
3676
3752
|
}
|
|
3677
3753
|
}
|
|
3678
3754
|
async deleteQueryResult(queryHash) {
|
|
3679
|
-
|
|
3755
|
+
logger20.trace("deleteQueryResult", { queryHash });
|
|
3680
3756
|
try {
|
|
3681
3757
|
return new Promise((resolve, reject) => {
|
|
3682
3758
|
const request = indexedDB.open(this.dbName, this.version);
|
|
3683
3759
|
request.onerror = () => {
|
|
3684
|
-
|
|
3760
|
+
logger20.error("Failed to open database for deleteQueryResult", { error: request.error });
|
|
3685
3761
|
reject(request.error);
|
|
3686
3762
|
};
|
|
3687
3763
|
request.onsuccess = () => {
|
|
@@ -3691,7 +3767,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3691
3767
|
const queryKey = `query:${queryHash}`;
|
|
3692
3768
|
const deleteRequest = store.delete(queryKey);
|
|
3693
3769
|
deleteRequest.onerror = () => {
|
|
3694
|
-
|
|
3770
|
+
logger20.error("Failed to delete query result", { queryHash, error: deleteRequest.error });
|
|
3695
3771
|
reject(deleteRequest.error);
|
|
3696
3772
|
};
|
|
3697
3773
|
deleteRequest.onsuccess = () => {
|
|
@@ -3700,12 +3776,12 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3700
3776
|
};
|
|
3701
3777
|
});
|
|
3702
3778
|
} catch (error) {
|
|
3703
|
-
|
|
3779
|
+
logger20.error("Error in deleteQueryResult", { queryHash, error });
|
|
3704
3780
|
throw error;
|
|
3705
3781
|
}
|
|
3706
3782
|
}
|
|
3707
3783
|
async invalidateItemKeys(keys) {
|
|
3708
|
-
|
|
3784
|
+
logger20.debug("invalidateItemKeys", { keys });
|
|
3709
3785
|
if (keys.length === 0) {
|
|
3710
3786
|
return;
|
|
3711
3787
|
}
|
|
@@ -3742,7 +3818,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3742
3818
|
queryResults2[queryHash] = itemKeys;
|
|
3743
3819
|
}
|
|
3744
3820
|
} catch (error) {
|
|
3745
|
-
|
|
3821
|
+
logger20.debug("Failed to parse query result", { key: item.key, error });
|
|
3746
3822
|
}
|
|
3747
3823
|
}
|
|
3748
3824
|
}
|
|
@@ -3770,18 +3846,18 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3770
3846
|
});
|
|
3771
3847
|
}
|
|
3772
3848
|
}
|
|
3773
|
-
|
|
3849
|
+
logger20.debug("Selectively invalidated queries referencing affected keys", {
|
|
3774
3850
|
affectedKeys: keys.length,
|
|
3775
3851
|
queriesRemoved: queriesToRemove.length,
|
|
3776
3852
|
totalQueries: Object.keys(queryResults).length
|
|
3777
3853
|
});
|
|
3778
3854
|
} catch (error) {
|
|
3779
|
-
|
|
3855
|
+
logger20.error("Error during selective query invalidation, falling back to clearing all queries", { error });
|
|
3780
3856
|
await this.clearQueryResults();
|
|
3781
3857
|
}
|
|
3782
3858
|
}
|
|
3783
3859
|
async invalidateLocation(locations) {
|
|
3784
|
-
|
|
3860
|
+
logger20.debug("invalidateLocation", { locations });
|
|
3785
3861
|
let keysToInvalidate = [];
|
|
3786
3862
|
if (locations.length === 0) {
|
|
3787
3863
|
await this.clearQueryResults();
|
|
@@ -3794,12 +3870,12 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3794
3870
|
}
|
|
3795
3871
|
}
|
|
3796
3872
|
async clearQueryResults() {
|
|
3797
|
-
|
|
3873
|
+
logger20.trace("clearQueryResults");
|
|
3798
3874
|
try {
|
|
3799
3875
|
return new Promise((resolve, reject) => {
|
|
3800
3876
|
const request = indexedDB.open(this.dbName, this.version);
|
|
3801
3877
|
request.onerror = () => {
|
|
3802
|
-
|
|
3878
|
+
logger20.error("Failed to open database for clearQueryResults", { error: request.error });
|
|
3803
3879
|
reject(request.error);
|
|
3804
3880
|
};
|
|
3805
3881
|
request.onsuccess = () => {
|
|
@@ -3809,7 +3885,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3809
3885
|
const cursorRequest = store.openCursor();
|
|
3810
3886
|
const keysToDelete = [];
|
|
3811
3887
|
cursorRequest.onerror = () => {
|
|
3812
|
-
|
|
3888
|
+
logger20.error("Failed to open cursor for clearQueryResults", { error: cursorRequest.error });
|
|
3813
3889
|
reject(cursorRequest.error);
|
|
3814
3890
|
};
|
|
3815
3891
|
cursorRequest.onsuccess = () => {
|
|
@@ -3830,7 +3906,7 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3830
3906
|
keysToDelete.forEach((queryKey) => {
|
|
3831
3907
|
const deleteRequest = store.delete(queryKey);
|
|
3832
3908
|
deleteRequest.onerror = () => {
|
|
3833
|
-
|
|
3909
|
+
logger20.error("Failed to delete query key", { queryKey, error: deleteRequest.error });
|
|
3834
3910
|
deletedCount++;
|
|
3835
3911
|
if (deletedCount === totalToDelete) {
|
|
3836
3912
|
resolve();
|
|
@@ -3848,14 +3924,14 @@ var AsyncIndexDBCacheMap = class _AsyncIndexDBCacheMap {
|
|
|
3848
3924
|
};
|
|
3849
3925
|
});
|
|
3850
3926
|
} catch (error) {
|
|
3851
|
-
|
|
3927
|
+
logger20.error("Error in clearQueryResults", { error });
|
|
3852
3928
|
throw error;
|
|
3853
3929
|
}
|
|
3854
3930
|
}
|
|
3855
3931
|
};
|
|
3856
3932
|
|
|
3857
3933
|
// src/browser/IndexDBCacheMap.ts
|
|
3858
|
-
var
|
|
3934
|
+
var logger21 = logger_default.get("IndexDBCacheMap");
|
|
3859
3935
|
var IndexDBCacheMap = class _IndexDBCacheMap extends CacheMap {
|
|
3860
3936
|
implementationType = "browser/indexedDB";
|
|
3861
3937
|
// Memory storage
|
|
@@ -4039,7 +4115,7 @@ var IndexDBCacheMap = class _IndexDBCacheMap extends CacheMap {
|
|
|
4039
4115
|
}
|
|
4040
4116
|
// Invalidation methods
|
|
4041
4117
|
async invalidateItemKeys(keys) {
|
|
4042
|
-
|
|
4118
|
+
logger21.debug("invalidateItemKeys", { keys });
|
|
4043
4119
|
if (keys.length === 0) {
|
|
4044
4120
|
return;
|
|
4045
4121
|
}
|
|
@@ -4069,7 +4145,7 @@ var IndexDBCacheMap = class _IndexDBCacheMap extends CacheMap {
|
|
|
4069
4145
|
queriesToRemove.forEach((queryHash) => {
|
|
4070
4146
|
delete this.queryResultCache[queryHash];
|
|
4071
4147
|
});
|
|
4072
|
-
|
|
4148
|
+
logger21.debug("Selectively invalidated queries referencing affected keys", {
|
|
4073
4149
|
affectedKeys: keys.length,
|
|
4074
4150
|
queriesRemoved: queriesToRemove.length,
|
|
4075
4151
|
totalQueries: Object.keys(this.queryResultCache).length
|
|
@@ -4456,11 +4532,22 @@ var createOperations = (api, coordinate, cacheMap, pkType, options, eventEmitter
|
|
|
4456
4532
|
return {
|
|
4457
4533
|
all: (query, locations) => all(query, locations, context).then(([ctx, result]) => result),
|
|
4458
4534
|
one: (query, locations) => one(query, locations, context).then(([ctx, result]) => result),
|
|
4459
|
-
create: (item,
|
|
4535
|
+
create: (item, options2) => {
|
|
4536
|
+
const locations = options2?.locations || [];
|
|
4537
|
+
return create(item, locations, context).then(([ctx, result]) => result);
|
|
4538
|
+
},
|
|
4460
4539
|
get: (key) => get(key, context).then(([ctx, result]) => result),
|
|
4461
4540
|
retrieve: (key) => retrieve(key, context).then(([ctx, result]) => result),
|
|
4462
4541
|
remove: (key) => remove(key, context).then((ctx) => void 0),
|
|
4463
4542
|
update: (key, item) => update(key, item, context).then(([ctx, result]) => result),
|
|
4543
|
+
upsert: async (key, itemProperties, locations) => {
|
|
4544
|
+
const existing = await get(key, context).then(([ctx, result]) => result);
|
|
4545
|
+
if (existing) {
|
|
4546
|
+
return update(key, itemProperties, context).then(([ctx, result]) => result);
|
|
4547
|
+
} else {
|
|
4548
|
+
return create(itemProperties, locations || [], context).then(([ctx, result]) => result);
|
|
4549
|
+
}
|
|
4550
|
+
},
|
|
4464
4551
|
action: (key, actionName, body) => action(key, actionName, body, context).then(([ctx, result, affectedItems]) => [result, affectedItems]),
|
|
4465
4552
|
allAction: (actionName, body, locations) => allAction(actionName, body, locations, context).then(([ctx, result, affectedItems]) => [result, affectedItems]),
|
|
4466
4553
|
facet: (key, facetName, params) => facet(key, facetName, params, context).then((result) => result),
|
|
@@ -4473,7 +4560,7 @@ var createOperations = (api, coordinate, cacheMap, pkType, options, eventEmitter
|
|
|
4473
4560
|
};
|
|
4474
4561
|
|
|
4475
4562
|
// src/eviction/EvictionManager.ts
|
|
4476
|
-
var
|
|
4563
|
+
var logger22 = logger_default.get("EvictionManager");
|
|
4477
4564
|
var EvictionManager = class {
|
|
4478
4565
|
evictionStrategy;
|
|
4479
4566
|
constructor(evictionStrategy) {
|
|
@@ -4485,7 +4572,7 @@ var EvictionManager = class {
|
|
|
4485
4572
|
*/
|
|
4486
4573
|
setEvictionStrategy(strategy) {
|
|
4487
4574
|
this.evictionStrategy = strategy;
|
|
4488
|
-
|
|
4575
|
+
logger22.debug("Eviction strategy updated", {
|
|
4489
4576
|
strategy: strategy?.getStrategyName() || "none"
|
|
4490
4577
|
});
|
|
4491
4578
|
}
|
|
@@ -4508,7 +4595,7 @@ var EvictionManager = class {
|
|
|
4508
4595
|
try {
|
|
4509
4596
|
await this.evictionStrategy.onItemAccessed(key, metadataProvider);
|
|
4510
4597
|
} catch (error) {
|
|
4511
|
-
|
|
4598
|
+
logger22.error("Error in eviction strategy onItemAccessed", { key, error });
|
|
4512
4599
|
}
|
|
4513
4600
|
}
|
|
4514
4601
|
/**
|
|
@@ -4533,14 +4620,14 @@ var EvictionManager = class {
|
|
|
4533
4620
|
}
|
|
4534
4621
|
await this.evictionStrategy.onItemAdded(key, estimatedSize, metadataProvider);
|
|
4535
4622
|
if (evictedKeys.length > 0) {
|
|
4536
|
-
|
|
4623
|
+
logger22.debug("Items evicted during addition", {
|
|
4537
4624
|
newKey: key,
|
|
4538
4625
|
evictedKeys,
|
|
4539
4626
|
strategy: this.evictionStrategy.getStrategyName()
|
|
4540
4627
|
});
|
|
4541
4628
|
}
|
|
4542
4629
|
} catch (error) {
|
|
4543
|
-
|
|
4630
|
+
logger22.error("Error in eviction strategy onItemAdded", { key, error });
|
|
4544
4631
|
}
|
|
4545
4632
|
return evictedKeys;
|
|
4546
4633
|
}
|
|
@@ -4556,7 +4643,7 @@ var EvictionManager = class {
|
|
|
4556
4643
|
try {
|
|
4557
4644
|
this.evictionStrategy.onItemRemoved(key, metadataProvider);
|
|
4558
4645
|
} catch (error) {
|
|
4559
|
-
|
|
4646
|
+
logger22.error("Error in eviction strategy onItemRemoved", { key, error });
|
|
4560
4647
|
}
|
|
4561
4648
|
}
|
|
4562
4649
|
/**
|
|
@@ -4577,13 +4664,13 @@ var EvictionManager = class {
|
|
|
4577
4664
|
evictedKeys.push(evictKey);
|
|
4578
4665
|
}
|
|
4579
4666
|
if (evictedKeys.length > 0) {
|
|
4580
|
-
|
|
4667
|
+
logger22.debug("Manual eviction performed", {
|
|
4581
4668
|
evictedKeys,
|
|
4582
4669
|
strategy: this.evictionStrategy.getStrategyName()
|
|
4583
4670
|
});
|
|
4584
4671
|
}
|
|
4585
4672
|
} catch (error) {
|
|
4586
|
-
|
|
4673
|
+
logger22.error("Error in manual eviction", { error });
|
|
4587
4674
|
}
|
|
4588
4675
|
return evictedKeys;
|
|
4589
4676
|
}
|
|
@@ -4603,7 +4690,7 @@ var EvictionManager = class {
|
|
|
4603
4690
|
this.evictionStrategy.reset();
|
|
4604
4691
|
}
|
|
4605
4692
|
}
|
|
4606
|
-
|
|
4693
|
+
logger22.debug("Eviction manager cleared");
|
|
4607
4694
|
}
|
|
4608
4695
|
/**
|
|
4609
4696
|
* Create eviction context from current cache state
|
|
@@ -5941,7 +6028,7 @@ function createEvictionStrategy(policy, maxCacheSize, config) {
|
|
|
5941
6028
|
}
|
|
5942
6029
|
|
|
5943
6030
|
// src/ttl/TTLManager.ts
|
|
5944
|
-
var
|
|
6031
|
+
var logger23 = logger_default.get("TTLManager");
|
|
5945
6032
|
var TTLManager = class {
|
|
5946
6033
|
config;
|
|
5947
6034
|
cleanupTimer;
|
|
@@ -5953,7 +6040,7 @@ var TTLManager = class {
|
|
|
5953
6040
|
validateOnAccess: true,
|
|
5954
6041
|
...config
|
|
5955
6042
|
};
|
|
5956
|
-
|
|
6043
|
+
logger23.debug("TTL_DEBUG: TTLManager created", {
|
|
5957
6044
|
config: this.config,
|
|
5958
6045
|
isTTLEnabled: this.isTTLEnabled(),
|
|
5959
6046
|
defaultTTL: this.config.defaultTTL
|
|
@@ -5986,13 +6073,13 @@ var TTLManager = class {
|
|
|
5986
6073
|
this.startAutoCleanup();
|
|
5987
6074
|
}
|
|
5988
6075
|
}
|
|
5989
|
-
|
|
6076
|
+
logger23.debug("TTL configuration updated", { config: this.config });
|
|
5990
6077
|
}
|
|
5991
6078
|
/**
|
|
5992
6079
|
* Set TTL metadata for an item when it's added
|
|
5993
6080
|
*/
|
|
5994
6081
|
async onItemAdded(key, metadataProvider, itemTTL) {
|
|
5995
|
-
|
|
6082
|
+
logger23.debug("TTL_DEBUG: onItemAdded called", {
|
|
5996
6083
|
key,
|
|
5997
6084
|
itemTTL,
|
|
5998
6085
|
isTTLEnabled: this.isTTLEnabled(),
|
|
@@ -6000,19 +6087,19 @@ var TTLManager = class {
|
|
|
6000
6087
|
metadataProviderType: metadataProvider?.constructor?.name
|
|
6001
6088
|
});
|
|
6002
6089
|
if (!this.isTTLEnabled() && !itemTTL) {
|
|
6003
|
-
|
|
6090
|
+
logger23.debug("TTL_DEBUG: No TTL configured for item - returning early", { key });
|
|
6004
6091
|
return;
|
|
6005
6092
|
}
|
|
6006
|
-
|
|
6093
|
+
logger23.debug("TTL_DEBUG: Getting metadata for key", { key });
|
|
6007
6094
|
const metadata = await metadataProvider.getMetadata(key);
|
|
6008
|
-
|
|
6095
|
+
logger23.debug("TTL_DEBUG: Retrieved metadata", {
|
|
6009
6096
|
key,
|
|
6010
6097
|
hasMetadata: !!metadata,
|
|
6011
6098
|
metadataKeys: metadata ? Object.keys(metadata) : null,
|
|
6012
6099
|
metadata
|
|
6013
6100
|
});
|
|
6014
6101
|
if (!metadata) {
|
|
6015
|
-
|
|
6102
|
+
logger23.warning("TTL_DEBUG: No metadata found for item when setting TTL", {
|
|
6016
6103
|
key,
|
|
6017
6104
|
metadataProviderType: metadataProvider?.constructor?.name,
|
|
6018
6105
|
metadataProviderMethods: metadataProvider ? Object.getOwnPropertyNames(Object.getPrototypeOf(metadataProvider)) : null
|
|
@@ -6020,7 +6107,7 @@ var TTLManager = class {
|
|
|
6020
6107
|
return;
|
|
6021
6108
|
}
|
|
6022
6109
|
const ttl = itemTTL || this.config.defaultTTL;
|
|
6023
|
-
|
|
6110
|
+
logger23.debug("TTL_DEBUG: Calculated TTL value", {
|
|
6024
6111
|
key,
|
|
6025
6112
|
itemTTL,
|
|
6026
6113
|
defaultTTL: this.config.defaultTTL,
|
|
@@ -6033,7 +6120,7 @@ var TTLManager = class {
|
|
|
6033
6120
|
expiresAt: metadata.addedAt + ttl,
|
|
6034
6121
|
ttl
|
|
6035
6122
|
};
|
|
6036
|
-
|
|
6123
|
+
logger23.debug("TTL_DEBUG: Setting TTL metadata", {
|
|
6037
6124
|
key,
|
|
6038
6125
|
ttl,
|
|
6039
6126
|
addedAt: metadata.addedAt,
|
|
@@ -6041,9 +6128,9 @@ var TTLManager = class {
|
|
|
6041
6128
|
ttlMetadata
|
|
6042
6129
|
});
|
|
6043
6130
|
await metadataProvider.setMetadata(key, ttlMetadata);
|
|
6044
|
-
|
|
6131
|
+
logger23.trace("TTL_DEBUG: TTL set for item", { key, ttl, expiresAt: ttlMetadata.expiresAt });
|
|
6045
6132
|
} else {
|
|
6046
|
-
|
|
6133
|
+
logger23.debug("TTL_DEBUG: No TTL set - invalid TTL value", { key, ttl });
|
|
6047
6134
|
}
|
|
6048
6135
|
}
|
|
6049
6136
|
/**
|
|
@@ -6057,7 +6144,7 @@ var TTLManager = class {
|
|
|
6057
6144
|
const now = Date.now();
|
|
6058
6145
|
const expired = now >= metadata.expiresAt;
|
|
6059
6146
|
if (expired) {
|
|
6060
|
-
|
|
6147
|
+
logger23.trace("Item expired", { key, expiresAt: metadata.expiresAt, now });
|
|
6061
6148
|
}
|
|
6062
6149
|
return expired;
|
|
6063
6150
|
}
|
|
@@ -6104,7 +6191,7 @@ var TTLManager = class {
|
|
|
6104
6191
|
}
|
|
6105
6192
|
}
|
|
6106
6193
|
if (expiredKeys.length > 0) {
|
|
6107
|
-
|
|
6194
|
+
logger23.debug("Found expired items", { count: expiredKeys.length, keys: expiredKeys });
|
|
6108
6195
|
}
|
|
6109
6196
|
return expiredKeys;
|
|
6110
6197
|
}
|
|
@@ -6132,7 +6219,7 @@ var TTLManager = class {
|
|
|
6132
6219
|
}
|
|
6133
6220
|
metadata.expiresAt += additionalTTL;
|
|
6134
6221
|
await metadataProvider.setMetadata(key, metadata);
|
|
6135
|
-
|
|
6222
|
+
logger23.trace("TTL extended for item", { key, additionalTTL, newExpiresAt: metadata.expiresAt });
|
|
6136
6223
|
return true;
|
|
6137
6224
|
}
|
|
6138
6225
|
/**
|
|
@@ -6154,7 +6241,7 @@ var TTLManager = class {
|
|
|
6154
6241
|
ttl
|
|
6155
6242
|
};
|
|
6156
6243
|
await metadataProvider.setMetadata(key, ttlMetadata);
|
|
6157
|
-
|
|
6244
|
+
logger23.trace("TTL refreshed for item", { key, ttl, expiresAt: ttlMetadata.expiresAt });
|
|
6158
6245
|
return true;
|
|
6159
6246
|
}
|
|
6160
6247
|
/**
|
|
@@ -6166,9 +6253,9 @@ var TTLManager = class {
|
|
|
6166
6253
|
}
|
|
6167
6254
|
if (this.config.cleanupInterval) {
|
|
6168
6255
|
this.cleanupTimer = setInterval(() => {
|
|
6169
|
-
|
|
6256
|
+
logger23.trace("Auto cleanup timer triggered");
|
|
6170
6257
|
}, this.config.cleanupInterval);
|
|
6171
|
-
|
|
6258
|
+
logger23.debug("Auto cleanup started", { interval: this.config.cleanupInterval });
|
|
6172
6259
|
}
|
|
6173
6260
|
}
|
|
6174
6261
|
/**
|
|
@@ -6178,7 +6265,7 @@ var TTLManager = class {
|
|
|
6178
6265
|
if (this.cleanupTimer) {
|
|
6179
6266
|
clearInterval(this.cleanupTimer);
|
|
6180
6267
|
this.cleanupTimer = null;
|
|
6181
|
-
|
|
6268
|
+
logger23.debug("Auto cleanup stopped");
|
|
6182
6269
|
}
|
|
6183
6270
|
}
|
|
6184
6271
|
/**
|
|
@@ -6186,14 +6273,14 @@ var TTLManager = class {
|
|
|
6186
6273
|
*/
|
|
6187
6274
|
clear() {
|
|
6188
6275
|
this.stopAutoCleanup();
|
|
6189
|
-
|
|
6276
|
+
logger23.debug("TTL manager cleared");
|
|
6190
6277
|
}
|
|
6191
6278
|
/**
|
|
6192
6279
|
* Cleanup resources
|
|
6193
6280
|
*/
|
|
6194
6281
|
destroy() {
|
|
6195
6282
|
this.stopAutoCleanup();
|
|
6196
|
-
|
|
6283
|
+
logger23.debug("TTL manager destroyed");
|
|
6197
6284
|
}
|
|
6198
6285
|
};
|
|
6199
6286
|
|
|
@@ -6593,9 +6680,9 @@ var CacheStatsManager = class {
|
|
|
6593
6680
|
};
|
|
6594
6681
|
|
|
6595
6682
|
// src/Cache.ts
|
|
6596
|
-
var
|
|
6683
|
+
var logger24 = logger_default.get("Cache");
|
|
6597
6684
|
var createCache = (api, coordinate, registry, options) => {
|
|
6598
|
-
|
|
6685
|
+
logger24.debug("createCache", { coordinate, registry, options });
|
|
6599
6686
|
const completeOptions = createOptions(options);
|
|
6600
6687
|
const cacheMap = createCacheMap(coordinate.kta, completeOptions);
|
|
6601
6688
|
const pkType = coordinate.kta[0];
|
|
@@ -6675,13 +6762,13 @@ var isCache2 = (cache) => {
|
|
|
6675
6762
|
};
|
|
6676
6763
|
|
|
6677
6764
|
// src/InstanceFactory.ts
|
|
6678
|
-
var
|
|
6765
|
+
var logger25 = logger_default.get("InstanceFactory");
|
|
6679
6766
|
var createInstanceFactory = (api, options) => {
|
|
6680
6767
|
const templateOptions = createOptions(options);
|
|
6681
6768
|
validateOptions(templateOptions);
|
|
6682
6769
|
return (coordinate, context) => {
|
|
6683
6770
|
const instanceOptions = createOptions(options);
|
|
6684
|
-
|
|
6771
|
+
logger25.debug("Creating cache instance", {
|
|
6685
6772
|
coordinate,
|
|
6686
6773
|
registry: context.registry,
|
|
6687
6774
|
api,
|
|
@@ -6748,9 +6835,9 @@ var createInstanceFactory = (api, options) => {
|
|
|
6748
6835
|
};
|
|
6749
6836
|
|
|
6750
6837
|
// src/Instance.ts
|
|
6751
|
-
var
|
|
6838
|
+
var logger26 = logger_default.get("Instance");
|
|
6752
6839
|
var createInstance = (registry, coordinate, api, options) => {
|
|
6753
|
-
|
|
6840
|
+
logger26.debug("createInstance", { coordinate, api, registry, options });
|
|
6754
6841
|
return createCache(api, coordinate, registry, options);
|
|
6755
6842
|
};
|
|
6756
6843
|
var isInstance = (instance) => {
|
|
@@ -6758,7 +6845,7 @@ var isInstance = (instance) => {
|
|
|
6758
6845
|
};
|
|
6759
6846
|
|
|
6760
6847
|
// src/Aggregator.ts
|
|
6761
|
-
var
|
|
6848
|
+
var logger27 = logger_default.get("ItemAggregator");
|
|
6762
6849
|
var toCacheConfig = (config) => {
|
|
6763
6850
|
let cacheConfig;
|
|
6764
6851
|
if (config.optional === void 0) {
|
|
@@ -6770,22 +6857,22 @@ var toCacheConfig = (config) => {
|
|
|
6770
6857
|
};
|
|
6771
6858
|
var createAggregator = async (cache, { aggregates = {}, events = {} }) => {
|
|
6772
6859
|
const populate = async (item) => {
|
|
6773
|
-
|
|
6860
|
+
logger27.default("populate", { item });
|
|
6774
6861
|
for (const key in aggregates) {
|
|
6775
6862
|
await populateAggregate(key, item);
|
|
6776
6863
|
}
|
|
6777
6864
|
for (const key in events) {
|
|
6778
6865
|
await populateEvent(key, item);
|
|
6779
6866
|
}
|
|
6780
|
-
|
|
6867
|
+
logger27.default("populate done", { item });
|
|
6781
6868
|
return item;
|
|
6782
6869
|
};
|
|
6783
6870
|
const populateAggregate = async (key, item) => {
|
|
6784
|
-
|
|
6871
|
+
logger27.default("populate aggregate key", { key });
|
|
6785
6872
|
const cacheConfig = toCacheConfig(aggregates[key]);
|
|
6786
6873
|
if (item.refs === void 0) {
|
|
6787
6874
|
if (cacheConfig.optional === false) {
|
|
6788
|
-
|
|
6875
|
+
logger27.error("Item does not have refs an is not optional ", { item });
|
|
6789
6876
|
throw new Error("Item does not have refs an is not optional " + JSON.stringify(item));
|
|
6790
6877
|
} else {
|
|
6791
6878
|
if (item.events && Object.prototype.hasOwnProperty.call(item.events, key)) {
|
|
@@ -6794,7 +6881,7 @@ var createAggregator = async (cache, { aggregates = {}, events = {} }) => {
|
|
|
6794
6881
|
}
|
|
6795
6882
|
} else if (item.refs[key] === void 0) {
|
|
6796
6883
|
if (cacheConfig.optional === false) {
|
|
6797
|
-
|
|
6884
|
+
logger27.error("Item does not have mandatory ref with key, not optional ", { key, item });
|
|
6798
6885
|
throw new Error("Item does not have mandatory ref with key, not optional " + key + " " + JSON.stringify(item));
|
|
6799
6886
|
} else {
|
|
6800
6887
|
if (item.events && Object.prototype.hasOwnProperty.call(item.events, key)) {
|
|
@@ -6803,7 +6890,7 @@ var createAggregator = async (cache, { aggregates = {}, events = {} }) => {
|
|
|
6803
6890
|
}
|
|
6804
6891
|
} else {
|
|
6805
6892
|
const ref = item.refs[key];
|
|
6806
|
-
|
|
6893
|
+
logger27.default("AGG Retrieving Item in Populate", { key: ref });
|
|
6807
6894
|
const newItem = await cacheConfig.cache.operations.retrieve(ref);
|
|
6808
6895
|
if (newItem) {
|
|
6809
6896
|
if (item.aggs === void 0) {
|
|
@@ -6820,25 +6907,25 @@ var createAggregator = async (cache, { aggregates = {}, events = {} }) => {
|
|
|
6820
6907
|
}
|
|
6821
6908
|
};
|
|
6822
6909
|
const populateEvent = async (key, item) => {
|
|
6823
|
-
|
|
6910
|
+
logger27.default("populate event key", { key });
|
|
6824
6911
|
const cacheConfig = toCacheConfig(events[key]);
|
|
6825
6912
|
if (item.events === void 0) {
|
|
6826
6913
|
throw new Error("Item does not have events " + JSON.stringify(item));
|
|
6827
6914
|
} else if (item.events[key] === void 0) {
|
|
6828
6915
|
if (cacheConfig.optional === false) {
|
|
6829
|
-
|
|
6916
|
+
logger27.error("Item does not have mandatory event with key", { key, item });
|
|
6830
6917
|
throw new Error("Item does not have mandatory event with key " + key + " " + JSON.stringify(item));
|
|
6831
6918
|
}
|
|
6832
6919
|
} else {
|
|
6833
6920
|
const event = item.events[key];
|
|
6834
6921
|
if (event.by === void 0) {
|
|
6835
|
-
|
|
6922
|
+
logger27.error(
|
|
6836
6923
|
"populateEvent with an Event that does not have by",
|
|
6837
6924
|
{ event, ik: item.key, eventKey: key }
|
|
6838
6925
|
);
|
|
6839
6926
|
throw new Error("populateEvent with an Event that does not have by: " + JSON.stringify({ key }));
|
|
6840
6927
|
}
|
|
6841
|
-
|
|
6928
|
+
logger27.default("EVENT Retrieving Item in Populate", { key: event.by });
|
|
6842
6929
|
const newItem = await cacheConfig.cache.operations.retrieve(event.by);
|
|
6843
6930
|
if (newItem) {
|
|
6844
6931
|
event.agg = newItem;
|
|
@@ -6846,13 +6933,13 @@ var createAggregator = async (cache, { aggregates = {}, events = {} }) => {
|
|
|
6846
6933
|
}
|
|
6847
6934
|
};
|
|
6848
6935
|
const all2 = async (query = {}, locations = []) => {
|
|
6849
|
-
|
|
6936
|
+
logger27.default("all", { query, locations });
|
|
6850
6937
|
const items = await cache.operations.all(query, locations);
|
|
6851
6938
|
const populatedItems = await Promise.all(items.map(async (item) => populate(item)));
|
|
6852
6939
|
return populatedItems;
|
|
6853
6940
|
};
|
|
6854
6941
|
const one2 = async (query = {}, locations = []) => {
|
|
6855
|
-
|
|
6942
|
+
logger27.default("one", { query, locations });
|
|
6856
6943
|
const item = await cache.operations.one(query, locations);
|
|
6857
6944
|
let populatedItem = null;
|
|
6858
6945
|
if (item) {
|
|
@@ -6861,30 +6948,30 @@ var createAggregator = async (cache, { aggregates = {}, events = {} }) => {
|
|
|
6861
6948
|
return populatedItem;
|
|
6862
6949
|
};
|
|
6863
6950
|
const action2 = async (key, action3, body = {}) => {
|
|
6864
|
-
|
|
6951
|
+
logger27.default("action", { key, action: action3, body });
|
|
6865
6952
|
const [item, affectedItems] = await cache.operations.action(key, action3, body);
|
|
6866
6953
|
const populatedItem = await populate(item);
|
|
6867
6954
|
return [populatedItem, affectedItems];
|
|
6868
6955
|
};
|
|
6869
6956
|
const allAction2 = async (action3, body = {}, locations = []) => {
|
|
6870
|
-
|
|
6957
|
+
logger27.default("action", { action: action3, body, locations });
|
|
6871
6958
|
const [items, affectedItems] = await cache.operations.allAction(action3, body, locations);
|
|
6872
6959
|
const populatedItems = await Promise.all(items.map(async (item) => populate(item)));
|
|
6873
6960
|
return [populatedItems, affectedItems];
|
|
6874
6961
|
};
|
|
6875
6962
|
const allFacet2 = async (facet3, params = {}, locations = []) => {
|
|
6876
|
-
|
|
6963
|
+
logger27.default("allFacet", { facet: facet3, params, locations });
|
|
6877
6964
|
const response = await cache.operations.allFacet(facet3, params, locations);
|
|
6878
6965
|
return response;
|
|
6879
6966
|
};
|
|
6880
6967
|
const create2 = async (v, locations = []) => {
|
|
6881
|
-
|
|
6882
|
-
const item = await cache.operations.create(v, locations);
|
|
6968
|
+
logger27.default("create", { v, locations });
|
|
6969
|
+
const item = locations.length === 0 ? await cache.operations.create(v) : await cache.operations.create(v, { locations });
|
|
6883
6970
|
const populatedItem = await populate(item);
|
|
6884
6971
|
return populatedItem;
|
|
6885
6972
|
};
|
|
6886
6973
|
const get2 = async (key) => {
|
|
6887
|
-
|
|
6974
|
+
logger27.default("get", { key });
|
|
6888
6975
|
const item = await cache.operations.get(key);
|
|
6889
6976
|
let populatedItem = null;
|
|
6890
6977
|
if (item) {
|
|
@@ -6893,7 +6980,7 @@ var createAggregator = async (cache, { aggregates = {}, events = {} }) => {
|
|
|
6893
6980
|
return populatedItem;
|
|
6894
6981
|
};
|
|
6895
6982
|
const retrieve2 = async (key) => {
|
|
6896
|
-
|
|
6983
|
+
logger27.default("retrieve", { key });
|
|
6897
6984
|
const item = await cache.operations.retrieve(key);
|
|
6898
6985
|
let populatedItem = null;
|
|
6899
6986
|
if (item) {
|
|
@@ -6902,34 +6989,37 @@ var createAggregator = async (cache, { aggregates = {}, events = {} }) => {
|
|
|
6902
6989
|
return populatedItem;
|
|
6903
6990
|
};
|
|
6904
6991
|
const remove2 = async (key) => {
|
|
6905
|
-
|
|
6992
|
+
logger27.default("remove", { key });
|
|
6906
6993
|
await cache.operations.remove(key);
|
|
6907
6994
|
};
|
|
6908
6995
|
const update2 = async (key, v) => {
|
|
6909
|
-
|
|
6996
|
+
logger27.default("update", { key, v });
|
|
6910
6997
|
const item = await cache.operations.update(key, v);
|
|
6911
6998
|
const populatedItem = await populate(item);
|
|
6912
6999
|
return populatedItem;
|
|
6913
7000
|
};
|
|
6914
7001
|
const facet2 = async (key, facet3) => {
|
|
6915
|
-
|
|
7002
|
+
logger27.default("facet", { key, facet: facet3 });
|
|
6916
7003
|
const response = await cache.operations.facet(key, facet3);
|
|
6917
7004
|
return response;
|
|
6918
7005
|
};
|
|
6919
7006
|
const find2 = async (finder, finderParams = {}, locations = []) => {
|
|
6920
|
-
|
|
7007
|
+
logger27.default("find", { finder, finderParams, locations });
|
|
6921
7008
|
const items = await cache.operations.find(finder, finderParams, locations);
|
|
6922
7009
|
const populatedItems = await Promise.all(items.map(async (item) => populate(item)));
|
|
6923
7010
|
return populatedItems;
|
|
6924
7011
|
};
|
|
6925
7012
|
const findOne2 = async (finder, finderParams = {}, locations = []) => {
|
|
6926
|
-
|
|
7013
|
+
logger27.default("find", { finder, finderParams, locations });
|
|
6927
7014
|
const item = await cache.operations.findOne(finder, finderParams, locations);
|
|
7015
|
+
if (!item) {
|
|
7016
|
+
return null;
|
|
7017
|
+
}
|
|
6928
7018
|
const populatedItem = await populate(item);
|
|
6929
7019
|
return populatedItem;
|
|
6930
7020
|
};
|
|
6931
7021
|
const set2 = async (key, v) => {
|
|
6932
|
-
|
|
7022
|
+
logger27.default("set", { key, v });
|
|
6933
7023
|
const item = await cache.operations.set(key, v);
|
|
6934
7024
|
const populatedItem = await populate(item);
|
|
6935
7025
|
return populatedItem;
|
|
@@ -6981,13 +7071,13 @@ var createAggregator = async (cache, { aggregates = {}, events = {} }) => {
|
|
|
6981
7071
|
import {
|
|
6982
7072
|
createRegistry as createBaseRegistry
|
|
6983
7073
|
} from "@fjell/registry";
|
|
6984
|
-
var
|
|
7074
|
+
var logger28 = logger_default.get("Registry");
|
|
6985
7075
|
var createRegistryFactory = () => {
|
|
6986
7076
|
return (type, registryHub) => {
|
|
6987
7077
|
if (type !== "cache") {
|
|
6988
7078
|
throw new Error(`Cache registry factory can only create 'cache' type registries, got: ${type}`);
|
|
6989
7079
|
}
|
|
6990
|
-
|
|
7080
|
+
logger28.debug("Creating cache registry", { type, registryHub });
|
|
6991
7081
|
const baseRegistry = createBaseRegistry(type, registryHub);
|
|
6992
7082
|
return baseRegistry;
|
|
6993
7083
|
};
|