@fjell/cache 4.5.2 → 4.6.0

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,108 @@
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
+ function _define_property(obj, key, value) {
9
+ if (key in obj) {
10
+ Object.defineProperty(obj, key, {
11
+ value: value,
12
+ enumerable: true,
13
+ configurable: true,
14
+ writable: true
15
+ });
16
+ } else {
17
+ obj[key] = value;
18
+ }
19
+ return obj;
20
+ }
21
+ const logger = logger$1.default.get("CacheMap");
22
+ // const isObj = (x: any) => typeof x === "object" && x !== null;
23
+ // const intersection = (a: object, b: object): object => {
24
+ // const result: { [key: string]: any } = {}
25
+ // if (([a, b]).every(isObj)) {
26
+ // Object.keys(a).forEach((key) => {
27
+ // // @ts-ignore
28
+ // const value = a[key]
29
+ // // @ts-ignore
30
+ // const other = b[key]
31
+ // if (isObj(value)) {
32
+ // result[key] = intersection(value, other)
33
+ // } else if (value === other) {
34
+ // result[key] = value
35
+ // }
36
+ // })
37
+ // }
38
+ // return result
39
+ // }
40
+ // const removeEmptyObjects = (obj: object): object => {
41
+ // const result: { [key: string]: any } = {}
42
+ // Object.keys(obj).forEach((key) => {
43
+ // // @ts-ignore
44
+ // const value = obj[key];
45
+ // if (isObj(value)) {
46
+ // const nested = removeEmptyObjects(value);
47
+ // if (Object.keys(nested).length > 0) {
48
+ // result[key] = nested
49
+ // }
50
+ // } else if (value !== null) {
51
+ // result[key] = value
52
+ // }
53
+ // });
54
+ // return result;
55
+ // }
56
+ class CacheMap extends core.Dictionary {
57
+ get(key) {
58
+ return super.get(key);
59
+ }
60
+ allIn(locations) {
61
+ if (locations.length === 0) {
62
+ logger.debug('Returning all items, LocKeys is empty');
63
+ return this.values();
64
+ } else {
65
+ const locKeys = locations;
66
+ logger.debug('allIn', {
67
+ locKeys,
68
+ keys: this.keys().length
69
+ });
70
+ return this.keys().filter((key)=>key && core.isComKey(key)).filter((key)=>{
71
+ const ComKey = key;
72
+ logger.debug('Comparing Location Keys', {
73
+ locKeys,
74
+ ComKey
75
+ });
76
+ return JSON.stringify(locKeys) === JSON.stringify(ComKey.loc);
77
+ }).map((key)=>this.get(key));
78
+ }
79
+ }
80
+ // TODO: Can we do case insensitive matching?
81
+ contains(query, locations) {
82
+ logger.debug('contains', {
83
+ query,
84
+ locations
85
+ });
86
+ const items = this.allIn(locations);
87
+ return items.some((item)=>core.isQueryMatch(item, query));
88
+ }
89
+ queryIn(query, locations = []) {
90
+ logger.debug('queryIn', {
91
+ query,
92
+ locations
93
+ });
94
+ const items = this.allIn(locations);
95
+ return items.filter((item)=>core.isQueryMatch(item, query));
96
+ }
97
+ clone() {
98
+ const clone = new CacheMap(this.types, this.map);
99
+ return clone;
100
+ }
101
+ constructor(types, map){
102
+ super(map), _define_property(this, "types", void 0);
103
+ this.types = types;
104
+ }
105
+ }
106
+
107
+ exports.CacheMap = CacheMap;
108
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ2FjaGVNYXAuY2pzLmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
@@ -1,4 +1,4 @@
1
- import { AllItemTypeArrays, ComKey, Dictionary, Item, ItemQuery, LocKeyArray, PriKey } from "@fjell/core";
1
+ import { AllItemTypeArrays, ComKey, Dictionary, Item, ItemQuery, LocKeyArray, PriKey } from '@fjell/core';
2
2
  export declare class CacheMap<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> extends Dictionary<ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>, V> {
3
3
  private types;
4
4
  constructor(types: AllItemTypeArrays<S, L1, L2, L3, L4, L5>, map?: {
@@ -1,5 +1,19 @@
1
- import { Dictionary, isComKey, isQueryMatch } from "@fjell/core";
2
- import LibLogger from "./logger";
1
+ import { Dictionary, isComKey, isQueryMatch } from '@fjell/core';
2
+ import LibLogger from './logger.es.js';
3
+
4
+ function _define_property(obj, key, value) {
5
+ if (key in obj) {
6
+ Object.defineProperty(obj, key, {
7
+ value: value,
8
+ enumerable: true,
9
+ configurable: true,
10
+ writable: true
11
+ });
12
+ } else {
13
+ obj[key] = value;
14
+ }
15
+ return obj;
16
+ }
3
17
  const logger = LibLogger.get("CacheMap");
4
18
  // const isObj = (x: any) => typeof x === "object" && x !== null;
5
19
  // const intersection = (a: object, b: object): object => {
@@ -35,12 +49,7 @@ const logger = LibLogger.get("CacheMap");
35
49
  // });
36
50
  // return result;
37
51
  // }
38
- export class CacheMap extends Dictionary {
39
- types;
40
- constructor(types, map) {
41
- super(map);
42
- this.types = types;
43
- }
52
+ class CacheMap extends Dictionary {
44
53
  get(key) {
45
54
  return super.get(key);
46
55
  }
@@ -48,38 +57,48 @@ export class CacheMap extends Dictionary {
48
57
  if (locations.length === 0) {
49
58
  logger.debug('Returning all items, LocKeys is empty');
50
59
  return this.values();
51
- }
52
- else {
60
+ } else {
53
61
  const locKeys = locations;
54
- logger.debug('allIn', { locKeys, keys: this.keys().length });
55
- return this.keys()
56
- .filter((key) => key && isComKey(key))
57
- .filter((key) => {
62
+ logger.debug('allIn', {
63
+ locKeys,
64
+ keys: this.keys().length
65
+ });
66
+ return this.keys().filter((key)=>key && isComKey(key)).filter((key)=>{
58
67
  const ComKey = key;
59
68
  logger.debug('Comparing Location Keys', {
60
69
  locKeys,
61
- ComKey,
70
+ ComKey
62
71
  });
63
72
  return JSON.stringify(locKeys) === JSON.stringify(ComKey.loc);
64
- })
65
- .map((key) => this.get(key));
73
+ }).map((key)=>this.get(key));
66
74
  }
67
75
  }
68
76
  // TODO: Can we do case insensitive matching?
69
77
  contains(query, locations) {
70
- logger.debug('contains', { query, locations });
78
+ logger.debug('contains', {
79
+ query,
80
+ locations
81
+ });
71
82
  const items = this.allIn(locations);
72
- return items.some((item) => isQueryMatch(item, query));
83
+ return items.some((item)=>isQueryMatch(item, query));
73
84
  }
74
85
  queryIn(query, locations = []) {
75
- logger.debug('queryIn', { query, locations });
86
+ logger.debug('queryIn', {
87
+ query,
88
+ locations
89
+ });
76
90
  const items = this.allIn(locations);
77
- return items.filter((item) => isQueryMatch(item, query));
91
+ return items.filter((item)=>isQueryMatch(item, query));
78
92
  }
79
93
  clone() {
80
94
  const clone = new CacheMap(this.types, this.map);
81
95
  return clone;
82
96
  }
97
+ constructor(types, map){
98
+ super(map), _define_property(this, "types", void 0);
99
+ this.types = types;
100
+ }
83
101
  }
84
- ;
85
- //# sourceMappingURL=CacheMap.js.map
102
+
103
+ export { CacheMap };
104
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ2FjaGVNYXAuZXMuanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
@@ -0,0 +1,54 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const logger$1 = require('./logger.cjs.js');
6
+
7
+ function _define_property(obj, key, value) {
8
+ if (key in obj) {
9
+ Object.defineProperty(obj, key, {
10
+ value: value,
11
+ enumerable: true,
12
+ configurable: true,
13
+ writable: true
14
+ });
15
+ } else {
16
+ obj[key] = value;
17
+ }
18
+ return obj;
19
+ }
20
+ const logger = logger$1.default.get('CacheRegistry');
21
+ class CacheRegistry {
22
+ static getInstance() {
23
+ if (!CacheRegistry.instance) {
24
+ CacheRegistry.instance = new CacheRegistry();
25
+ }
26
+ return CacheRegistry.instance;
27
+ }
28
+ constructor(){
29
+ _define_property(this, "configured", false);
30
+ // TODO: My use of Generics has Boxed me into a corner where I can't reference AbstractCache without the types
31
+ _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;
40
+ });
41
+ _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");
45
+ }
46
+ return this.cacheMap[JSON.stringify(kts)];
47
+ });
48
+ logger.debug('CacheRegistry created');
49
+ }
50
+ }
51
+ _define_property(CacheRegistry, "instance", void 0);
52
+
53
+ exports.CacheRegistry = CacheRegistry;
54
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ2FjaGVSZWdpc3RyeS5janMuanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0=
@@ -1,5 +1,5 @@
1
- import { Item } from "@fjell/core";
2
- import { Cache } from "./Cache";
1
+ import { Item } from '@fjell/core';
2
+ import { Cache } from './Cache';
3
3
  export declare class CacheRegistry {
4
4
  private static instance;
5
5
  private configured;
@@ -0,0 +1,50 @@
1
+ import LibLogger from './logger.es.js';
2
+
3
+ function _define_property(obj, key, value) {
4
+ if (key in obj) {
5
+ Object.defineProperty(obj, key, {
6
+ value: value,
7
+ enumerable: true,
8
+ configurable: true,
9
+ writable: true
10
+ });
11
+ } else {
12
+ obj[key] = value;
13
+ }
14
+ return obj;
15
+ }
16
+ const logger = LibLogger.get('CacheRegistry');
17
+ class CacheRegistry {
18
+ static getInstance() {
19
+ if (!CacheRegistry.instance) {
20
+ CacheRegistry.instance = new CacheRegistry();
21
+ }
22
+ return CacheRegistry.instance;
23
+ }
24
+ constructor(){
25
+ _define_property(this, "configured", false);
26
+ // TODO: My use of Generics has Boxed me into a corner where I can't reference AbstractCache without the types
27
+ _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;
36
+ });
37
+ _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");
41
+ }
42
+ return this.cacheMap[JSON.stringify(kts)];
43
+ });
44
+ logger.debug('CacheRegistry created');
45
+ }
46
+ }
47
+ _define_property(CacheRegistry, "instance", void 0);
48
+
49
+ export { CacheRegistry };
50
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ2FjaGVSZWdpc3RyeS5lcy5qcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9