@adaptivestone/framework 3.1.1 → 3.2.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/CHANGELOG.md +10 -0
- package/modules/AbstractController.js +22 -11
- package/package.json +1 -1
- package/services/cache/Cache.d.ts +13 -0
- package/services/cache/Cache.js +13 -1
package/CHANGELOG.md
CHANGED
|
@@ -359,11 +359,15 @@ class AbstractController extends Base {
|
|
|
359
359
|
routeMiddlewares: routeMiddlewaresReg
|
|
360
360
|
// eslint-disable-next-line consistent-return
|
|
361
361
|
.map((middleware) => {
|
|
362
|
+
const routeFullPath = route.fullPath.toUpperCase();
|
|
363
|
+
const middlewareFullPath = middleware.fullPath.toUpperCase();
|
|
364
|
+
const middlewareFullPathWithSliced = middleware.fullPath
|
|
365
|
+
.toUpperCase()
|
|
366
|
+
.slice(0, -1);
|
|
362
367
|
if (
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
`${route.fullPath.toUpperCase()}*`
|
|
368
|
+
middlewareFullPath === routeFullPath ||
|
|
369
|
+
middlewareFullPath === `${routeFullPath}*` ||
|
|
370
|
+
routeFullPath?.indexOf(middlewareFullPathWithSliced) !== -1
|
|
367
371
|
) {
|
|
368
372
|
return {
|
|
369
373
|
name: middleware.name,
|
|
@@ -376,13 +380,20 @@ class AbstractController extends Base {
|
|
|
376
380
|
controllerMiddlewares: [
|
|
377
381
|
...new Set(
|
|
378
382
|
middlewaresInfo
|
|
379
|
-
.filter(
|
|
380
|
-
(
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
383
|
+
.filter((middleware) => {
|
|
384
|
+
const routeFullPath = route.fullPath.toUpperCase();
|
|
385
|
+
const middlewareFullPath =
|
|
386
|
+
middleware.fullPath.toUpperCase();
|
|
387
|
+
const middlewareFullPathWithSliced = middleware.fullPath
|
|
388
|
+
.toUpperCase()
|
|
389
|
+
.slice(0, -1);
|
|
390
|
+
return (
|
|
391
|
+
middlewareFullPath === routeFullPath ||
|
|
392
|
+
middlewareFullPath === `${routeFullPath}*` ||
|
|
393
|
+
routeFullPath?.indexOf(middlewareFullPathWithSliced) !==
|
|
394
|
+
-1
|
|
395
|
+
);
|
|
396
|
+
})
|
|
386
397
|
.map(({ name, params, authParams }) => ({
|
|
387
398
|
name,
|
|
388
399
|
params,
|
package/package.json
CHANGED
|
@@ -6,6 +6,13 @@ declare class Cache extends Base {
|
|
|
6
6
|
|
|
7
7
|
constructor(app: Server['app']);
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* As framework support namespaces all key for cache go through this function
|
|
11
|
+
* Function return new key with added namespace
|
|
12
|
+
* @param key key to add namespace
|
|
13
|
+
*/
|
|
14
|
+
getKeyWithNameSpace(key: String): String;
|
|
15
|
+
|
|
9
16
|
/**
|
|
10
17
|
* Get value from cache. Set and get if not eists
|
|
11
18
|
* @param key key to check
|
|
@@ -17,6 +24,12 @@ declare class Cache extends Base {
|
|
|
17
24
|
onNotFound: () => Promise<any>,
|
|
18
25
|
storeTime: number,
|
|
19
26
|
): Promise<any>;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Remove key from cache
|
|
30
|
+
* @param key key to remove
|
|
31
|
+
*/
|
|
32
|
+
removeKey(key: String): Promise<number>;
|
|
20
33
|
}
|
|
21
34
|
|
|
22
35
|
export = Cache;
|
package/services/cache/Cache.js
CHANGED
|
@@ -28,11 +28,15 @@ class Cache extends Base {
|
|
|
28
28
|
this.promiseMapping = new Map();
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
getKeyWithNameSpace(key) {
|
|
32
|
+
return `${this.redisNamespace}-${key}`;
|
|
33
|
+
}
|
|
34
|
+
|
|
31
35
|
async getSetValue(keyValue, onNotFound, storeTime = 60 * 5) {
|
|
32
36
|
if (!this.redisClient.isOpen) {
|
|
33
37
|
await this.redisClient.connect();
|
|
34
38
|
}
|
|
35
|
-
const key =
|
|
39
|
+
const key = this.getKeyWithNameSpace(keyValue);
|
|
36
40
|
// 5 mins default
|
|
37
41
|
let resolve = null;
|
|
38
42
|
let reject = null;
|
|
@@ -81,6 +85,14 @@ class Cache extends Base {
|
|
|
81
85
|
return result;
|
|
82
86
|
}
|
|
83
87
|
|
|
88
|
+
async removeKey(keyValue) {
|
|
89
|
+
if (!this.redisClient.isOpen) {
|
|
90
|
+
await this.redisClient.connect();
|
|
91
|
+
}
|
|
92
|
+
const key = this.getKeyWithNameSpace(keyValue);
|
|
93
|
+
return this.redisClient.del(key);
|
|
94
|
+
}
|
|
95
|
+
|
|
84
96
|
static get loggerGroup() {
|
|
85
97
|
return 'Cache_';
|
|
86
98
|
}
|