@fjell/cache 4.6.7 → 4.6.11

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 (77) hide show
  1. package/dist/Aggregator.cjs.js +26 -20
  2. package/dist/Aggregator.d.ts +17 -1
  3. package/dist/Aggregator.es.js +26 -20
  4. package/dist/Cache.cjs.js +22 -345
  5. package/dist/Cache.d.ts +25 -20
  6. package/dist/Cache.es.js +22 -346
  7. package/dist/Instance.cjs.js +23 -0
  8. package/dist/Instance.d.ts +17 -0
  9. package/dist/Instance.es.js +18 -0
  10. package/dist/InstanceFactory.cjs.js +35 -0
  11. package/dist/InstanceFactory.d.ts +8 -0
  12. package/dist/InstanceFactory.es.js +31 -0
  13. package/dist/Operations.cjs.js +43 -0
  14. package/dist/Operations.d.ts +70 -0
  15. package/dist/Operations.es.js +39 -0
  16. package/dist/Registry.cjs.js +36 -0
  17. package/dist/Registry.d.ts +15 -0
  18. package/dist/Registry.es.js +31 -0
  19. package/dist/index.cjs +459 -408
  20. package/dist/index.cjs.js +12 -3
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.d.ts +4 -1
  23. package/dist/index.es.js +6 -3
  24. package/dist/ops/action.cjs.js +28 -0
  25. package/dist/ops/action.d.ts +4 -0
  26. package/dist/ops/action.es.js +24 -0
  27. package/dist/ops/all.cjs.js +33 -0
  28. package/dist/ops/all.d.ts +4 -0
  29. package/dist/ops/all.es.js +29 -0
  30. package/dist/ops/allAction.cjs.js +35 -0
  31. package/dist/ops/allAction.d.ts +4 -0
  32. package/dist/ops/allAction.es.js +31 -0
  33. package/dist/ops/allFacet.cjs.js +22 -0
  34. package/dist/ops/allFacet.d.ts +4 -0
  35. package/dist/ops/allFacet.es.js +18 -0
  36. package/dist/ops/create.cjs.js +23 -0
  37. package/dist/ops/create.d.ts +4 -0
  38. package/dist/ops/create.es.js +19 -0
  39. package/dist/ops/facet.cjs.js +21 -0
  40. package/dist/ops/facet.d.ts +4 -0
  41. package/dist/ops/facet.es.js +17 -0
  42. package/dist/ops/find.cjs.js +26 -0
  43. package/dist/ops/find.d.ts +4 -0
  44. package/dist/ops/find.es.js +22 -0
  45. package/dist/ops/findOne.cjs.js +24 -0
  46. package/dist/ops/findOne.d.ts +4 -0
  47. package/dist/ops/findOne.es.js +20 -0
  48. package/dist/ops/get.cjs.js +38 -0
  49. package/dist/ops/get.d.ts +4 -0
  50. package/dist/ops/get.es.js +34 -0
  51. package/dist/ops/one.cjs.js +33 -0
  52. package/dist/ops/one.d.ts +4 -0
  53. package/dist/ops/one.es.js +29 -0
  54. package/dist/ops/remove.cjs.js +30 -0
  55. package/dist/ops/remove.d.ts +4 -0
  56. package/dist/ops/remove.es.js +26 -0
  57. package/dist/ops/reset.cjs.js +15 -0
  58. package/dist/ops/reset.d.ts +4 -0
  59. package/dist/ops/reset.es.js +11 -0
  60. package/dist/ops/retrieve.cjs.js +37 -0
  61. package/dist/ops/retrieve.d.ts +4 -0
  62. package/dist/ops/retrieve.es.js +33 -0
  63. package/dist/ops/set.cjs.js +71 -0
  64. package/dist/ops/set.d.ts +3 -0
  65. package/dist/ops/set.es.js +67 -0
  66. package/dist/ops/update.cjs.js +34 -0
  67. package/dist/ops/update.d.ts +4 -0
  68. package/dist/ops/update.es.js +30 -0
  69. package/examples/README.md +302 -0
  70. package/examples/aggregator-example.ts +328 -0
  71. package/examples/basic-cache-example.ts +270 -0
  72. package/examples/cache-map-example.ts +265 -0
  73. package/package.json +7 -6
  74. package/vitest.config.ts +2 -2
  75. package/dist/CacheRegistry.cjs.js +0 -66
  76. package/dist/CacheRegistry.d.ts +0 -10
  77. package/dist/CacheRegistry.es.js +0 -62
@@ -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