@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 CHANGED
@@ -1,3 +1,13 @@
1
+ ### 3.2.1
2
+
3
+ [UPDATE] updated deps
4
+ [FIX] fix documentation generation
5
+
6
+ ### 3.2.0
7
+
8
+ [UPDATE] updated deps
9
+ [NEW] cache.removeKey(key) - function to remove key from cache
10
+
1
11
  ### 3.1.1
2
12
 
3
13
  [UPDATE] updated deps
@@ -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
- route.fullPath.toUpperCase() ===
364
- middleware.fullPath.toUpperCase() ||
365
- middleware.fullPath.toUpperCase() ===
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
- (middleware) =>
381
- middleware.fullPath.toUpperCase() ===
382
- route.fullPath.toUpperCase() ||
383
- middleware.fullPath.toUpperCase() ===
384
- `${route.fullPath.toUpperCase()}*`,
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adaptivestone/framework",
3
- "version": "3.1.1",
3
+ "version": "3.2.1",
4
4
  "description": "Adaptive stone node js framework",
5
5
  "main": "src/index.js",
6
6
  "engines": {
@@ -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;
@@ -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 = `${this.redisNamespace}-${keyValue}`;
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
  }