woonplan-packages-redishelper 1.0.87 → 1.0.90

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.
@@ -17,21 +17,23 @@ var getStreamInfo = function (config, streamname, count) { return (0, memdb_1.ge
17
17
  var getEntriesFromStream = function (config, streamname) {
18
18
  return getStreamInfo(config, streamname, 0)
19
19
  .then(function (result) {
20
- return result[9].map(function (entry) {
21
- var keysandvalues = entry[1];
22
- return {
23
- id: entry[0],
24
- message: keysandvalues.reduce(function (prevValue, currentValue, n) {
25
- if (n % 2)
26
- return __assign({}, prevValue);
27
- var newStruct = __assign({}, prevValue);
28
- newStruct[currentValue] = keysandvalues[n + 1];
29
- return newStruct;
30
- }, {})
31
- };
32
- });
20
+ var redisStreamResult = getObjectFromStreamResult(result);
21
+ if (!redisStreamResult.entries)
22
+ return [];
23
+ return redisStreamResult.entries.map(function (entry) { return ({
24
+ id: entry[0],
25
+ message: entry[1].reduce(function (prevValue, currentValue, n) {
26
+ var _a;
27
+ return (n % 2 ? __assign({}, prevValue) : __assign(__assign({}, prevValue), (_a = {}, _a[currentValue] = entry[1][n + 1], _a)));
28
+ }, {})
29
+ }); });
33
30
  });
34
31
  };
32
+ var getObjectFromStreamResult = function (arr) { return arr.reduce(function (obj, current, n) {
33
+ if (!(n % 2) && arr.length + 1 >= n)
34
+ obj[current] = arr[n + 1];
35
+ return obj;
36
+ }, {}); };
35
37
  var filterStream = function (config, streamname, key, value) {
36
38
  return getEntriesFromStream(config, streamname)
37
39
  .then(function (entries) { return entries.filter(function (entry) {
package/dist/memdb.js CHANGED
@@ -2,5 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getRedisClient = void 0;
4
4
  var IORedis = require("ioredis");
5
- var getRedisClient = function (config) { return new IORedis(config.REDISURL); };
5
+ var getRedisClient = function (config) { return new IORedis({
6
+ host: config.REDISURL,
7
+ password: config.REDISPW
8
+ }); };
6
9
  exports.getRedisClient = getRedisClient;
package/dist/types.d.ts CHANGED
@@ -6,6 +6,7 @@ export interface Struct {
6
6
  }
7
7
  export interface RedisConfig {
8
8
  REDISURL: string | number | undefined;
9
+ REDISPW: string | undefined;
9
10
  }
10
11
  export interface RedisStreamEntry {
11
12
  id: string;
package/eventsource.ts CHANGED
@@ -5,22 +5,23 @@ const getStreamInfo = ( config:RedisConfig, streamname:string, count:number ) =>
5
5
 
6
6
  const getEntriesFromStream = ( config:RedisConfig, streamname:string ) =>
7
7
  getStreamInfo( config, streamname, 0 )
8
- .then(( result:any ) =>
9
- result[9].map( (entry:[string,string[]]) => {
10
- const keysandvalues = entry[1]
11
- return {
8
+ .then(( result:any[] ) => {
9
+ const redisStreamResult = getObjectFromStreamResult( result )
10
+ if( !redisStreamResult.entries ) return []
11
+
12
+ return redisStreamResult.entries.map( (entry:[string,string[]]) => ({
12
13
  id : entry[0],
13
- message : keysandvalues.reduce( (prevValue:RedisMessage, currentValue:string, n:number) => {
14
- if( n%2 ) return {
15
- ...prevValue
16
- }
17
- const newStruct:RedisMessage = { ...prevValue }
18
- newStruct[currentValue] = keysandvalues[n+1]
19
- return newStruct
20
- }, {} as RedisMessage )
21
- } as RedisStreamEntry
22
- })
23
- )
14
+ message : entry[1].reduce( (prevValue:RedisMessage, currentValue:string, n:number) => (n%2 ? {...prevValue} : { ...prevValue, [currentValue] : entry[1][n+1] }) as RedisMessage, {} as RedisMessage )
15
+ }
16
+ )
17
+ ) as RedisStreamEntry[]
18
+ })
19
+
20
+
21
+ const getObjectFromStreamResult = ( arr:any[] ) => arr.reduce( (obj,current,n:number) => {
22
+ if( !(n % 2) && arr.length+1 >= n ) obj[current] = arr[n+1]
23
+ return obj
24
+ }, {} )
24
25
 
25
26
 
26
27
  const filterStream = ( config:RedisConfig, streamname:string, key:string, value:string ) =>
package/memdb.ts CHANGED
@@ -2,6 +2,9 @@ import { RedisConfig } from "./types"
2
2
  import { Redis } from "ioredis"
3
3
  const IORedis = require("ioredis");
4
4
 
5
- const getRedisClient = ( config:RedisConfig ):Redis => new IORedis( config.REDISURL );
5
+ const getRedisClient = ( config:RedisConfig ):Redis => new IORedis({
6
+ host : config.REDISURL,
7
+ password : config.REDISPW
8
+ })
6
9
 
7
10
  export { getRedisClient }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "woonplan-packages-redishelper",
3
- "version": "1.0.87",
3
+ "version": "1.0.90",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/types.ts CHANGED
@@ -7,6 +7,7 @@ export interface Struct{
7
7
 
8
8
  export interface RedisConfig{
9
9
  REDISURL: string | number | undefined;
10
+ REDISPW: string | undefined
10
11
  }
11
12
 
12
13
  export interface RedisStreamEntry{