From 7868eb0ecdaa6980b8cbd619e7881d28e6ec6697 Mon Sep 17 00:00:00 2001 From: Dimitri DO BAIRRO Date: Tue, 30 Apr 2019 17:34:42 +0200 Subject: [PATCH 1/5] chore(types.ts) IRedisClientAsync interface created --- src/types.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/types.ts b/src/types.ts index 8a944b1..7efb4f6 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,3 +1,5 @@ +import { RedisClient } from 'redis'; + export interface IOptions { buckets: { meta: string; @@ -9,6 +11,19 @@ export interface IOptions { }; } +export interface IDynamicObject { + [key: string]: any // tslint:disable-line no-any +} + +export interface IRedisClientAsync extends RedisClient { + endAsync: any; // tslint:disable-line no-any + getAsync: any; // tslint:disable-line no-any + sunionAsync: any; // tslint:disable-line no-any + keysAsync: any; // tslint:disable-line no-any + delAsync: any; // tslint:disable-line no-any + smembersAsync: any; // tslint:disable-line no-any +} + export type IRolesParent = string; export type IRolesParents = IRolesParent[]; @@ -33,7 +48,3 @@ export type IRolesObjects = IRolesObject[]; export type IBucket = string export type IDemuxed = { roles: IRole | IRoles, resources: IResource | IResources, permissions: IPermission | IPermissions }; - -export interface IDynamicObject { - [key: string]: any // tslint:disable-line no-any -} From 2063725496370be11086c835135c007fb3f8f68b Mon Sep 17 00:00:00 2001 From: Dimitri DO BAIRRO Date: Tue, 30 Apr 2019 17:35:35 +0200 Subject: [PATCH 2/5] feat(stores/redis.ts) auto promisified redis commands --- src/stores/redis.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/stores/redis.ts b/src/stores/redis.ts index 0582135..70ee325 100644 --- a/src/stores/redis.ts +++ b/src/stores/redis.ts @@ -1,8 +1,8 @@ -import { isFunction } from 'lodash'; -import { Multi, RedisClient } from 'redis'; +import * as Bluebird from 'bluebird'; +import { Multi } from 'redis'; import { IStore } from '..'; import { Common } from '../classes/common'; -import { IBucket } from '../types'; +import { IBucket, IRedisClientAsync } from '../types'; /** * {@inheritDoc} @@ -10,7 +10,7 @@ import { IBucket } from '../types'; */ export class RedisStore extends Common implements IStore { public buckets: {}; - private readonly redis: RedisClient; + private readonly redis: IRedisClientAsync; private transaction: Multi; /** @@ -18,15 +18,15 @@ export class RedisStore extends Common implements IStore { * @param redis * @param prefix */ - constructor(redis: RedisClient, prefix?: string) { + constructor(redis: IRedisClientAsync, prefix?: string) { super(); - - // @ts-ignore - if (!isFunction(redis.keysAsync) || !isFunction(redis.delAsync) || !isFunction(redis.smembersAsync) || !isFunction(redis.sunionAsync)) { - throw new Error('Redis client must be promisified.'); - } - this.redis = redis; + this.redis.endAsync = Bluebird.promisify(this.redis.end); + this.redis.getAsync = Bluebird.promisify(this.redis.get); + this.redis.sunionAsync = Bluebird.promisify(this.redis.sunion); + this.redis.keysAsync = Bluebird.promisify(this.redis.keys); + this.redis.delAsync = Bluebird.promisify(this.redis.del); + this.redis.smembersAsync = Bluebird.promisify(this.redis.smembers); this.prefix = prefix !== undefined ? prefix : 'acl'; } From db34fdc48241faf9bc9fe9ed1870df8980115e77 Mon Sep 17 00:00:00 2001 From: Dimitri DO BAIRRO Date: Tue, 30 Apr 2019 17:37:08 +0200 Subject: [PATCH 3/5] feat(package.json) promisify redis methods --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7cd7eda..3072569 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ }, "homepage": "https://github.com/aclify/aclify#readme", "dependencies": { + "bluebird": "^3.5.4", "lodash": "^4.17.11" }, "devDependencies": { @@ -29,7 +30,6 @@ "@types/lodash": "^4.14.123", "@types/node": "^11.13.8", "@types/redis": "^2.8.12", - "bluebird": "^3.5.4", "jest": "^24.7.1", "mongodb": "^3.2.3", "node-mocks-http": "^1.7.3", From cea4d7cf0e00d830eb1ec43805c6068125311497 Mon Sep 17 00:00:00 2001 From: Dimitri DO BAIRRO Date: Tue, 30 Apr 2019 18:07:24 +0200 Subject: [PATCH 4/5] fix(stores/redis.ts) fix typing --- src/stores/redis.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/stores/redis.ts b/src/stores/redis.ts index 70ee325..4f53a3d 100644 --- a/src/stores/redis.ts +++ b/src/stores/redis.ts @@ -1,5 +1,5 @@ import * as Bluebird from 'bluebird'; -import { Multi } from 'redis'; +import { Multi, RedisClient } from 'redis'; import { IStore } from '..'; import { Common } from '../classes/common'; import { IBucket, IRedisClientAsync } from '../types'; @@ -18,15 +18,15 @@ export class RedisStore extends Common implements IStore { * @param redis * @param prefix */ - constructor(redis: IRedisClientAsync, prefix?: string) { + constructor(redis: RedisClient, prefix?: string) { super(); - this.redis = redis; this.redis.endAsync = Bluebird.promisify(this.redis.end); this.redis.getAsync = Bluebird.promisify(this.redis.get); this.redis.sunionAsync = Bluebird.promisify(this.redis.sunion); this.redis.keysAsync = Bluebird.promisify(this.redis.keys); this.redis.delAsync = Bluebird.promisify(this.redis.del); this.redis.smembersAsync = Bluebird.promisify(this.redis.smembers); + this.redis = redis as IRedisClientAsync; this.prefix = prefix !== undefined ? prefix : 'acl'; } From d787c853001b7d9465925e312c99c3fd88356191 Mon Sep 17 00:00:00 2001 From: Dimitri DO BAIRRO Date: Tue, 30 Apr 2019 18:14:14 +0200 Subject: [PATCH 5/5] fix(stores/redis.ts) fix redis --- src/stores/redis.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stores/redis.ts b/src/stores/redis.ts index 4f53a3d..778f224 100644 --- a/src/stores/redis.ts +++ b/src/stores/redis.ts @@ -20,13 +20,13 @@ export class RedisStore extends Common implements IStore { */ constructor(redis: RedisClient, prefix?: string) { super(); + this.redis = redis as IRedisClientAsync; this.redis.endAsync = Bluebird.promisify(this.redis.end); this.redis.getAsync = Bluebird.promisify(this.redis.get); this.redis.sunionAsync = Bluebird.promisify(this.redis.sunion); this.redis.keysAsync = Bluebird.promisify(this.redis.keys); this.redis.delAsync = Bluebird.promisify(this.redis.del); this.redis.smembersAsync = Bluebird.promisify(this.redis.smembers); - this.redis = redis as IRedisClientAsync; this.prefix = prefix !== undefined ? prefix : 'acl'; }