@fjell/cache 4.6.10 → 4.6.13

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.
Files changed (81) hide show
  1. package/README.md +96 -0
  2. package/dist/Aggregator.cjs.js +26 -20
  3. package/dist/Aggregator.d.ts +17 -1
  4. package/dist/Aggregator.es.js +26 -20
  5. package/dist/Cache.cjs.js +22 -345
  6. package/dist/Cache.d.ts +25 -20
  7. package/dist/Cache.es.js +22 -346
  8. package/dist/Instance.cjs.js +7 -11
  9. package/dist/Instance.d.ts +5 -8
  10. package/dist/Instance.es.js +6 -10
  11. package/dist/InstanceFactory.cjs.js +17 -5
  12. package/dist/InstanceFactory.d.ts +3 -3
  13. package/dist/InstanceFactory.es.js +17 -5
  14. package/dist/Operations.cjs.js +43 -0
  15. package/dist/Operations.d.ts +70 -0
  16. package/dist/Operations.es.js +39 -0
  17. package/dist/index.cjs +416 -369
  18. package/dist/index.cjs.js +4 -1
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.ts +1 -0
  21. package/dist/index.es.js +3 -2
  22. package/dist/ops/action.cjs.js +28 -0
  23. package/dist/ops/action.d.ts +4 -0
  24. package/dist/ops/action.es.js +24 -0
  25. package/dist/ops/all.cjs.js +33 -0
  26. package/dist/ops/all.d.ts +4 -0
  27. package/dist/ops/all.es.js +29 -0
  28. package/dist/ops/allAction.cjs.js +35 -0
  29. package/dist/ops/allAction.d.ts +4 -0
  30. package/dist/ops/allAction.es.js +31 -0
  31. package/dist/ops/allFacet.cjs.js +22 -0
  32. package/dist/ops/allFacet.d.ts +4 -0
  33. package/dist/ops/allFacet.es.js +18 -0
  34. package/dist/ops/create.cjs.js +23 -0
  35. package/dist/ops/create.d.ts +4 -0
  36. package/dist/ops/create.es.js +19 -0
  37. package/dist/ops/facet.cjs.js +21 -0
  38. package/dist/ops/facet.d.ts +4 -0
  39. package/dist/ops/facet.es.js +17 -0
  40. package/dist/ops/find.cjs.js +26 -0
  41. package/dist/ops/find.d.ts +4 -0
  42. package/dist/ops/find.es.js +22 -0
  43. package/dist/ops/findOne.cjs.js +24 -0
  44. package/dist/ops/findOne.d.ts +4 -0
  45. package/dist/ops/findOne.es.js +20 -0
  46. package/dist/ops/get.cjs.js +38 -0
  47. package/dist/ops/get.d.ts +4 -0
  48. package/dist/ops/get.es.js +34 -0
  49. package/dist/ops/one.cjs.js +33 -0
  50. package/dist/ops/one.d.ts +4 -0
  51. package/dist/ops/one.es.js +29 -0
  52. package/dist/ops/remove.cjs.js +30 -0
  53. package/dist/ops/remove.d.ts +4 -0
  54. package/dist/ops/remove.es.js +26 -0
  55. package/dist/ops/reset.cjs.js +15 -0
  56. package/dist/ops/reset.d.ts +4 -0
  57. package/dist/ops/reset.es.js +11 -0
  58. package/dist/ops/retrieve.cjs.js +37 -0
  59. package/dist/ops/retrieve.d.ts +4 -0
  60. package/dist/ops/retrieve.es.js +33 -0
  61. package/dist/ops/set.cjs.js +71 -0
  62. package/dist/ops/set.d.ts +3 -0
  63. package/dist/ops/set.es.js +67 -0
  64. package/dist/ops/update.cjs.js +34 -0
  65. package/dist/ops/update.d.ts +4 -0
  66. package/dist/ops/update.es.js +30 -0
  67. package/docs/docs.config.ts +75 -0
  68. package/docs/index.html +18 -0
  69. package/docs/package.json +34 -0
  70. package/docs/public/README.md +96 -0
  71. package/docs/public/examples-README.md +302 -0
  72. package/docs/public/test.txt +0 -0
  73. package/docs/src/index.css +3 -0
  74. package/docs/src/main.tsx +12 -0
  75. package/docs/src/test/setup.ts +1 -0
  76. package/docs/tsconfig.node.json +15 -0
  77. package/examples/README.md +34 -39
  78. package/examples/aggregator-example.ts +9 -14
  79. package/examples/basic-cache-example.ts +18 -21
  80. package/package.json +16 -11
  81. package/vitest.config.ts +1 -1
@@ -0,0 +1,29 @@
1
+ import { validatePK } from '@fjell/core';
2
+ import { NotFoundError } from '@fjell/http-api';
3
+ import LibLogger from '../logger.es.js';
4
+
5
+ const logger = LibLogger.get('one');
6
+ const one = async (api, cacheMap, pkType, query = {}, locations = [])=>{
7
+ logger.default('one', {
8
+ query,
9
+ locations
10
+ });
11
+ let retItem = null;
12
+ try {
13
+ retItem = await api.one(query, locations);
14
+ if (retItem) {
15
+ cacheMap.set(retItem.key, retItem);
16
+ }
17
+ } catch (e) {
18
+ if (e instanceof NotFoundError) ; else {
19
+ throw e;
20
+ }
21
+ }
22
+ return [
23
+ cacheMap,
24
+ retItem ? validatePK(retItem, pkType) : null
25
+ ];
26
+ };
27
+
28
+ export { one };
29
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib25lLmVzLmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0=
@@ -0,0 +1,30 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const core = require('@fjell/core');
6
+ const logger$1 = require('../logger.cjs.js');
7
+
8
+ const logger = logger$1.default.get('remove');
9
+ const remove = async (api, cacheMap, key)=>{
10
+ logger.default('remove', {
11
+ key
12
+ });
13
+ if (!core.isValidItemKey(key)) {
14
+ logger.error('Key for Remove is not a valid ItemKey: %j', key);
15
+ throw new Error('Key for Remove is not a valid ItemKey');
16
+ }
17
+ try {
18
+ await api.remove(key);
19
+ cacheMap.delete(key);
20
+ } catch (e) {
21
+ logger.error("Error deleting item", {
22
+ error: e
23
+ });
24
+ throw e;
25
+ }
26
+ return cacheMap;
27
+ };
28
+
29
+ exports.remove = remove;
30
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVtb3ZlLmNqcy5qcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
@@ -0,0 +1,4 @@
1
+ import { ComKey, Item, PriKey } from '@fjell/core';
2
+ import { ClientApi } from '@fjell/client-api';
3
+ import { CacheMap } from '../CacheMap';
4
+ export declare const remove: <V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(api: ClientApi<V, S, L1, L2, L3, L4, L5>, cacheMap: CacheMap<V, S, L1, L2, L3, L4, L5>, key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>) => Promise<CacheMap<V, S, L1, L2, L3, L4, L5>>;
@@ -0,0 +1,26 @@
1
+ import { isValidItemKey } from '@fjell/core';
2
+ import LibLogger from '../logger.es.js';
3
+
4
+ const logger = LibLogger.get('remove');
5
+ const remove = async (api, cacheMap, key)=>{
6
+ logger.default('remove', {
7
+ key
8
+ });
9
+ if (!isValidItemKey(key)) {
10
+ logger.error('Key for Remove is not a valid ItemKey: %j', key);
11
+ throw new Error('Key for Remove is not a valid ItemKey');
12
+ }
13
+ try {
14
+ await api.remove(key);
15
+ cacheMap.delete(key);
16
+ } catch (e) {
17
+ logger.error("Error deleting item", {
18
+ error: e
19
+ });
20
+ throw e;
21
+ }
22
+ return cacheMap;
23
+ };
24
+
25
+ export { remove };
26
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVtb3ZlLmVzLmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0=
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const CacheMap = require('../CacheMap.cjs.js');
6
+
7
+ const reset = async (coordinate)=>{
8
+ const cacheMap = new CacheMap.CacheMap(coordinate.kta);
9
+ return [
10
+ cacheMap
11
+ ];
12
+ };
13
+
14
+ exports.reset = reset;
15
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVzZXQuY2pzLmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7OyJ9
@@ -0,0 +1,4 @@
1
+ import { Item } from '@fjell/core';
2
+ import { CacheMap } from '../CacheMap';
3
+ import { Coordinate } from '@fjell/registry';
4
+ export declare const reset: <V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(coordinate: Coordinate<S, L1, L2, L3, L4, L5>) => Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>]>;
@@ -0,0 +1,11 @@
1
+ import { CacheMap } from '../CacheMap.es.js';
2
+
3
+ const reset = async (coordinate)=>{
4
+ const cacheMap = new CacheMap(coordinate.kta);
5
+ return [
6
+ cacheMap
7
+ ];
8
+ };
9
+
10
+ export { reset };
11
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVzZXQuZXMuanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7OzsifQ==
@@ -0,0 +1,37 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const core = require('@fjell/core');
6
+ const logger$1 = require('../logger.cjs.js');
7
+ const get = require('./get.cjs.js');
8
+
9
+ const logger = logger$1.default.get('retrieve');
10
+ const retrieve = async (api, cacheMap, pkType, key)=>{
11
+ logger.default('retrieve', {
12
+ key
13
+ });
14
+ if (!core.isValidItemKey(key)) {
15
+ logger.error('Key for Retrieve is not a valid ItemKey: %j', key);
16
+ throw new Error('Key for Retrieve is not a valid ItemKey');
17
+ }
18
+ const containsItemKey = cacheMap.includesKey(key);
19
+ let retrieved;
20
+ if (containsItemKey) {
21
+ logger.default('Looking for Object in Cache', key);
22
+ retrieved = cacheMap.get(key);
23
+ } else {
24
+ logger.default('Object Not Found in Cache, Retrieving from Server API', {
25
+ key
26
+ });
27
+ [, retrieved] = await get.get(api, cacheMap, pkType, key);
28
+ }
29
+ const retValue = [
30
+ containsItemKey ? null : cacheMap,
31
+ retrieved ? core.validatePK(retrieved, pkType) : null
32
+ ];
33
+ return retValue;
34
+ };
35
+
36
+ exports.retrieve = retrieve;
37
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmV0cmlldmUuY2pzLmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
@@ -0,0 +1,4 @@
1
+ import { ComKey, Item, PriKey } from '@fjell/core';
2
+ import { CacheMap } from '../CacheMap';
3
+ import { ClientApi } from '@fjell/client-api';
4
+ export declare const retrieve: <V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(api: ClientApi<V, S, L1, L2, L3, L4, L5>, cacheMap: CacheMap<V, S, L1, L2, L3, L4, L5>, pkType: S, key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>) => Promise<[CacheMap<V, S, L1, L2, L3, L4, L5> | null, V | null]>;
@@ -0,0 +1,33 @@
1
+ import { isValidItemKey, validatePK } from '@fjell/core';
2
+ import LibLogger from '../logger.es.js';
3
+ import { get } from './get.es.js';
4
+
5
+ const logger = LibLogger.get('retrieve');
6
+ const retrieve = async (api, cacheMap, pkType, key)=>{
7
+ logger.default('retrieve', {
8
+ key
9
+ });
10
+ if (!isValidItemKey(key)) {
11
+ logger.error('Key for Retrieve is not a valid ItemKey: %j', key);
12
+ throw new Error('Key for Retrieve is not a valid ItemKey');
13
+ }
14
+ const containsItemKey = cacheMap.includesKey(key);
15
+ let retrieved;
16
+ if (containsItemKey) {
17
+ logger.default('Looking for Object in Cache', key);
18
+ retrieved = cacheMap.get(key);
19
+ } else {
20
+ logger.default('Object Not Found in Cache, Retrieving from Server API', {
21
+ key
22
+ });
23
+ [, retrieved] = await get(api, cacheMap, pkType, key);
24
+ }
25
+ const retValue = [
26
+ containsItemKey ? null : cacheMap,
27
+ retrieved ? validatePK(retrieved, pkType) : null
28
+ ];
29
+ return retValue;
30
+ };
31
+
32
+ export { retrieve };
33
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmV0cmlldmUuZXMuanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0=
@@ -0,0 +1,71 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const core = require('@fjell/core');
6
+ const logger$1 = require('../logger.cjs.js');
7
+
8
+ const logger = logger$1.default.get('set');
9
+ // Normalize a key value to string for consistent comparison
10
+ const normalizeKeyValue = (value)=>{
11
+ return String(value);
12
+ };
13
+ // Normalized key comparison function that handles string/number differences
14
+ const isItemKeyEqualNormalized = (a, b)=>{
15
+ // For now, just normalize the keys to strings and use the original comparison
16
+ const normalizedA = normalizeKey(a);
17
+ const normalizedB = normalizeKey(b);
18
+ return core.isItemKeyEqual(normalizedA, normalizedB);
19
+ };
20
+ // Helper function to normalize a key
21
+ const normalizeKey = (key)=>{
22
+ if (typeof key === 'object' && key !== null) {
23
+ const normalizedKey = JSON.parse(JSON.stringify(key));
24
+ // Normalize pk values
25
+ if ('pk' in normalizedKey && normalizedKey.pk !== null) {
26
+ normalizedKey.pk = normalizeKeyValue(normalizedKey.pk);
27
+ }
28
+ // Normalize lk values
29
+ if ('lk' in normalizedKey && normalizedKey.lk !== null) {
30
+ normalizedKey.lk = normalizeKeyValue(normalizedKey.lk);
31
+ }
32
+ // Normalize loc array lk values
33
+ if ('loc' in normalizedKey && Array.isArray(normalizedKey.loc)) {
34
+ normalizedKey.loc = normalizedKey.loc.map((locItem)=>{
35
+ if (locItem && 'lk' in locItem && locItem.lk !== null) {
36
+ return {
37
+ ...locItem,
38
+ lk: normalizeKeyValue(locItem.lk)
39
+ };
40
+ }
41
+ return locItem;
42
+ });
43
+ }
44
+ return normalizedKey;
45
+ }
46
+ return key;
47
+ };
48
+ const set = async (cacheMap, pkType, key, v)=>{
49
+ logger.default('set', {
50
+ key,
51
+ v
52
+ });
53
+ if (!core.isValidItemKey(key)) {
54
+ logger.error('Key for Set is not a valid ItemKey: %j', key);
55
+ throw new Error('Key for Set is not a valid ItemKey');
56
+ }
57
+ // Validate the item's primary key
58
+ core.validatePK(v, pkType);
59
+ if (!isItemKeyEqualNormalized(key, v.key)) {
60
+ logger.error('Key does not match item key: %j != %j', key, v.key);
61
+ throw new Error('Key does not match item key');
62
+ }
63
+ cacheMap.set(key, v);
64
+ return [
65
+ cacheMap,
66
+ core.validatePK(v, pkType)
67
+ ];
68
+ };
69
+
70
+ exports.set = set;
71
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2V0LmNqcy5qcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
@@ -0,0 +1,3 @@
1
+ import { ComKey, Item, PriKey } from '@fjell/core';
2
+ import { CacheMap } from '../CacheMap';
3
+ export declare const set: <V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(cacheMap: CacheMap<V, S, L1, L2, L3, L4, L5>, pkType: S, key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>, v: Item<S, L1, L2, L3, L4, L5>) => Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V]>;
@@ -0,0 +1,67 @@
1
+ import { isValidItemKey, validatePK, isItemKeyEqual } from '@fjell/core';
2
+ import LibLogger from '../logger.es.js';
3
+
4
+ const logger = LibLogger.get('set');
5
+ // Normalize a key value to string for consistent comparison
6
+ const normalizeKeyValue = (value)=>{
7
+ return String(value);
8
+ };
9
+ // Normalized key comparison function that handles string/number differences
10
+ const isItemKeyEqualNormalized = (a, b)=>{
11
+ // For now, just normalize the keys to strings and use the original comparison
12
+ const normalizedA = normalizeKey(a);
13
+ const normalizedB = normalizeKey(b);
14
+ return isItemKeyEqual(normalizedA, normalizedB);
15
+ };
16
+ // Helper function to normalize a key
17
+ const normalizeKey = (key)=>{
18
+ if (typeof key === 'object' && key !== null) {
19
+ const normalizedKey = JSON.parse(JSON.stringify(key));
20
+ // Normalize pk values
21
+ if ('pk' in normalizedKey && normalizedKey.pk !== null) {
22
+ normalizedKey.pk = normalizeKeyValue(normalizedKey.pk);
23
+ }
24
+ // Normalize lk values
25
+ if ('lk' in normalizedKey && normalizedKey.lk !== null) {
26
+ normalizedKey.lk = normalizeKeyValue(normalizedKey.lk);
27
+ }
28
+ // Normalize loc array lk values
29
+ if ('loc' in normalizedKey && Array.isArray(normalizedKey.loc)) {
30
+ normalizedKey.loc = normalizedKey.loc.map((locItem)=>{
31
+ if (locItem && 'lk' in locItem && locItem.lk !== null) {
32
+ return {
33
+ ...locItem,
34
+ lk: normalizeKeyValue(locItem.lk)
35
+ };
36
+ }
37
+ return locItem;
38
+ });
39
+ }
40
+ return normalizedKey;
41
+ }
42
+ return key;
43
+ };
44
+ const set = async (cacheMap, pkType, key, v)=>{
45
+ logger.default('set', {
46
+ key,
47
+ v
48
+ });
49
+ if (!isValidItemKey(key)) {
50
+ logger.error('Key for Set is not a valid ItemKey: %j', key);
51
+ throw new Error('Key for Set is not a valid ItemKey');
52
+ }
53
+ // Validate the item's primary key
54
+ validatePK(v, pkType);
55
+ if (!isItemKeyEqualNormalized(key, v.key)) {
56
+ logger.error('Key does not match item key: %j != %j', key, v.key);
57
+ throw new Error('Key does not match item key');
58
+ }
59
+ cacheMap.set(key, v);
60
+ return [
61
+ cacheMap,
62
+ validatePK(v, pkType)
63
+ ];
64
+ };
65
+
66
+ export { set };
67
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2V0LmVzLmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
@@ -0,0 +1,34 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const core = require('@fjell/core');
6
+ const logger$1 = require('../logger.cjs.js');
7
+
8
+ const logger = logger$1.default.get('update');
9
+ const update = async (api, cacheMap, pkType, key, v)=>{
10
+ logger.default('update', {
11
+ key,
12
+ v
13
+ });
14
+ if (!core.isValidItemKey(key)) {
15
+ logger.error('Key for Update is not a valid ItemKey: %j', key);
16
+ throw new Error('Key for Update is not a valid ItemKey');
17
+ }
18
+ try {
19
+ const updated = await api.update(key, v);
20
+ cacheMap.set(updated.key, updated);
21
+ return [
22
+ cacheMap,
23
+ core.validatePK(updated, pkType)
24
+ ];
25
+ } catch (e) {
26
+ logger.error("Error updating item", {
27
+ error: e
28
+ });
29
+ throw e;
30
+ }
31
+ };
32
+
33
+ exports.update = update;
34
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXBkYXRlLmNqcy5qcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0=
@@ -0,0 +1,4 @@
1
+ import { ComKey, Item, PriKey } from '@fjell/core';
2
+ import { ClientApi } from '@fjell/client-api';
3
+ import { CacheMap } from '../CacheMap';
4
+ export declare const update: <V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(api: ClientApi<V, S, L1, L2, L3, L4, L5>, cacheMap: CacheMap<V, S, L1, L2, L3, L4, L5>, pkType: S, key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>, v: Partial<Item<S, L1, L2, L3, L4, L5>>) => Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V]>;
@@ -0,0 +1,30 @@
1
+ import { isValidItemKey, validatePK } from '@fjell/core';
2
+ import LibLogger from '../logger.es.js';
3
+
4
+ const logger = LibLogger.get('update');
5
+ const update = async (api, cacheMap, pkType, key, v)=>{
6
+ logger.default('update', {
7
+ key,
8
+ v
9
+ });
10
+ if (!isValidItemKey(key)) {
11
+ logger.error('Key for Update is not a valid ItemKey: %j', key);
12
+ throw new Error('Key for Update is not a valid ItemKey');
13
+ }
14
+ try {
15
+ const updated = await api.update(key, v);
16
+ cacheMap.set(updated.key, updated);
17
+ return [
18
+ cacheMap,
19
+ validatePK(updated, pkType)
20
+ ];
21
+ } catch (e) {
22
+ logger.error("Error updating item", {
23
+ error: e
24
+ });
25
+ throw e;
26
+ }
27
+ };
28
+
29
+ export { update };
30
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXBkYXRlLmVzLmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
@@ -0,0 +1,75 @@
1
+ interface DocsConfig {
2
+ projectName: string;
3
+ basePath: string;
4
+ port: number;
5
+ branding: {
6
+ theme: string;
7
+ tagline: string;
8
+ logo?: string;
9
+ backgroundImage?: string;
10
+ primaryColor?: string;
11
+ accentColor?: string;
12
+ github?: string;
13
+ npm?: string;
14
+ };
15
+ sections: Array<{
16
+ id: string;
17
+ title: string;
18
+ subtitle: string;
19
+ file: string;
20
+ }>;
21
+ filesToCopy: Array<{
22
+ source: string;
23
+ destination: string;
24
+ }>;
25
+ plugins?: any[];
26
+ version: {
27
+ source: string;
28
+ };
29
+ customContent?: {
30
+ [key: string]: (content: string) => string;
31
+ };
32
+ }
33
+
34
+ const config: DocsConfig = {
35
+ projectName: 'Fjell Cache',
36
+ basePath: '/fjell-cache/',
37
+ port: 3005,
38
+ branding: {
39
+ theme: 'cache',
40
+ tagline: 'Cache for Fjell',
41
+ backgroundImage: '/pano.png',
42
+ github: 'https://github.com/getfjell/fjell-cache',
43
+ npm: 'https://www.npmjs.com/package/@fjell/cache'
44
+ },
45
+ sections: [
46
+ {
47
+ id: 'overview',
48
+ title: 'Getting Started',
49
+ subtitle: 'Installation, setup & core concepts',
50
+ file: '/README.md'
51
+ },
52
+ {
53
+ id: 'examples',
54
+ title: 'Examples',
55
+ subtitle: 'Code examples & usage patterns',
56
+ file: '/examples-README.md'
57
+ }
58
+ ],
59
+ filesToCopy: [
60
+ {
61
+ source: '../README.md',
62
+ destination: 'public/README.md'
63
+ },
64
+ {
65
+ source: '../examples/README.md',
66
+ destination: 'public/examples-README.md'
67
+ }
68
+ ],
69
+ plugins: [],
70
+ version: {
71
+ source: 'package.json'
72
+ }
73
+ }
74
+
75
+ export default config
@@ -0,0 +1,18 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+
4
+ <head>
5
+ <meta charset="UTF-8" />
6
+ <link rel="icon" type="image/svg+xml" href="/fjell-icon.svg" />
7
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
8
+ <title>Fjell Cache - Cache for Fjell</title>
9
+ <meta name="description"
10
+ content="Cache for Fjell - A powerful caching framework for TypeScript applications with intelligent caching and business relationships">
11
+ </head>
12
+
13
+ <body>
14
+ <div id="root"></div>
15
+ <script type="module" src="/src/main.tsx"></script>
16
+ </body>
17
+
18
+ </html>
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "fjell-cache-docs",
3
+ "private": true,
4
+ "version": "0.0.0",
5
+ "type": "module",
6
+ "scripts": {
7
+ "copy-docs": "node node_modules/@fjell/docs-template/scripts/copy-docs.js",
8
+ "dev": "pnpm run copy-docs && vite",
9
+ "build": "pnpm run copy-docs && vite build",
10
+ "preview": "vite preview",
11
+ "test": "vitest run --coverage",
12
+ "test:watch": "vitest --watch"
13
+ },
14
+ "dependencies": {
15
+ "@fjell/docs-template": "1.0.5",
16
+ "react": "^19.1.0",
17
+ "react-dom": "^19.1.0"
18
+ },
19
+ "devDependencies": {
20
+ "@testing-library/jest-dom": "^6.6.3",
21
+ "@testing-library/react": "^16.3.0",
22
+ "@testing-library/user-event": "^14.6.1",
23
+ "@types/react": "^19.1.8",
24
+ "@types/react-dom": "^19.1.6",
25
+ "@types/react-syntax-highlighter": "^15.5.13",
26
+ "@vitejs/plugin-react": "^4.6.0",
27
+ "@vitest/coverage-v8": "^3.2.4",
28
+ "@vitest/ui": "^3.2.4",
29
+ "jsdom": "^26.1.0",
30
+ "typescript": "^5.8.3",
31
+ "vite": "^7.0.0",
32
+ "vitest": "^3.2.4"
33
+ }
34
+ }
@@ -0,0 +1,96 @@
1
+ # Fjell Cache
2
+
3
+ Cache for Fjell - A powerful caching framework for TypeScript applications
4
+
5
+ ## Overview
6
+
7
+ Fjell Cache provides intelligent caching capabilities for complex data models and business relationships. Built on the Fjell framework architecture, it offers high-performance caching with automatic relationship management and business logic integration.
8
+
9
+ ## Features
10
+
11
+ - **Smart Caching**: Intelligent cache operations with automatic cache hits/misses
12
+ - **Business Relationships**: Automatic population of related entities through aggregation
13
+ - **Performance Optimized**: High-performance cache operations with bulk processing
14
+ - **Location-Based**: Support for contained items with location hierarchies
15
+ - **Framework Integration**: Seamless integration with Fjell Core, Registry, and Client API
16
+ - **TypeScript First**: Full TypeScript support with comprehensive type safety
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ npm install @fjell/cache
22
+ # or
23
+ pnpm add @fjell/cache
24
+ # or
25
+ yarn add @fjell/cache
26
+ ```
27
+
28
+ ## Quick Start
29
+
30
+ ```typescript
31
+ import { createCache } from '@fjell/cache';
32
+ import { createCoordinate, createRegistry } from '@fjell/registry';
33
+ import { ClientApi } from '@fjell/client-api';
34
+
35
+ // Create a registry for cache management
36
+ const registry = createRegistry();
37
+
38
+ // Create a cache instance with API integration
39
+ const userApi = createUserApi(); // Your API implementation
40
+ const userCache = await createCache(userApi, createCoordinate('user'), registry);
41
+
42
+ // Perform cache operations
43
+ const [cacheMap, allUsers] = await userCache.operations.all();
44
+ const [, cachedUser] = await userCache.operations.get(userKey);
45
+ const [, retrievedUser] = await userCache.operations.retrieve(userKey); // Cache hit!
46
+
47
+ await userCache.operations.set(userKey, updatedUser);
48
+ ```
49
+
50
+ ## Core Components
51
+
52
+ ### Basic Caching
53
+ - **Cache Operations**: Get, set, retrieve, and manage cached data
54
+ - **Cache-as-Instance**: Caches extend Instance from fjell-registry
55
+ - **Performance Monitoring**: Track cache hits, misses, and efficiency
56
+
57
+ ### Advanced Aggregation
58
+ - **Entity Relationships**: Automatic population of related entities
59
+ - **Required vs Optional**: Flexible relationship management
60
+ - **Business Logic**: Complex business scenarios with interconnected data
61
+
62
+ ### Direct Cache Management
63
+ - **CacheMap**: Low-level cache operations and management
64
+ - **Location Filtering**: Filter contained items by location hierarchy
65
+ - **Bulk Operations**: Efficient processing of multiple cache operations
66
+
67
+ ## Examples
68
+
69
+ Comprehensive examples are available in the [examples directory](./examples/):
70
+
71
+ - **[Basic Cache Example](./examples/basic-cache-example.ts)** - Start here! Fundamental caching operations
72
+ - **[Aggregator Example](./examples/aggregator-example.ts)** - Advanced business relationships
73
+ - **[Cache Map Example](./examples/cache-map-example.ts)** - Low-level cache operations
74
+
75
+ ## Documentation
76
+
77
+ For detailed documentation, examples, and API reference, visit our [documentation site](https://getfjell.github.io/fjell-cache/).
78
+
79
+ ## Dependencies
80
+
81
+ Fjell Cache builds on the Fjell ecosystem:
82
+ - `@fjell/core` - Core framework functionality
83
+ - `@fjell/registry` - Registry and coordinate management
84
+ - `@fjell/client-api` - API integration layer
85
+ - `@fjell/http-api` - HTTP API capabilities
86
+ - `@fjell/logging` - Structured logging
87
+
88
+ ## License
89
+
90
+ Apache-2.0
91
+
92
+ ## Contributing
93
+
94
+ We welcome contributions! Please see our contributing guidelines for more information.
95
+
96
+ Built with love by the Fjell team.