@fjell/cache 4.4.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,17 @@
1
+ import { ClientApi } from "@fjell/client-api";
2
+ import { ComKey, Item, ItemQuery, LocKeyArray, PriKey, TypesProperties } from "@fjell/core";
3
+ import { AItemCache } from "./AItemCache";
4
+ import { CacheMap } from "./CacheMap";
5
+ export declare class CItemCache<V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never> extends AItemCache<V, S, L1, L2, L3, L4, L5> {
6
+ constructor(cacheName: string, api: ClientApi<V, S, L1, L2, L3, L4, L5>, pkType: S, parentCache: AItemCache<Item<L1, L2, L3, L4, L5, never>, L1, L2, L3, L4, L5>);
7
+ all(query?: ItemQuery, locations?: LocKeyArray<L1, L2, L3, L4, L5>): Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V[]]>;
8
+ one(query?: ItemQuery, locations?: LocKeyArray<L1, L2, L3, L4, L5>): Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V | null]>;
9
+ action(key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>, action: string, body?: any): Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V]>;
10
+ allAction(action: string, body?: any, locations?: LocKeyArray<L1, L2, L3, L4, L5>): Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V[]]>;
11
+ create(v: TypesProperties<V, S, L1, L2, L3, L4, L5>, locations?: LocKeyArray<L1, L2, L3, L4, L5>): Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V]>;
12
+ get(key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>): Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V | null]>;
13
+ retrieve(key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>): Promise<[CacheMap<V, S, L1, L2, L3, L4, L5> | null, V | null]>;
14
+ remove(key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>): Promise<CacheMap<V, S, L1, L2, L3, L4, L5>>;
15
+ 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]>;
16
+ 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[]]>;
17
+ }
@@ -0,0 +1,58 @@
1
+ import { AItemCache } from "./AItemCache";
2
+ import LibLogger from "./logger";
3
+ const logger = LibLogger.get('CItemCache');
4
+ export class CItemCache extends AItemCache {
5
+ constructor(cacheName, api, pkType, parentCache) {
6
+ super(cacheName, api, pkType, parentCache);
7
+ }
8
+ // TODO: There's something annoying about these parameters. Location isn't option in a CItem, but query is.
9
+ async all(
10
+ // istanbul ignore next
11
+ query = {}, locations) {
12
+ logger.default('all', { query, locations });
13
+ return await super.all(query, locations);
14
+ }
15
+ // TODO: There's something annoying about these parameters. Location isn't option in a CItem, but query is.
16
+ async one(
17
+ // istanbul ignore next
18
+ query = {}, locations) {
19
+ logger.default('one', { query, locations });
20
+ return await super.one(query, locations);
21
+ }
22
+ async action(key, action, body = {}) {
23
+ logger.default('action', { key, action, body });
24
+ return await super.action(key, action, body);
25
+ }
26
+ // TODO: There's something annoying about these parameters. Location isn't option in a CItem, but query is.
27
+ async allAction(action,
28
+ // istanbul ignore next
29
+ body = {}, locations) {
30
+ logger.default('action', { action, body, locations });
31
+ return await super.allAction(action, body, locations);
32
+ }
33
+ async create(v, locations) {
34
+ logger.default('create', { v });
35
+ return await super.create(v, locations);
36
+ }
37
+ async get(key) {
38
+ logger.default('get', { key });
39
+ return await super.get(key);
40
+ }
41
+ async retrieve(key) {
42
+ logger.default('retrieve', { key });
43
+ return await super.retrieve(key);
44
+ }
45
+ async remove(key) {
46
+ logger.default('remove', { key });
47
+ return await super.remove(key);
48
+ }
49
+ async update(key, v) {
50
+ logger.default('update', { key, v });
51
+ return await super.update(key, v);
52
+ }
53
+ async find(finder, finderParams, locations = []) {
54
+ logger.default('find', { finder, finderParams, locations });
55
+ return await super.find(finder, finderParams, locations);
56
+ }
57
+ }
58
+ //# sourceMappingURL=CItemCache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CItemCache.js","sourceRoot":"","sources":["../../src/CItemCache.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,SAAS,MAAM,UAAU,CAAC;AAEjC,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;AAE3C,MAAM,OAAO,UAQX,SAAQ,UAAoC;IAE5C,YACE,SAAiB,EACjB,GAAwC,EACxC,MAAS,EACT,WAA4E;QAE5E,KAAK,CAAC,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;IAC7C,CAAC;IAED,6GAA6G;IACtG,KAAK,CAAC,GAAG;IACd,uBAAuB;IACvB,QAAmB,EAAE,EACrB,SAA2C;QAG3C,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;QAC5C,OAAO,MAAM,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,SAAS,CAA8C,CAAC;IACxF,CAAC;IAED,6GAA6G;IACtG,KAAK,CAAC,GAAG;IACd,uBAAuB;IACvB,QAAmB,EAAE,EACrB,SAA2C;QAG3C,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;QAC5C,OAAO,MAAM,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,SAAS,CAAmD,CAAC;IAC7F,CAAC;IAEM,KAAK,CAAC,MAAM,CACjB,GAA8C,EAC9C,MAAc,EACd,OAAY,EAAE;Q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C,CAAC;IACvE,CAAC;IAEM,KAAK,CAAC,MAAM,CACjB,GAA8C,EAC9C,CAA4C;QAE5C,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;QACrC,OAAO,MAAM,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAA4C,CAAC;IAC/E,CAAC;IAEM,KAAK,CAAC,IAAI,CACf,MAAc,EACd,YAAwG,EACxG,YAAkD,EAAE;QAEpD,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,CAAC,CAAC;QAC5D,OAAO,MAAM,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,YAAY,EAAE,SAAS,CAA8C,CAAC;IACxG,CAAC;CAEF"}
@@ -0,0 +1,14 @@
1
+ import { ComKey, Item, ItemQuery, LocKeyArray, PriKey, TypesProperties } from "@fjell/core";
2
+ import { CacheMap } from "./CacheMap";
3
+ export interface Cache<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> {
4
+ all: (query?: ItemQuery, locations?: LocKeyArray<L1, L2, L3, L4, L5> | []) => Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V[]]>;
5
+ one: (query?: ItemQuery, locations?: LocKeyArray<L1, L2, L3, L4, L5> | []) => Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V | null]>;
6
+ action: (key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>, action: string, body?: any) => Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V]>;
7
+ allAction: (action: string, body?: any, locations?: LocKeyArray<L1, L2, L3, L4, L5> | []) => Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V[]]>;
8
+ create: (v: TypesProperties<V, S, L1, L2, L3, L4, L5>, locations?: LocKeyArray<L1, L2, L3, L4, L5> | []) => Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V]>;
9
+ get: (key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>) => Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V | null]>;
10
+ retrieve: (key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>) => Promise<[CacheMap<V, S, L1, L2, L3, L4, L5> | null, V | null]>;
11
+ remove: (key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>) => Promise<CacheMap<V, S, L1, L2, L3, L4, L5>>;
12
+ 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]>;
13
+ 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[]]>;
14
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Cache.js","sourceRoot":"","sources":["../../src/Cache.ts"],"names":[],"mappings":""}
@@ -0,0 +1,12 @@
1
+ import { AllItemTypeArrays, ComKey, Dictionary, Item, ItemQuery, LocKeyArray, PriKey } from "@fjell/core";
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
+ private types;
4
+ constructor(types: AllItemTypeArrays<S, L1, L2, L3, L4, L5>, map?: {
5
+ [key: string]: V;
6
+ });
7
+ get(key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>): V | null;
8
+ allIn(locations: LocKeyArray<L1, L2, L3, L4, L5> | []): V[];
9
+ contains(query: ItemQuery, locations: LocKeyArray<L1, L2, L3, L4, L5> | []): boolean;
10
+ queryIn(query: ItemQuery, locations?: LocKeyArray<L1, L2, L3, L4, L5> | []): V[];
11
+ clone(): CacheMap<V, S, L1, L2, L3, L4, L5>;
12
+ }
@@ -0,0 +1,85 @@
1
+ import { Dictionary, isComKey, isQueryMatch } from "@fjell/core";
2
+ import LibLogger from "./logger";
3
+ const logger = LibLogger.get("CacheMap");
4
+ // const isObj = (x: any) => typeof x === "object" && x !== null;
5
+ // const intersection = (a: object, b: object): object => {
6
+ // const result: { [key: string]: any } = {}
7
+ // if (([a, b]).every(isObj)) {
8
+ // Object.keys(a).forEach((key) => {
9
+ // // @ts-ignore
10
+ // const value = a[key]
11
+ // // @ts-ignore
12
+ // const other = b[key]
13
+ // if (isObj(value)) {
14
+ // result[key] = intersection(value, other)
15
+ // } else if (value === other) {
16
+ // result[key] = value
17
+ // }
18
+ // })
19
+ // }
20
+ // return result
21
+ // }
22
+ // const removeEmptyObjects = (obj: object): object => {
23
+ // const result: { [key: string]: any } = {}
24
+ // Object.keys(obj).forEach((key) => {
25
+ // // @ts-ignore
26
+ // const value = obj[key];
27
+ // if (isObj(value)) {
28
+ // const nested = removeEmptyObjects(value);
29
+ // if (Object.keys(nested).length > 0) {
30
+ // result[key] = nested
31
+ // }
32
+ // } else if (value !== null) {
33
+ // result[key] = value
34
+ // }
35
+ // });
36
+ // return result;
37
+ // }
38
+ export class CacheMap extends Dictionary {
39
+ types;
40
+ constructor(types, map) {
41
+ super(map);
42
+ this.types = types;
43
+ }
44
+ get(key) {
45
+ return super.get(key);
46
+ }
47
+ allIn(locations) {
48
+ if (locations.length === 0) {
49
+ logger.debug('Returning all items, LocKeys is empty');
50
+ return this.values();
51
+ }
52
+ else {
53
+ 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) => {
58
+ const ComKey = key;
59
+ logger.debug('Comparing Location Keys', {
60
+ locKeys,
61
+ ComKey,
62
+ });
63
+ return JSON.stringify(locKeys) === JSON.stringify(ComKey.loc);
64
+ })
65
+ .map((key) => this.get(key));
66
+ }
67
+ }
68
+ // TODO: Can we do case insensitive matching?
69
+ contains(query, locations) {
70
+ logger.debug('contains', { query, locations });
71
+ const items = this.allIn(locations);
72
+ return items.some((item) => isQueryMatch(item, query));
73
+ }
74
+ queryIn(query, locations = []) {
75
+ logger.debug('queryIn', { query, locations });
76
+ const items = this.allIn(locations);
77
+ return items.filter((item) => isQueryMatch(item, query));
78
+ }
79
+ clone() {
80
+ const clone = new CacheMap(this.types, this.map);
81
+ return clone;
82
+ }
83
+ }
84
+ ;
85
+ //# sourceMappingURL=CacheMap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CacheMap.js","sourceRoot":"","sources":["../../src/CacheMap.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,UAAU,EACV,QAAQ,EACR,YAAY,EAKb,MAAM,aAAa,CAAC;AACrB,OAAO,SAAS,MAAM,UAAU,CAAC;AAEjC,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;AAEzC,iEAAiE;AAEjE,2DAA2D;AAC3D,8CAA8C;AAE9C,iCAAiC;AACjC,wCAAwC;AACxC,sBAAsB;AACtB,6BAA6B;AAC7B,sBAAsB;AACtB,6BAA6B;AAE7B,4BAA4B;AAC5B,mDAAmD;AACnD,sCAAsC;AACtC,8BAA8B;AAC9B,UAAU;AACV,SAAS;AACT,MAAM;AAEN,kBAAkB;AAClB,IAAI;AAEJ,wDAAwD;AACxD,8CAA8C;AAE9C,wCAAwC;AACxC,oBAAoB;AACpB,8BAA8B;AAE9B,0BAA0B;AAC1B,kDAAkD;AAElD,8CAA8C;AAC9C,+BAA+B;AAC/B,UAAU;AACV,mCAAmC;AACnC,4BAA4B;AAC5B,QAAQ;AACR,QAAQ;AAER,mBAAmB;AACnB,IAAI;AAEJ,MAAM,OAAO,QAQX,SAAQ,UAAwD;IAExD,KAAK,CAA2C;IAExD,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EAAE,CAAC,CAAC;QAC/C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QAEpC,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;IACzD,CAAC;IAEM,OAAO,CACZ,KAAgB,EAChB,YAAkD,EAAE;QAEpD,MAAM,CAAC,KAAK,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;QAC9C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QAEpC,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;IAC3D,CAAC;IAEM,KAAK;QACV,MAAM,KAAK,GAAG,IAAI,QAAQ,CAA2B,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;QAC3E,OAAO,KAAK,CAAC;IACf,CAAC;CAEF;AAAA,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { Item } from "@fjell/core";
2
+ import { PItemCache } from "./PItemCache";
3
+ import { CItemCache } from "./CItemCache";
4
+ export declare class CacheRegistry {
5
+ private static instance;
6
+ private configured;
7
+ constructor();
8
+ static getInstance(): CacheRegistry;
9
+ private cacheMap;
10
+ 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: PItemCache<Item<S>, S> | CItemCache<Item<S, L1, L2, L3, L4, L5>, S, L1, L2, L3, L4, L5>) => void;
11
+ isConfigured: () => boolean;
12
+ markConfigured: () => void;
13
+ getCache: (kts: string[]) => any;
14
+ }
@@ -0,0 +1,34 @@
1
+ import LibLogger from './logger';
2
+ const logger = LibLogger.get('CacheRegistry');
3
+ export class CacheRegistry {
4
+ static instance;
5
+ configured = false;
6
+ constructor() {
7
+ logger.debug('CacheRegistry created');
8
+ }
9
+ static getInstance() {
10
+ if (!CacheRegistry.instance) {
11
+ CacheRegistry.instance = new CacheRegistry();
12
+ }
13
+ return CacheRegistry.instance;
14
+ }
15
+ // TODO: My use of Generics has Boxed me into a corner where I can't reference AbstractCache without the types
16
+ cacheMap = {};
17
+ registerCache = (cache) => {
18
+ this.cacheMap[JSON.stringify(cache.getKeyTypes())] = cache;
19
+ };
20
+ isConfigured = () => {
21
+ return this.configured;
22
+ };
23
+ markConfigured = () => {
24
+ this.configured = true;
25
+ };
26
+ getCache = (kts) => {
27
+ if (!this.configured) {
28
+ logger.error('CacheRegistry must be configured before use');
29
+ throw new Error("CacheRegistry must be configured before use");
30
+ }
31
+ return this.cacheMap[JSON.stringify(kts)];
32
+ };
33
+ }
34
+ //# sourceMappingURL=CacheRegistry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CacheRegistry.js","sourceRoot":"","sources":["../../src/CacheRegistry.ts"],"names":[],"mappings":"AAIA,OAAO,SAAS,MAAM,UAAU,CAAC;AAEjC,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;AAE9C,MAAM,OAAO,aAAa;IAEhB,MAAM,CAAC,QAAQ,CAAgB;IAC/B,UAAU,GAAY,KAAK,CAAC;IAEpC;QACE,MAAM,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;IACxC,CAAC;IAEM,MAAM,CAAC,WAAW;QAEvB,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC;YAC5B,aAAa,CAAC,QAAQ,GAAG,IAAI,aAAa,EAAE,CAAC;QAC/C,CAAC;QACD,OAAO,aAAa,CAAC,QAAQ,CAAC;IAChC,CAAC;IAED,8GAA8G;IACtG,QAAQ,GAA0B,EAAE,CAAC;IAEtC,aAAa,GAAG,CAOrB,KAC8D,EAAQ,EAAE;QACxE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC,GAAG,KAAK,CAAC;IAC7D,CAAC,CAAC;IAEK,YAAY,GAAG,GAAY,EAAE;QAClC,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC,CAAA;IAEM,cAAc,GAAG,GAAS,EAAE;QACjC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;IACzB,CAAC,CAAA;IAEM,QAAQ,GAAG,CAAC,GAAa,EAAO,EAAE;QACvC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACrB,MAAM,CAAC,KAAK,CAAC,6CAA6C,CAAC,CAAC;YAC5D,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;QACjE,CAAC;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5C,CAAC,CAAC;CAEH"}
@@ -0,0 +1,17 @@
1
+ import { ClientApi } from "@fjell/client-api";
2
+ import { Item, ItemQuery, PriKey, TypesProperties } from "@fjell/core";
3
+ import { AItemCache } from "./AItemCache";
4
+ import { CacheMap } from "./CacheMap";
5
+ export declare class PItemCache<V extends Item<S>, S extends string> extends AItemCache<V, S> {
6
+ constructor(cacheName: string, api: ClientApi<V, S>, pkType: S);
7
+ all(query?: ItemQuery): Promise<[CacheMap<V, S>, V[]]>;
8
+ one(query?: ItemQuery): Promise<[CacheMap<V, S>, V | null]>;
9
+ action(key: PriKey<S>, action: string, body?: any): Promise<[CacheMap<V, S>, V]>;
10
+ allAction(action: string, body?: any): Promise<[CacheMap<V, S>, V[]]>;
11
+ create(v: TypesProperties<V, S, never, never, never, never, never>): Promise<[CacheMap<V, S>, V]>;
12
+ get(key: PriKey<S>): Promise<[CacheMap<V, S>, V | null]>;
13
+ retrieve(key: PriKey<S>): Promise<[CacheMap<V, S> | null, V | null]>;
14
+ remove(key: PriKey<S>): Promise<CacheMap<V, S>>;
15
+ update(key: PriKey<S>, v: TypesProperties<V, S>): Promise<[CacheMap<V, S>, V]>;
16
+ find(finder: string, finderParams: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>): Promise<[CacheMap<V, S>, V[]]>;
17
+ }
@@ -0,0 +1,50 @@
1
+ /* eslint-disable no-undefined, max-params */
2
+ import { AItemCache } from "./AItemCache";
3
+ import LibLogger from './logger';
4
+ const logger = LibLogger.get('PItemCache');
5
+ export class PItemCache extends AItemCache {
6
+ constructor(cacheName, api, pkType) {
7
+ super(cacheName, api, pkType);
8
+ }
9
+ async all(query = {}) {
10
+ logger.default('all', { query });
11
+ return await super.all(query);
12
+ }
13
+ async one(query = {}) {
14
+ logger.default('one', { query });
15
+ return await super.one(query);
16
+ }
17
+ async action(key, action, body = {}) {
18
+ logger.default('action', { key, action, body });
19
+ return await super.action(key, action, body);
20
+ }
21
+ async allAction(action, body = {}) {
22
+ logger.default('action', { action, body });
23
+ return await super.allAction(action, body);
24
+ }
25
+ async create(v) {
26
+ logger.default('create', { v });
27
+ return await super.create(v);
28
+ }
29
+ async get(key) {
30
+ logger.default('get', { key });
31
+ return await super.get(key);
32
+ }
33
+ async retrieve(key) {
34
+ logger.default('retrieve', { key });
35
+ return await super.retrieve(key);
36
+ }
37
+ async remove(key) {
38
+ logger.default('remove', { key });
39
+ return await super.remove(key);
40
+ }
41
+ async update(key, v) {
42
+ logger.default('update', { key, v });
43
+ return await super.update(key, v);
44
+ }
45
+ async find(finder, finderParams) {
46
+ logger.default('find', { finder, finderParams });
47
+ return await super.find(finder, finderParams);
48
+ }
49
+ }
50
+ //# sourceMappingURL=PItemCache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PItemCache.js","sourceRoot":"","sources":["../../src/PItemCache.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAI7C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,SAAS,MAAM,UAAU,CAAC;AAEjC,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,CAAC,YAAY,CA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AG,CAAC,GAAc;QAE7B,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;QAC/B,OAAO,MAAM,KAAK,CAAC,GAAG,CAAC,GAAG,CAA+B,CAAC;IAC5D,CAAC;IAEM,KAAK,CAAC,QAAQ,CACnB,GAAc;QAEd,MAAM,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;QACpC,OAAO,MAAM,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAsC,CAAC;IACxE,CAAC;IAEM,KAAK,CAAC,MAAM,CACjB,GAAc;QAEd,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;QAClC,OAAO,MAAM,KAAK,CAAC,MAAM,CAAC,GAAG,CAAmB,CAAC;IACnD,CAAC;IAEM,KAAK,CAAC,MAAM,CACjB,GAAc,EACd,CAAwB;QAExB,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;QACrC,OAAO,MAAM,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAwB,CAAC;IAC3D,CAAC;IAEM,KAAK,CAAC,IAAI,CACf,MAAc,EACd,YAAwG;QAExG,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,CAAC;QACjD,OAAO,MAAM,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,YAAY,CAA0B,CAAC;IACzE,CAAC;CAEF"}
@@ -0,0 +1,7 @@
1
+ export { Cache } from "./Cache";
2
+ export { CacheMap } from "./CacheMap";
3
+ export { CacheRegistry } from "./CacheRegistry";
4
+ export { AggregateConfig, AItemAggregator } from "./AItemAggregator";
5
+ export { AItemCache } from "./AItemCache";
6
+ export { CItemCache } from "./CItemCache";
7
+ export { PItemCache } from "./PItemCache";
@@ -0,0 +1,7 @@
1
+ export { CacheMap } from "./CacheMap";
2
+ export { CacheRegistry } from "./CacheRegistry";
3
+ export { AItemAggregator } from "./AItemAggregator";
4
+ export { AItemCache } from "./AItemCache";
5
+ export { CItemCache } from "./CItemCache";
6
+ export { PItemCache } from "./PItemCache";
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAmB,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAErE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,2 @@
1
+ declare const LibLogger: import("@fjell/logging").Logger;
2
+ export default LibLogger;
@@ -0,0 +1,4 @@
1
+ import Logging from '@fjell/logging';
2
+ const LibLogger = Logging.getLogger('@fjellproject/cache');
3
+ export default LibLogger;
4
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,gBAAgB,CAAC;AAErC,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,qBAAqB,CAAC,CAAC;AAE3D,eAAe,SAAS,CAAC"}
@@ -0,0 +1 @@
1
+ {"root":["../src/AItemAggregator.ts","../src/AItemCache.ts","../src/CItemCache.ts","../src/Cache.ts","../src/CacheMap.ts","../src/CacheRegistry.ts","../src/PItemCache.ts","../src/index.ts","../src/logger.ts","../tests/AItemAggregator.test.ts","../tests/AItemCache.test.ts","../tests/CItemCache.test.ts","../tests/CacheMap.test.ts","../tests/CacheRegistry.test.ts","../tests/PItemCache.test.ts"],"version":"5.7.3"}
@@ -0,0 +1,70 @@
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/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@fjell/cache",
3
+ "description": "Cache for Fjell",
4
+ "version": "4.4.0",
5
+ "license": "Apache-2.0",
6
+ "main": "./dist/src/index.js",
7
+ "exports": {
8
+ ".": {
9
+ "require": "./dist/src/index.js",
10
+ "types": "./dist/src/index.d.ts",
11
+ "default": "./dist/src/index.js"
12
+ }
13
+ },
14
+ "type": "module",
15
+ "scripts": {
16
+ "lint": "eslint .",
17
+ "dev": "concurrently \"tsc --watch\" \"tsc-alias -w\"",
18
+ "build": "yarn run lint && tsc --build --verbose --force && tsc-alias -p tsconfig.json",
19
+ "clean": "rimraf dist",
20
+ "test": "yarn run lint && NODE_OPTIONS='--experimental-require-module' yarn run jest --coverage"
21
+ },
22
+ "dependencies": {
23
+ "@fjell/client-api": "^4.3.0",
24
+ "@fjell/core": "^4.3.1",
25
+ "@fjell/http-api": "^4.3.0",
26
+ "@fjell/logging": "^4.3.4",
27
+ "d3": "^7.9.0",
28
+ "dayjs": "^1.11.13",
29
+ "react": "18.3.1"
30
+ },
31
+ "devDependencies": {
32
+ "@babel/preset-env": "^7.26.9",
33
+ "@babel/preset-typescript": "^7.26.0",
34
+ "@jest/globals": "^29.7.0",
35
+ "@tsconfig/recommended": "^1.0.8",
36
+ "@types/babel__preset-env": "^7",
37
+ "@types/d3": "^7.4.3",
38
+ "@types/jest": "^29.5.14",
39
+ "@types/multer": "^1.4.12",
40
+ "@types/node": "^22.13.5",
41
+ "@typescript-eslint/eslint-plugin": "^8.24.1",
42
+ "@typescript-eslint/parser": "^8.24.1",
43
+ "babel-jest": "^29.7.0",
44
+ "concurrently": "^9.1.2",
45
+ "eslint": "^9.21.0",
46
+ "jest": "^29.7.0",
47
+ "nodemon": "^3.1.9",
48
+ "rimraf": "^6.0.1",
49
+ "ts-jest": "^29.2.5",
50
+ "ts-node": "^10.9.2",
51
+ "tsc-alias": "^1.8.10",
52
+ "typescript": "^5.7.3"
53
+ },
54
+ "packageManager": "yarn@4.6.0",
55
+ "repository": {
56
+ "type": "git",
57
+ "url": "git+https://github.com/getfjell/cache.git"
58
+ }
59
+ }