@fjell/cache 4.6.0 → 4.6.2

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.
@@ -0,0 +1,10 @@
1
+ verbose: false
2
+ model: gpt-4.1
3
+ contextDirectories:
4
+ - .kodrdriv/context
5
+ commit:
6
+ cached: true
7
+ sendit: true
8
+ release:
9
+ from: main
10
+ to: HEAD
@@ -0,0 +1 @@
1
+ This is the Fjell Library for Client-side Caches
@@ -17,7 +17,7 @@ const toCacheConfig = (config)=>{
17
17
  }
18
18
  return cacheConfig;
19
19
  };
20
- const createAggregator = (cache, { aggregates = {}, events = {} })=>{
20
+ const createAggregator = async (cache, { aggregates = {}, events = {} })=>{
21
21
  const populate = async (item)=>{
22
22
  logger.default('populate', {
23
23
  item
@@ -220,6 +220,18 @@ const createAggregator = (cache, { aggregates = {}, events = {} })=>{
220
220
  populatedItem
221
221
  ];
222
222
  };
223
+ // Facets are a pass-thru for aggregators
224
+ const facet = async (key, facet)=>{
225
+ logger.default('facet', {
226
+ key,
227
+ facet
228
+ });
229
+ const [cacheMap, response] = await cache.facet(key, facet);
230
+ return [
231
+ cacheMap,
232
+ response
233
+ ];
234
+ };
223
235
  const find = async (finder, finderParams, locations = [])=>{
224
236
  logger.default('find', {
225
237
  finder,
@@ -233,6 +245,19 @@ const createAggregator = (cache, { aggregates = {}, events = {} })=>{
233
245
  populatedItems
234
246
  ];
235
247
  };
248
+ const findOne = async (finder, finderParams, locations = [])=>{
249
+ logger.default('find', {
250
+ finder,
251
+ finderParams,
252
+ locations
253
+ });
254
+ const [cacheMap, item] = await cache.findOne(finder, finderParams, locations);
255
+ const populatedItem = await populate(item);
256
+ return [
257
+ cacheMap,
258
+ populatedItem
259
+ ];
260
+ };
236
261
  const set = async (key, v)=>{
237
262
  logger.default('set', {
238
263
  key,
@@ -260,7 +285,9 @@ const createAggregator = (cache, { aggregates = {}, events = {} })=>{
260
285
  retrieve,
261
286
  remove,
262
287
  update,
288
+ facet,
263
289
  find,
290
+ findOne,
264
291
  reset,
265
292
  set,
266
293
  pkTypes: cache.pkTypes,
@@ -273,4 +300,4 @@ const createAggregator = (cache, { aggregates = {}, events = {} })=>{
273
300
 
274
301
  exports.createAggregator = createAggregator;
275
302
  exports.toCacheConfig = toCacheConfig;
276
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQWdncmVnYXRvci5janMuanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0=
303
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQWdncmVnYXRvci5janMuanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0=
@@ -16,4 +16,4 @@ export declare const toCacheConfig: <V extends Item<S, L1, L2, L3, L4, L5>, S ex
16
16
  export declare const createAggregator: <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>(cache: Cache<V, S, L1, L2, L3, L4, L5>, { aggregates, events }: {
17
17
  aggregates?: AggregateConfig;
18
18
  events?: AggregateConfig;
19
- }) => Aggregator<V, S, L1, L2, L3, L4, L5>;
19
+ }) => Promise<Aggregator<V, S, L1, L2, L3, L4, L5>>;
@@ -13,7 +13,7 @@ const toCacheConfig = (config)=>{
13
13
  }
14
14
  return cacheConfig;
15
15
  };
16
- const createAggregator = (cache, { aggregates = {}, events = {} })=>{
16
+ const createAggregator = async (cache, { aggregates = {}, events = {} })=>{
17
17
  const populate = async (item)=>{
18
18
  logger.default('populate', {
19
19
  item
@@ -216,6 +216,18 @@ const createAggregator = (cache, { aggregates = {}, events = {} })=>{
216
216
  populatedItem
217
217
  ];
218
218
  };
219
+ // Facets are a pass-thru for aggregators
220
+ const facet = async (key, facet)=>{
221
+ logger.default('facet', {
222
+ key,
223
+ facet
224
+ });
225
+ const [cacheMap, response] = await cache.facet(key, facet);
226
+ return [
227
+ cacheMap,
228
+ response
229
+ ];
230
+ };
219
231
  const find = async (finder, finderParams, locations = [])=>{
220
232
  logger.default('find', {
221
233
  finder,
@@ -229,6 +241,19 @@ const createAggregator = (cache, { aggregates = {}, events = {} })=>{
229
241
  populatedItems
230
242
  ];
231
243
  };
244
+ const findOne = async (finder, finderParams, locations = [])=>{
245
+ logger.default('find', {
246
+ finder,
247
+ finderParams,
248
+ locations
249
+ });
250
+ const [cacheMap, item] = await cache.findOne(finder, finderParams, locations);
251
+ const populatedItem = await populate(item);
252
+ return [
253
+ cacheMap,
254
+ populatedItem
255
+ ];
256
+ };
232
257
  const set = async (key, v)=>{
233
258
  logger.default('set', {
234
259
  key,
@@ -256,7 +281,9 @@ const createAggregator = (cache, { aggregates = {}, events = {} })=>{
256
281
  retrieve,
257
282
  remove,
258
283
  update,
284
+ facet,
259
285
  find,
286
+ findOne,
260
287
  reset,
261
288
  set,
262
289
  pkTypes: cache.pkTypes,
@@ -268,4 +295,4 @@ const createAggregator = (cache, { aggregates = {}, events = {} })=>{
268
295
  };
269
296
 
270
297
  export { createAggregator, toCacheConfig };
271
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQWdncmVnYXRvci5lcy5qcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7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6 +213,18 @@ const createCache = (api, pkType, parentCache)=>{
213
213
  throw e;
214
214
  }
215
215
  };
216
+ // Facets are a pass-thru for caches
217
+ const facet = async (key, facet)=>{
218
+ logger.default('facet', {
219
+ key,
220
+ facet
221
+ });
222
+ const ret = await api.facet(key, facet, {});
223
+ return [
224
+ cacheMap,
225
+ ret
226
+ ];
227
+ };
216
228
  const find = async (finder, finderParams, locations = [])=>{
217
229
  logger.default('find', {
218
230
  finder,
@@ -228,6 +240,19 @@ const createCache = (api, pkType, parentCache)=>{
228
240
  core.validatePK(ret, pkType)
229
241
  ];
230
242
  };
243
+ const findOne = async (finder, finderParams, locations = [])=>{
244
+ logger.default('findOne', {
245
+ finder,
246
+ finderParams,
247
+ locations
248
+ });
249
+ const ret = await api.findOne(finder, finderParams, {}, locations);
250
+ cacheMap.set(ret.key, ret);
251
+ return [
252
+ cacheMap,
253
+ core.validatePK(ret, pkType)
254
+ ];
255
+ };
231
256
  const reset = async ()=>{
232
257
  cacheMap = new CacheMap.CacheMap(pkTypes);
233
258
  return [
@@ -267,7 +292,9 @@ const createCache = (api, pkType, parentCache)=>{
267
292
  retrieve,
268
293
  remove,
269
294
  update,
295
+ facet,
270
296
  find,
297
+ findOne,
271
298
  reset,
272
299
  set,
273
300
  pkTypes,
@@ -276,4 +303,4 @@ const createCache = (api, pkType, parentCache)=>{
276
303
  };
277
304
 
278
305
  exports.createCache = createCache;
279
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ2FjaGUuY2pzLmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7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<S, L1, L2, L3, L4, L5>, S extends string,
11
11
  retrieve: (key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>) => Promise<[CacheMap<V, S, L1, L2, L3, L4, L5> | null, V | null]>;
12
12
  remove: (key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>) => Promise<CacheMap<V, S, L1, L2, L3, L4, L5>>;
13
13
  update: (key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>, v: TypesProperties<V, S, L1, L2, L3, L4, L5>) => Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V]>;
14
+ facet: (key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>, facet: string) => Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, any]>;
14
15
  find: (finder: string, finderParams: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>, locations?: LocKeyArray<L1, L2, L3, L4, L5> | []) => Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V[]]>;
16
+ findOne: (finder: string, finderParams: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>, locations?: LocKeyArray<L1, L2, L3, L4, L5> | []) => Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V]>;
15
17
  set: (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]>;
16
18
  reset: () => Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>]>;
17
19
  pkTypes: AllItemTypeArrays<S, L1, L2, L3, L4, L5>;
18
20
  cacheMap: CacheMap<V, S, L1, L2, L3, L4, L5>;
19
21
  }
20
- export declare const createCache: <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>, pkType: S, parentCache?: Cache<Item<L1, L2, L3, L4, L5>, L1, L2, L3, L4, L5>) => Cache<V, S, L1, L2, L3, L4, L5>;
22
+ export declare const createCache: <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>, pkType: S, parentCache?: Cache<Item<L1, L2, L3, L4, L5>, L1, L2, L3, L4, L5>) => Promise<Cache<V, S, L1, L2, L3, L4, L5>>;
package/dist/Cache.es.js CHANGED
@@ -4,7 +4,7 @@ import LibLogger from './logger.es.js';
4
4
  import { NotFoundError } from '@fjell/http-api';
5
5
 
6
6
  const logger = LibLogger.get('Cache');
7
- const createCache = (api, pkType, parentCache)=>{
7
+ const createCache = async (api, pkType, parentCache)=>{
8
8
  let pkTypes = [
9
9
  pkType
10
10
  ];
@@ -209,6 +209,18 @@ const createCache = (api, pkType, parentCache)=>{
209
209
  throw e;
210
210
  }
211
211
  };
212
+ // Facets are a pass-thru for caches
213
+ const facet = async (key, facet)=>{
214
+ logger.default('facet', {
215
+ key,
216
+ facet
217
+ });
218
+ const ret = await api.facet(key, facet, {});
219
+ return [
220
+ cacheMap,
221
+ ret
222
+ ];
223
+ };
212
224
  const find = async (finder, finderParams, locations = [])=>{
213
225
  logger.default('find', {
214
226
  finder,
@@ -224,6 +236,19 @@ const createCache = (api, pkType, parentCache)=>{
224
236
  validatePK(ret, pkType)
225
237
  ];
226
238
  };
239
+ const findOne = async (finder, finderParams, locations = [])=>{
240
+ logger.default('findOne', {
241
+ finder,
242
+ finderParams,
243
+ locations
244
+ });
245
+ const ret = await api.findOne(finder, finderParams, {}, locations);
246
+ cacheMap.set(ret.key, ret);
247
+ return [
248
+ cacheMap,
249
+ validatePK(ret, pkType)
250
+ ];
251
+ };
227
252
  const reset = async ()=>{
228
253
  cacheMap = new CacheMap(pkTypes);
229
254
  return [
@@ -263,7 +288,9 @@ const createCache = (api, pkType, parentCache)=>{
263
288
  retrieve,
264
289
  remove,
265
290
  update,
291
+ facet,
266
292
  find,
293
+ findOne,
267
294
  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ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
@@ -19,36 +19,48 @@ function _define_property(obj, key, value) {
19
19
  }
20
20
  const logger = logger$1.default.get('CacheRegistry');
21
21
  class CacheRegistry {
22
- static getInstance() {
23
- if (!CacheRegistry.instance) {
24
- CacheRegistry.instance = new CacheRegistry();
25
- }
26
- return CacheRegistry.instance;
27
- }
28
22
  constructor(){
29
- _define_property(this, "configured", false);
30
23
  // TODO: My use of Generics has Boxed me into a corner where I can't reference AbstractCache without the types
31
24
  _define_property(this, "cacheMap", {});
32
- _define_property(this, "registerCache", (cache)=>{
33
- this.cacheMap[JSON.stringify(cache.pkTypes)] = cache;
34
- });
35
- _define_property(this, "isConfigured", ()=>{
36
- return this.configured;
37
- });
38
- _define_property(this, "markConfigured", ()=>{
39
- this.configured = true;
25
+ _define_property(this, "registerCache", async (cache)=>{
26
+ try {
27
+ logger.debug('Attempting to register cache with pkTypes:', cache.pkTypes);
28
+ const key = JSON.stringify(cache.pkTypes);
29
+ if (this.cacheMap[key]) {
30
+ logger.debug(`Cache with pkTypes ${key} already exists, will be overwritten`);
31
+ }
32
+ this.cacheMap[key] = cache;
33
+ logger.debug('Cache registered successfully with key:', key);
34
+ } catch (error) {
35
+ logger.error('Failed to register cache:', error);
36
+ throw error;
37
+ }
40
38
  });
41
39
  _define_property(this, "getCache", (kts)=>{
42
- if (!this.configured) {
43
- logger.error('CacheRegistry must be configured before use');
44
- throw new Error("CacheRegistry must be configured before use");
40
+ logger.debug('Attempting to get cache for key types:', kts);
41
+ const key = JSON.stringify(kts);
42
+ logger.debug('Looking up cache with key:', key);
43
+ const cache = this.cacheMap[key];
44
+ if (!cache) {
45
+ logger.warning(`No cache found for key types: ${key}`);
46
+ }
47
+ return cache;
48
+ });
49
+ _define_property(this, "printRegisteredCaches", ()=>{
50
+ logger.debug('Printing all registered caches:');
51
+ const cacheCount = Object.keys(this.cacheMap).length;
52
+ logger.debug(`Total number of registered caches: ${cacheCount}`);
53
+ if (cacheCount === 0) {
54
+ logger.debug('No caches are currently registered');
45
55
  }
46
- return this.cacheMap[JSON.stringify(kts)];
56
+ Object.entries(this.cacheMap).forEach(([keyTypes])=>{
57
+ logger.debug(`Cache with key types: ${keyTypes}`);
58
+ });
47
59
  });
48
- logger.debug('CacheRegistry created');
60
+ logger.debug('CacheRegistry instance created');
49
61
  }
50
62
  }
51
63
  _define_property(CacheRegistry, "instance", void 0);
52
64
 
53
65
  exports.CacheRegistry = CacheRegistry;
54
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ2FjaGVSZWdpc3RyeS5janMuanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0=
66
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ2FjaGVSZWdpc3RyeS5janMuanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0=
@@ -2,12 +2,9 @@ import { Item } from '@fjell/core';
2
2
  import { Cache } from './Cache';
3
3
  export declare class CacheRegistry {
4
4
  private static instance;
5
- private configured;
6
5
  constructor();
7
- static getInstance(): CacheRegistry;
8
6
  private cacheMap;
9
- registerCache: <S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(cache: Cache<Item<S, L1, L2, L3, L4, L5>, S, L1, L2, L3, L4, L5>) => void;
10
- isConfigured: () => boolean;
11
- markConfigured: () => void;
7
+ registerCache: <S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(cache: Cache<Item<S, L1, L2, L3, L4, L5>, S, L1, L2, L3, L4, L5>) => Promise<void>;
12
8
  getCache: (kts: string[]) => any;
9
+ printRegisteredCaches: () => void;
13
10
  }
@@ -15,36 +15,48 @@ function _define_property(obj, key, value) {
15
15
  }
16
16
  const logger = LibLogger.get('CacheRegistry');
17
17
  class CacheRegistry {
18
- static getInstance() {
19
- if (!CacheRegistry.instance) {
20
- CacheRegistry.instance = new CacheRegistry();
21
- }
22
- return CacheRegistry.instance;
23
- }
24
18
  constructor(){
25
- _define_property(this, "configured", false);
26
19
  // TODO: My use of Generics has Boxed me into a corner where I can't reference AbstractCache without the types
27
20
  _define_property(this, "cacheMap", {});
28
- _define_property(this, "registerCache", (cache)=>{
29
- this.cacheMap[JSON.stringify(cache.pkTypes)] = cache;
30
- });
31
- _define_property(this, "isConfigured", ()=>{
32
- return this.configured;
33
- });
34
- _define_property(this, "markConfigured", ()=>{
35
- this.configured = true;
21
+ _define_property(this, "registerCache", async (cache)=>{
22
+ try {
23
+ logger.debug('Attempting to register cache with pkTypes:', cache.pkTypes);
24
+ const key = JSON.stringify(cache.pkTypes);
25
+ if (this.cacheMap[key]) {
26
+ logger.debug(`Cache with pkTypes ${key} already exists, will be overwritten`);
27
+ }
28
+ this.cacheMap[key] = cache;
29
+ logger.debug('Cache registered successfully with key:', key);
30
+ } catch (error) {
31
+ logger.error('Failed to register cache:', error);
32
+ throw error;
33
+ }
36
34
  });
37
35
  _define_property(this, "getCache", (kts)=>{
38
- if (!this.configured) {
39
- logger.error('CacheRegistry must be configured before use');
40
- throw new Error("CacheRegistry must be configured before use");
36
+ logger.debug('Attempting to get cache for key types:', kts);
37
+ const key = JSON.stringify(kts);
38
+ logger.debug('Looking up cache with key:', key);
39
+ const cache = this.cacheMap[key];
40
+ if (!cache) {
41
+ logger.warning(`No cache found for key types: ${key}`);
42
+ }
43
+ return cache;
44
+ });
45
+ _define_property(this, "printRegisteredCaches", ()=>{
46
+ logger.debug('Printing all registered caches:');
47
+ const cacheCount = Object.keys(this.cacheMap).length;
48
+ logger.debug(`Total number of registered caches: ${cacheCount}`);
49
+ if (cacheCount === 0) {
50
+ logger.debug('No caches are currently registered');
41
51
  }
42
- return this.cacheMap[JSON.stringify(kts)];
52
+ Object.entries(this.cacheMap).forEach(([keyTypes])=>{
53
+ logger.debug(`Cache with key types: ${keyTypes}`);
54
+ });
43
55
  });
44
- logger.debug('CacheRegistry created');
56
+ logger.debug('CacheRegistry instance created');
45
57
  }
46
58
  }
47
59
  _define_property(CacheRegistry, "instance", void 0);
48
60
 
49
61
  export { CacheRegistry };
50
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ2FjaGVSZWdpc3RyeS5lcy5qcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
62
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ2FjaGVSZWdpc3RyeS5lcy5qcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
package/dist/index.cjs CHANGED
@@ -6,7 +6,7 @@ const Logging = require('@fjell/logging');
6
6
  const core = require('@fjell/core');
7
7
  const httpApi = require('@fjell/http-api');
8
8
 
9
- const LibLogger = Logging.getLogger('@fjellproject/cache');
9
+ const LibLogger = Logging.getLogger('@fjell/cache');
10
10
 
11
11
  const logger$3 = LibLogger.get('ItemAggregator');
12
12
  const toCacheConfig = (config)=>{
@@ -21,7 +21,7 @@ const toCacheConfig = (config)=>{
21
21
  }
22
22
  return cacheConfig;
23
23
  };
24
- const createAggregator = (cache, { aggregates = {}, events = {} })=>{
24
+ const createAggregator = async (cache, { aggregates = {}, events = {} })=>{
25
25
  const populate = async (item)=>{
26
26
  logger$3.default('populate', {
27
27
  item
@@ -224,6 +224,18 @@ const createAggregator = (cache, { aggregates = {}, events = {} })=>{
224
224
  populatedItem
225
225
  ];
226
226
  };
227
+ // Facets are a pass-thru for aggregators
228
+ const facet = async (key, facet)=>{
229
+ logger$3.default('facet', {
230
+ key,
231
+ facet
232
+ });
233
+ const [cacheMap, response] = await cache.facet(key, facet);
234
+ return [
235
+ cacheMap,
236
+ response
237
+ ];
238
+ };
227
239
  const find = async (finder, finderParams, locations = [])=>{
228
240
  logger$3.default('find', {
229
241
  finder,
@@ -237,6 +249,19 @@ const createAggregator = (cache, { aggregates = {}, events = {} })=>{
237
249
  populatedItems
238
250
  ];
239
251
  };
252
+ const findOne = async (finder, finderParams, locations = [])=>{
253
+ logger$3.default('find', {
254
+ finder,
255
+ finderParams,
256
+ locations
257
+ });
258
+ const [cacheMap, item] = await cache.findOne(finder, finderParams, locations);
259
+ const populatedItem = await populate(item);
260
+ return [
261
+ cacheMap,
262
+ populatedItem
263
+ ];
264
+ };
240
265
  const set = async (key, v)=>{
241
266
  logger$3.default('set', {
242
267
  key,
@@ -264,7 +289,9 @@ const createAggregator = (cache, { aggregates = {}, events = {} })=>{
264
289
  retrieve,
265
290
  remove,
266
291
  update,
292
+ facet,
267
293
  find,
294
+ findOne,
268
295
  reset,
269
296
  set,
270
297
  pkTypes: cache.pkTypes,
@@ -375,7 +402,7 @@ class CacheMap extends core.Dictionary {
375
402
  }
376
403
 
377
404
  const logger$1 = LibLogger.get('Cache');
378
- const createCache = (api, pkType, parentCache)=>{
405
+ const createCache = async (api, pkType, parentCache)=>{
379
406
  let pkTypes = [
380
407
  pkType
381
408
  ];
@@ -580,6 +607,18 @@ const createCache = (api, pkType, parentCache)=>{
580
607
  throw e;
581
608
  }
582
609
  };
610
+ // Facets are a pass-thru for caches
611
+ const facet = async (key, facet)=>{
612
+ logger$1.default('facet', {
613
+ key,
614
+ facet
615
+ });
616
+ const ret = await api.facet(key, facet, {});
617
+ return [
618
+ cacheMap,
619
+ ret
620
+ ];
621
+ };
583
622
  const find = async (finder, finderParams, locations = [])=>{
584
623
  logger$1.default('find', {
585
624
  finder,
@@ -595,6 +634,19 @@ const createCache = (api, pkType, parentCache)=>{
595
634
  core.validatePK(ret, pkType)
596
635
  ];
597
636
  };
637
+ const findOne = async (finder, finderParams, locations = [])=>{
638
+ logger$1.default('findOne', {
639
+ finder,
640
+ finderParams,
641
+ locations
642
+ });
643
+ const ret = await api.findOne(finder, finderParams, {}, locations);
644
+ cacheMap.set(ret.key, ret);
645
+ return [
646
+ cacheMap,
647
+ core.validatePK(ret, pkType)
648
+ ];
649
+ };
598
650
  const reset = async ()=>{
599
651
  cacheMap = new CacheMap(pkTypes);
600
652
  return [
@@ -634,7 +686,9 @@ const createCache = (api, pkType, parentCache)=>{
634
686
  retrieve,
635
687
  remove,
636
688
  update,
689
+ facet,
637
690
  find,
691
+ findOne,
638
692
  reset,
639
693
  set,
640
694
  pkTypes,
@@ -657,33 +711,45 @@ function _define_property(obj, key, value) {
657
711
  }
658
712
  const logger = LibLogger.get('CacheRegistry');
659
713
  class CacheRegistry {
660
- static getInstance() {
661
- if (!CacheRegistry.instance) {
662
- CacheRegistry.instance = new CacheRegistry();
663
- }
664
- return CacheRegistry.instance;
665
- }
666
714
  constructor(){
667
- _define_property(this, "configured", false);
668
715
  // TODO: My use of Generics has Boxed me into a corner where I can't reference AbstractCache without the types
669
716
  _define_property(this, "cacheMap", {});
670
- _define_property(this, "registerCache", (cache)=>{
671
- this.cacheMap[JSON.stringify(cache.pkTypes)] = cache;
672
- });
673
- _define_property(this, "isConfigured", ()=>{
674
- return this.configured;
675
- });
676
- _define_property(this, "markConfigured", ()=>{
677
- this.configured = true;
717
+ _define_property(this, "registerCache", async (cache)=>{
718
+ try {
719
+ logger.debug('Attempting to register cache with pkTypes:', cache.pkTypes);
720
+ const key = JSON.stringify(cache.pkTypes);
721
+ if (this.cacheMap[key]) {
722
+ logger.debug(`Cache with pkTypes ${key} already exists, will be overwritten`);
723
+ }
724
+ this.cacheMap[key] = cache;
725
+ logger.debug('Cache registered successfully with key:', key);
726
+ } catch (error) {
727
+ logger.error('Failed to register cache:', error);
728
+ throw error;
729
+ }
678
730
  });
679
731
  _define_property(this, "getCache", (kts)=>{
680
- if (!this.configured) {
681
- logger.error('CacheRegistry must be configured before use');
682
- throw new Error("CacheRegistry must be configured before use");
732
+ logger.debug('Attempting to get cache for key types:', kts);
733
+ const key = JSON.stringify(kts);
734
+ logger.debug('Looking up cache with key:', key);
735
+ const cache = this.cacheMap[key];
736
+ if (!cache) {
737
+ logger.warning(`No cache found for key types: ${key}`);
683
738
  }
684
- return this.cacheMap[JSON.stringify(kts)];
739
+ return cache;
740
+ });
741
+ _define_property(this, "printRegisteredCaches", ()=>{
742
+ logger.debug('Printing all registered caches:');
743
+ const cacheCount = Object.keys(this.cacheMap).length;
744
+ logger.debug(`Total number of registered caches: ${cacheCount}`);
745
+ if (cacheCount === 0) {
746
+ logger.debug('No caches are currently registered');
747
+ }
748
+ Object.entries(this.cacheMap).forEach(([keyTypes])=>{
749
+ logger.debug(`Cache with key types: ${keyTypes}`);
750
+ });
685
751
  });
686
- logger.debug('CacheRegistry created');
752
+ logger.debug('CacheRegistry instance created');
687
753
  }
688
754
  }
689
755
  _define_property(CacheRegistry, "instance", void 0);
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -4,7 +4,7 @@ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toString
4
4
 
5
5
  const Logging = require('@fjell/logging');
6
6
 
7
- const LibLogger = Logging.getLogger('@fjellproject/cache');
7
+ const LibLogger = Logging.getLogger('@fjell/cache');
8
8
 
9
9
  exports.default = LibLogger;
10
10
  //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibG9nZ2VyLmNqcy5qcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7In0=
package/dist/logger.es.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import Logging from '@fjell/logging';
2
2
 
3
- const LibLogger = Logging.getLogger('@fjellproject/cache');
3
+ const LibLogger = Logging.getLogger('@fjell/cache');
4
4
 
5
5
  export { LibLogger as default };
6
6
  //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibG9nZ2VyLmVzLmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7OyJ9
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fjell/cache",
3
3
  "description": "Cache for Fjell",
4
- "version": "4.6.0",
4
+ "version": "4.6.2",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
7
7
  "main": "./dist/index.cjs.js",
@@ -15,13 +15,13 @@
15
15
  }
16
16
  },
17
17
  "dependencies": {
18
- "@fjell/client-api": "^4.4.0",
18
+ "@fjell/client-api": "^4.4.2",
19
19
  "@fjell/core": "^4.4.2",
20
20
  "@fjell/http-api": "^4.4.0",
21
21
  "@fjell/logging": "^4.4.2",
22
22
  "d3": "^7.9.0",
23
23
  "dayjs": "^1.11.13",
24
- "react": "18.3.1"
24
+ "react": "19.1.0"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@babel/preset-env": "^7.26.9",
@@ -33,7 +33,7 @@
33
33
  "@types/babel__preset-env": "^7.10.0",
34
34
  "@types/d3": "^7.4.3",
35
35
  "@types/multer": "^1.4.12",
36
- "@types/node": "^22.13.5",
36
+ "@types/node": "^24.0.3",
37
37
  "@typescript-eslint/eslint-plugin": "^8.24.1",
38
38
  "@typescript-eslint/parser": "^8.24.1",
39
39
  "@vitest/coverage-v8": "^3.1.4",
@@ -55,7 +55,8 @@
55
55
  "url": "git+https://github.com/getfjell/cache.git"
56
56
  },
57
57
  "scripts": {
58
- "build": "tsc --noEmit && vite build",
58
+ "dev": "concurrently \"tsc --noEmit --watch\" \"vite build --watch\"",
59
+ "build": "pnpm run lint && tsc --noEmit && vite build",
59
60
  "lint": "eslint . --ext .ts --fix",
60
61
  "clean": "rimraf dist",
61
62
  "test": "pnpm run lint && vitest run --coverage"
package/src/Aggregator.ts CHANGED
@@ -49,7 +49,7 @@ export const toCacheConfig = <
49
49
  return cacheConfig;
50
50
  }
51
51
 
52
- export const createAggregator = <
52
+ export const createAggregator = async <
53
53
  V extends Item<S, L1, L2, L3, L4, L5>,
54
54
  S extends string,
55
55
  L1 extends string = never,
@@ -58,13 +58,13 @@ export const createAggregator = <
58
58
  L4 extends string = never,
59
59
  L5 extends string = never
60
60
  >(
61
- cache: Cache<V, S, L1, L2, L3, L4, L5>,
62
- { aggregates = {}, events = {} }:
61
+ cache: Cache<V, S, L1, L2, L3, L4, L5>,
62
+ { aggregates = {}, events = {} }:
63
63
  {
64
64
  aggregates?: AggregateConfig,
65
65
  events?: AggregateConfig
66
66
  }
67
- ): Aggregator<V, S, L1, L2, L3, L4, L5> => {
67
+ ): Promise<Aggregator<V, S, L1, L2, L3, L4, L5>> => {
68
68
 
69
69
  const populate = async (item: V): Promise<V> => {
70
70
  logger.default('populate', { item });
@@ -247,6 +247,16 @@ export const createAggregator = <
247
247
  return [cacheMap, populatedItem];
248
248
  }
249
249
 
250
+ // Facets are a pass-thru for aggregators
251
+ const facet = async (
252
+ key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>,
253
+ facet: string,
254
+ ): Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, any]> => {
255
+ logger.default('facet', { key, facet });
256
+ const [cacheMap, response] = await cache.facet(key, facet);
257
+ return [cacheMap, response];
258
+ }
259
+
250
260
  const find = async (
251
261
  finder: string,
252
262
  finderParams: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>,
@@ -258,6 +268,17 @@ export const createAggregator = <
258
268
  return [cacheMap, populatedItems];
259
269
  }
260
270
 
271
+ const findOne = async (
272
+ finder: string,
273
+ finderParams: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>,
274
+ locations: LocKeyArray<L1, L2, L3, L4, L5> | [] = []
275
+ ): Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V]> => {
276
+ logger.default('find', { finder, finderParams, locations });
277
+ const [cacheMap, item] = await cache.findOne(finder, finderParams, locations);
278
+ const populatedItem = await populate(item);
279
+ return [cacheMap, populatedItem];
280
+ }
281
+
261
282
  const set = async (
262
283
  key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>,
263
284
  v: Item<S, L1, L2, L3, L4, L5>
@@ -285,7 +306,9 @@ export const createAggregator = <
285
306
  retrieve,
286
307
  remove,
287
308
  update,
309
+ facet,
288
310
  find,
311
+ findOne,
289
312
  reset,
290
313
  set,
291
314
  pkTypes: cache.pkTypes,
package/src/Cache.ts CHANGED
@@ -73,12 +73,23 @@ export interface Cache<
73
73
  v: TypesProperties<V, S, L1, L2, L3, L4, L5>,
74
74
  ) => Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V]>;
75
75
 
76
+ facet: (
77
+ key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>,
78
+ facet: string,
79
+ ) => Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, any]>;
80
+
76
81
  find: (
77
82
  finder: string,
78
83
  finderParams: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>,
79
84
  locations?: LocKeyArray<L1, L2, L3, L4, L5> | []
80
85
  ) => Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V[]]>;
81
86
 
87
+ findOne: (
88
+ finder: string,
89
+ finderParams: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>,
90
+ locations?: LocKeyArray<L1, L2, L3, L4, L5> | []
91
+ ) => Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V]>;
92
+
82
93
  set: (
83
94
  key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>,
84
95
  v: Item<S, L1, L2, L3, L4, L5>
@@ -91,7 +102,7 @@ export interface Cache<
91
102
  cacheMap: CacheMap<V, S, L1, L2, L3, L4, L5>;
92
103
  }
93
104
 
94
- export const createCache = <
105
+ export const createCache = async <
95
106
  V extends Item<S, L1, L2, L3, L4, L5>,
96
107
  S extends string,
97
108
  L1 extends string = never,
@@ -100,13 +111,13 @@ export const createCache = <
100
111
  L4 extends string = never,
101
112
  L5 extends string = never
102
113
  >(
103
- api: ClientApi<V, S, L1, L2, L3, L4, L5>,
104
- pkType: S,
105
- parentCache?: Cache<Item<L1, L2, L3, L4, L5>, L1, L2, L3, L4, L5>
106
- ): Cache<V, S, L1, L2, L3, L4, L5> => {
114
+ api: ClientApi<V, S, L1, L2, L3, L4, L5>,
115
+ pkType: S,
116
+ parentCache?: Cache<Item<L1, L2, L3, L4, L5>, L1, L2, L3, L4, L5>
117
+ ): Promise<Cache<V, S, L1, L2, L3, L4, L5>> => {
107
118
 
108
- let pkTypes: AllItemTypeArrays<S, L1, L2, L3, L4, L5> = [ pkType ];
109
- if( parentCache ) {
119
+ let pkTypes: AllItemTypeArrays<S, L1, L2, L3, L4, L5> = [pkType];
120
+ if (parentCache) {
110
121
  pkTypes = pkTypes.concat(parentCache.pkTypes as any) as unknown as AllItemTypeArrays<S, L1, L2, L3, L4, L5>;
111
122
  }
112
123
 
@@ -264,7 +275,7 @@ export const createCache = <
264
275
  const retValue: [CacheMap<V, S, L1, L2, L3, L4, L5> | null, V | null] = [
265
276
  containsItemKey ? null : cacheMap,
266
277
  retrieved ?
267
- validatePK(retrieved, pkType) as V:
278
+ validatePK(retrieved, pkType) as V :
268
279
  null
269
280
  ];
270
281
  // logger.debug('Returning from retrieve', { retValue });
@@ -314,6 +325,16 @@ export const createCache = <
314
325
  }
315
326
  }
316
327
 
328
+ // Facets are a pass-thru for caches
329
+ const facet = async (
330
+ key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>,
331
+ facet: string,
332
+ ): Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, any]> => {
333
+ logger.default('facet', { key, facet });
334
+ const ret = await api.facet(key, facet, {});
335
+ return [cacheMap, ret];
336
+ }
337
+
317
338
  const find = async (
318
339
  finder: string,
319
340
  finderParams: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>,
@@ -327,6 +348,17 @@ export const createCache = <
327
348
  return [cacheMap, validatePK(ret, pkType) as V[]];
328
349
  }
329
350
 
351
+ const findOne = async (
352
+ finder: string,
353
+ finderParams: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>,
354
+ locations: LocKeyArray<L1, L2, L3, L4, L5> | [] = []
355
+ ): Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V]> => {
356
+ logger.default('findOne', { finder, finderParams, locations });
357
+ const ret = await api.findOne(finder, finderParams, {}, locations);
358
+ cacheMap.set(ret.key, ret);
359
+ return [cacheMap, validatePK(ret, pkType) as V];
360
+ }
361
+
330
362
  const reset = async (): Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>]> => {
331
363
  cacheMap = new CacheMap<V, S, L1, L2, L3, L4, L5>(pkTypes);
332
364
  return [cacheMap];
@@ -337,7 +369,7 @@ export const createCache = <
337
369
  v: Item<S, L1, L2, L3, L4, L5>
338
370
  ): Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V]> => {
339
371
  logger.default('set', { key, v });
340
-
372
+
341
373
  // TODO: This is validating the key, but it doesn't have knowledge of the pkType
342
374
  // This should be looking at the parentCaches and calculating an array of pkTypes
343
375
  if (!isValidItemKey(key)) {
@@ -367,7 +399,9 @@ export const createCache = <
367
399
  retrieve,
368
400
  remove,
369
401
  update,
402
+ facet,
370
403
  find,
404
+ findOne,
371
405
  reset,
372
406
  set,
373
407
  pkTypes,
@@ -7,48 +7,60 @@ const logger = LibLogger.get('CacheRegistry');
7
7
  export class CacheRegistry {
8
8
 
9
9
  private static instance: CacheRegistry;
10
- private configured: boolean = false;
11
10
 
12
11
  public constructor() {
13
- logger.debug('CacheRegistry created');
14
- }
15
-
16
- public static getInstance(
17
- ): CacheRegistry {
18
- if (!CacheRegistry.instance) {
19
- CacheRegistry.instance = new CacheRegistry();
20
- }
21
- return CacheRegistry.instance;
12
+ logger.debug('CacheRegistry instance created');
22
13
  }
23
14
 
24
15
  // TODO: My use of Generics has Boxed me into a corner where I can't reference AbstractCache without the types
25
16
  private cacheMap: { [kt: string]: any } = {};
26
17
 
27
- public registerCache = <
18
+ public registerCache = async <
28
19
  S extends string,
29
20
  L1 extends string = never,
30
21
  L2 extends string = never,
31
22
  L3 extends string = never,
32
23
  L4 extends string = never,
33
24
  L5 extends string = never
34
- >(cache: Cache<Item<S, L1, L2, L3, L4, L5>, S, L1, L2, L3, L4, L5>): void => {
35
- this.cacheMap[JSON.stringify(cache.pkTypes)] = cache;
25
+ >(cache: Cache<Item<S, L1, L2, L3, L4, L5>, S, L1, L2, L3, L4, L5>): Promise<void> => {
26
+ try {
27
+ logger.debug('Attempting to register cache with pkTypes:', cache.pkTypes);
28
+ const key = JSON.stringify(cache.pkTypes);
29
+ if (this.cacheMap[key]) {
30
+ logger.debug(`Cache with pkTypes ${key} already exists, will be overwritten`);
31
+ }
32
+ this.cacheMap[key] = cache;
33
+ logger.debug('Cache registered successfully with key:', key);
34
+ } catch (error) {
35
+ logger.error('Failed to register cache:', error);
36
+ throw error;
37
+ }
36
38
  };
37
39
 
38
- public isConfigured = (): boolean => {
39
- return this.configured;
40
- }
41
-
42
- public markConfigured = (): void => {
43
- this.configured = true;
44
- }
45
-
46
40
  public getCache = (kts: string[]): any => {
47
- if (!this.configured) {
48
- logger.error('CacheRegistry must be configured before use');
49
- throw new Error("CacheRegistry must be configured before use");
41
+ logger.debug('Attempting to get cache for key types:', kts);
42
+
43
+ const key = JSON.stringify(kts);
44
+ logger.debug('Looking up cache with key:', key);
45
+
46
+ const cache = this.cacheMap[key];
47
+ if (!cache) {
48
+ logger.warning(`No cache found for key types: ${key}`);
50
49
  }
51
- return this.cacheMap[JSON.stringify(kts)];
50
+ return cache;
52
51
  };
53
52
 
53
+ public printRegisteredCaches = (): void => {
54
+ logger.debug('Printing all registered caches:');
55
+ const cacheCount = Object.keys(this.cacheMap).length;
56
+ logger.debug(`Total number of registered caches: ${cacheCount}`);
57
+
58
+ if (cacheCount === 0) {
59
+ logger.debug('No caches are currently registered');
60
+ }
61
+
62
+ Object.entries(this.cacheMap).forEach(([keyTypes]) => {
63
+ logger.debug(`Cache with key types: ${keyTypes}`);
64
+ });
65
+ };
54
66
  }
package/src/logger.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import Logging from '@fjell/logging';
2
2
 
3
- const LibLogger = Logging.getLogger('@fjellproject/cache');
3
+ const LibLogger = Logging.getLogger('@fjell/cache');
4
4
 
5
5
  export default LibLogger;
@@ -0,0 +1,44 @@
1
+ import { defineConfig } from 'vitest/config'
2
+ import * as path from 'path'
3
+
4
+ export default defineConfig({
5
+ test: {
6
+ globals: true,
7
+ environment: 'node',
8
+ include: ['tests/**/*.test.ts'],
9
+ coverage: {
10
+ provider: 'v8',
11
+ reporter: ['text', 'json', 'html'],
12
+ exclude: [
13
+ 'node_modules/',
14
+ 'tests/',
15
+ 'src/index.ts',
16
+ 'eslint.config.mjs',
17
+ 'vite.config.ts',
18
+ 'vitest.config.ts',
19
+ 'dist',
20
+ ],
21
+ thresholds: {
22
+ lines: 89,
23
+ functions: 85,
24
+ branches: 94,
25
+ statements: 89,
26
+ },
27
+ },
28
+ setupFiles: ['./tests/setup.ts'],
29
+ deps: {
30
+ inline: [/@fjell/],
31
+ },
32
+ testTimeout: 10000,
33
+ hookTimeout: 10000,
34
+ teardownTimeout: 10000,
35
+ },
36
+ resolve: {
37
+ alias: {
38
+ '@': path.resolve(__dirname, './src'),
39
+ },
40
+ },
41
+ build: {
42
+ sourcemap: true,
43
+ },
44
+ })
package/eslint.config.mjs DELETED
@@ -1,70 +0,0 @@
1
- import typescriptEslint from "@typescript-eslint/eslint-plugin";
2
- import tsParser from "@typescript-eslint/parser";
3
- import path from "node:path";
4
- import { fileURLToPath } from "node:url";
5
- import js from "@eslint/js";
6
- import { FlatCompat } from "@eslint/eslintrc";
7
-
8
- const __filename = fileURLToPath(import.meta.url);
9
- const __dirname = path.dirname(__filename);
10
- const compat = new FlatCompat({
11
- baseDirectory: __dirname,
12
- recommendedConfig: js.configs.recommended,
13
- allConfig: js.configs.all
14
- });
15
-
16
- export default [{
17
- ignores: ["**/dist", "**/node_modules"],
18
- }, ...compat.extends("plugin:@typescript-eslint/recommended"), {
19
- plugins: {
20
- "@typescript-eslint": typescriptEslint,
21
- },
22
-
23
- languageOptions: {
24
- parser: tsParser,
25
- },
26
-
27
- rules: {
28
- "@typescript-eslint/no-unused-expressions": "off",
29
- "no-console": 0,
30
- "no-unused-vars": "off",
31
-
32
- "max-len": ["error", {
33
- code: 120,
34
- }],
35
-
36
- "max-depth": ["error", 4],
37
- "max-params": ["error", 4],
38
- "max-lines": ["error", 500],
39
-
40
- "no-multiple-empty-lines": ["error", {
41
- max: 1,
42
- maxEOF: 1,
43
- }],
44
-
45
- "no-trailing-spaces": ["error", {
46
- skipBlankLines: true,
47
- }],
48
-
49
- indent: ["error", 2, {
50
- SwitchCase: 1,
51
- }],
52
-
53
- "sort-imports": ["error", {
54
- ignoreCase: true,
55
- ignoreDeclarationSort: true,
56
- ignoreMemberSort: false,
57
- memberSyntaxSortOrder: ["none", "all", "multiple", "single"],
58
- }],
59
-
60
- "no-var": "error",
61
- "no-undefined": "error",
62
- "@typescript-eslint/no-unused-vars": "error",
63
- "@typescript-eslint/ban-ts-comment": "off",
64
- "@typescript-eslint/no-explicit-any": "off",
65
-
66
- "no-restricted-imports": ["error", {
67
- patterns: ["..*", "src/*"],
68
- }],
69
- },
70
- }];
package/vite.config.ts DELETED
@@ -1,91 +0,0 @@
1
- // import { defineConfig } from 'vite';
2
- import { defineConfig as defineVitestConfig } from 'vitest/config';
3
- import { VitePluginNode } from 'vite-plugin-node';
4
- import dts from 'vite-plugin-dts';
5
- import path from 'path';
6
-
7
- export default defineVitestConfig({
8
- server: {
9
- port: 3000
10
- },
11
- plugins: [
12
- ...VitePluginNode({
13
- adapter: 'express',
14
- appPath: './src/index.ts',
15
- exportName: 'viteNodeApp',
16
- tsCompiler: 'swc',
17
- }),
18
- // visualizer({
19
- // template: 'network',
20
- // filename: 'network.html',
21
- // projectRoot: process.cwd(),
22
- // }),
23
- dts({
24
- entryRoot: 'src',
25
- outDir: 'dist',
26
- exclude: ['./tests/**/*.ts'],
27
- include: ['./src/**/*.ts'],
28
- }),
29
- ],
30
- resolve: {
31
- alias: {
32
- '@': path.resolve(__dirname, './src'),
33
- },
34
- },
35
- build: {
36
- target: 'esnext',
37
- outDir: 'dist',
38
- lib: {
39
- entry: './src/index.ts',
40
- formats: ['es', 'cjs'],
41
- },
42
- rollupOptions: {
43
- input: 'src/index.ts',
44
- output: [
45
- {
46
- format: 'esm',
47
- entryFileNames: '[name].es.js',
48
- preserveModules: true,
49
- exports: 'named',
50
- sourcemap: 'inline',
51
- },
52
- {
53
- format: 'cjs',
54
- entryFileNames: '[name].cjs.js',
55
- preserveModules: true,
56
- exports: 'named',
57
- sourcemap: 'inline',
58
- },
59
- ],
60
- },
61
- // Make sure Vite generates ESM-compatible code
62
- modulePreload: false,
63
- minify: false,
64
- sourcemap: true
65
- },
66
- test: {
67
- include: [
68
- 'tests/**/*.test.ts',
69
- 'tests/**/*.spec.ts',
70
- ],
71
- coverage: {
72
- provider: 'v8',
73
- reporter: ['text', 'html', 'lcov'],
74
- reportsDirectory: './coverage',
75
- exclude: [
76
- 'node_modules/',
77
- 'tests/',
78
- 'src/index.ts',
79
- ],
80
- thresholds: {
81
- global: {
82
- branches: 75,
83
- functions: 89,
84
- lines: 89,
85
- statements: 89,
86
- },
87
- },
88
- },
89
- environment: 'node',
90
- },
91
- });