@autofleet/matmon 2.1.1 → 2.1.2-beta-1
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.
- package/lib/cache.d.ts +2 -1
- package/lib/cache.js +8 -2
- package/lib/index.d.ts +2 -2
- package/lib/index.js +2 -1
- package/package.json +1 -1
package/lib/cache.d.ts
CHANGED
|
@@ -6,8 +6,9 @@ export declare const getWithCacheSupport: ({ cacheKey, cacheGet, cacheSet, fetch
|
|
|
6
6
|
fetching: any;
|
|
7
7
|
skipCache: any;
|
|
8
8
|
}) => Promise<any>;
|
|
9
|
-
export declare const getMultipleWithCache: ({ getFromCache, setInCache, getter, multiGetter, idField, }: {
|
|
9
|
+
export declare const getMultipleWithCache: ({ getFromCache, multiGetterFromCache, setInCache, getter, multiGetter, idField, }: {
|
|
10
10
|
getFromCache: any;
|
|
11
|
+
multiGetterFromCache: any;
|
|
11
12
|
setInCache: any;
|
|
12
13
|
getter?: any;
|
|
13
14
|
multiGetter?: any;
|
package/lib/cache.js
CHANGED
|
@@ -83,11 +83,17 @@ const getIdField = (query, idField) => {
|
|
|
83
83
|
}
|
|
84
84
|
return query[idField];
|
|
85
85
|
};
|
|
86
|
-
exports.getMultipleWithCache = ({ getFromCache, setInCache, getter = undefined, multiGetter = undefined, idField = 'id', }) => async (queries) => {
|
|
86
|
+
exports.getMultipleWithCache = ({ getFromCache, multiGetterFromCache, setInCache, getter = undefined, multiGetter = undefined, idField = 'id', }) => async (queries) => {
|
|
87
87
|
const queriesMap = new Map(queries.filter(Boolean).map(query => [getIdField(query, idField), query]));
|
|
88
88
|
const resultMap = new Map();
|
|
89
89
|
const valuesToPullFromCache = [...queriesMap.values()];
|
|
90
|
-
|
|
90
|
+
let valuesFromCache;
|
|
91
|
+
if (multiGetterFromCache) {
|
|
92
|
+
valuesFromCache = await multiGetterFromCache(valuesToPullFromCache);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
valuesFromCache = await Promise.all(valuesToPullFromCache.map(query => getFromCache(query)));
|
|
96
|
+
}
|
|
91
97
|
valuesFromCache.filter(Boolean).map((value) => {
|
|
92
98
|
queriesMap.delete(getIdField(value, idField));
|
|
93
99
|
resultMap.set(getIdField(value, idField), value);
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getNewLRU, getWithCacheSupport } from './cache';
|
|
1
|
+
import { getNewLRU, getWithCacheSupport, getMultipleWithCache } from './cache';
|
|
2
2
|
import RedisCache from './redis';
|
|
3
3
|
import { ORMCache, ORMTypes } from './orm-cache';
|
|
4
|
-
export { getNewLRU, getWithCacheSupport, RedisCache, ORMCache, ORMTypes };
|
|
4
|
+
export { getNewLRU, getWithCacheSupport, getMultipleWithCache, RedisCache, ORMCache, ORMTypes };
|
package/lib/index.js
CHANGED
|
@@ -3,10 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ORMTypes = exports.ORMCache = exports.RedisCache = exports.getWithCacheSupport = exports.getNewLRU = void 0;
|
|
6
|
+
exports.ORMTypes = exports.ORMCache = exports.RedisCache = exports.getMultipleWithCache = exports.getWithCacheSupport = exports.getNewLRU = void 0;
|
|
7
7
|
const cache_1 = require("./cache");
|
|
8
8
|
Object.defineProperty(exports, "getNewLRU", { enumerable: true, get: function () { return cache_1.getNewLRU; } });
|
|
9
9
|
Object.defineProperty(exports, "getWithCacheSupport", { enumerable: true, get: function () { return cache_1.getWithCacheSupport; } });
|
|
10
|
+
Object.defineProperty(exports, "getMultipleWithCache", { enumerable: true, get: function () { return cache_1.getMultipleWithCache; } });
|
|
10
11
|
const redis_1 = __importDefault(require("./redis"));
|
|
11
12
|
exports.RedisCache = redis_1.default;
|
|
12
13
|
const orm_cache_1 = require("./orm-cache");
|