woonplan-packages-redishelper 1.0.88 → 1.0.91
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/dist/eventsource.d.ts +1 -1
- package/dist/eventsource.js +21 -17
- package/dist/memdb.js +4 -1
- package/dist/types.d.ts +1 -0
- package/eventsource.ts +16 -7
- package/package.json +1 -1
package/dist/eventsource.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { RedisConfig, RedisStreamEntry } from "./types";
|
|
2
|
-
declare const filterStream: (config: RedisConfig, streamname: string, key: string, value: string) => Promise<RedisStreamEntry[]>;
|
|
2
|
+
declare const filterStream: (config: RedisConfig, streamname: string, key: string, value: string, count?: number) => Promise<RedisStreamEntry[]>;
|
|
3
3
|
export { filterStream };
|
package/dist/eventsource.js
CHANGED
|
@@ -14,26 +14,30 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
14
14
|
exports.filterStream = void 0;
|
|
15
15
|
var memdb_1 = require("./memdb");
|
|
16
16
|
var getStreamInfo = function (config, streamname, count) { return (0, memdb_1.getRedisClient)(config).xinfo('stream', streamname, 'FULL', 'COUNT', count); };
|
|
17
|
-
var getEntriesFromStream = function (config, streamname) {
|
|
18
|
-
|
|
17
|
+
var getEntriesFromStream = function (config, streamname, count) {
|
|
18
|
+
if (count === void 0) { count = 0; }
|
|
19
|
+
return getStreamInfo(config, streamname, count)
|
|
19
20
|
.then(function (result) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}, {})
|
|
31
|
-
};
|
|
32
|
-
});
|
|
21
|
+
var redisStreamResult = getObjectFromStreamResult(result);
|
|
22
|
+
if (!redisStreamResult.entries)
|
|
23
|
+
return [];
|
|
24
|
+
return redisStreamResult.entries.map(function (entry) { return ({
|
|
25
|
+
id: entry[0],
|
|
26
|
+
message: entry[1].reduce(function (prevValue, currentValue, n) {
|
|
27
|
+
var _a;
|
|
28
|
+
return (n % 2 ? __assign({}, prevValue) : __assign(__assign({}, prevValue), (_a = {}, _a[currentValue] = entry[1][n + 1], _a)));
|
|
29
|
+
}, {})
|
|
30
|
+
}); });
|
|
33
31
|
});
|
|
34
32
|
};
|
|
35
|
-
var
|
|
36
|
-
|
|
33
|
+
var getObjectFromStreamResult = function (arr) { return arr.reduce(function (obj, current, n) {
|
|
34
|
+
if (!(n % 2) && arr.length + 1 >= n)
|
|
35
|
+
obj[current] = arr[n + 1];
|
|
36
|
+
return obj;
|
|
37
|
+
}, {}); };
|
|
38
|
+
var filterStream = function (config, streamname, key, value, count) {
|
|
39
|
+
if (count === void 0) { count = 0; }
|
|
40
|
+
return getEntriesFromStream(config, streamname, count)
|
|
37
41
|
.then(function (entries) { return entries.filter(function (entry) {
|
|
38
42
|
return Object.keys(entry.message).indexOf(key) > -1 && entry.message[key] == value;
|
|
39
43
|
}); });
|
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(
|
|
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
package/eventsource.ts
CHANGED
|
@@ -3,20 +3,29 @@ import { RedisConfig, RedisStreamEntry, RedisMessage } from "./types"
|
|
|
3
3
|
|
|
4
4
|
const getStreamInfo = ( config:RedisConfig, streamname:string, count:number ) => getRedisClient( config ).xinfo('stream', streamname,'FULL', 'COUNT', count )
|
|
5
5
|
|
|
6
|
-
const getEntriesFromStream = ( config:RedisConfig, streamname:string ) =>
|
|
7
|
-
getStreamInfo( config, streamname,
|
|
8
|
-
.then(( result:any ) =>
|
|
9
|
-
|
|
6
|
+
const getEntriesFromStream = ( config:RedisConfig, streamname:string, count:number = 0 ) =>
|
|
7
|
+
getStreamInfo( config, streamname, count )
|
|
8
|
+
.then(( result:any[] ) => {
|
|
9
|
+
const redisStreamResult = getObjectFromStreamResult( result )
|
|
10
|
+
if( !redisStreamResult.entries ) return []
|
|
11
|
+
|
|
12
|
+
return redisStreamResult.entries.map( (entry:[string,string[]]) => ({
|
|
10
13
|
id : entry[0],
|
|
11
14
|
message : entry[1].reduce( (prevValue:RedisMessage, currentValue:string, n:number) => (n%2 ? {...prevValue} : { ...prevValue, [currentValue] : entry[1][n+1] }) as RedisMessage, {} as RedisMessage )
|
|
12
15
|
}
|
|
13
16
|
)
|
|
14
17
|
) as RedisStreamEntry[]
|
|
15
|
-
|
|
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
|
+
}, {} )
|
|
16
25
|
|
|
17
26
|
|
|
18
|
-
const filterStream = ( config:RedisConfig, streamname:string, key:string, value:string ) =>
|
|
19
|
-
getEntriesFromStream( config, streamname )
|
|
27
|
+
const filterStream = ( config:RedisConfig, streamname:string, key:string, value:string, count:number = 0 ) =>
|
|
28
|
+
getEntriesFromStream( config, streamname, count )
|
|
20
29
|
.then((entries:RedisStreamEntry[]) => entries.filter( entry => {
|
|
21
30
|
return Object.keys( entry.message ).indexOf( key ) > -1 && entry.message[key] == value
|
|
22
31
|
}))
|