woonplan-packages-redishelper 1.0.89 → 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.
- package/dist/eventsource.js +9 -1
- package/eventsource.ts +12 -3
- package/package.json +1 -1
package/dist/eventsource.js
CHANGED
|
@@ -17,7 +17,10 @@ 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
|
-
|
|
20
|
+
var redisStreamResult = getObjectFromStreamResult(result);
|
|
21
|
+
if (!redisStreamResult.entries)
|
|
22
|
+
return [];
|
|
23
|
+
return redisStreamResult.entries.map(function (entry) { return ({
|
|
21
24
|
id: entry[0],
|
|
22
25
|
message: entry[1].reduce(function (prevValue, currentValue, n) {
|
|
23
26
|
var _a;
|
|
@@ -26,6 +29,11 @@ var getEntriesFromStream = function (config, streamname) {
|
|
|
26
29
|
}); });
|
|
27
30
|
});
|
|
28
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
|
+
}, {}); };
|
|
29
37
|
var filterStream = function (config, streamname, key, value) {
|
|
30
38
|
return getEntriesFromStream(config, streamname)
|
|
31
39
|
.then(function (entries) { return entries.filter(function (entry) {
|
package/eventsource.ts
CHANGED
|
@@ -5,14 +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
|
-
|
|
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
27
|
const filterStream = ( config:RedisConfig, streamname:string, key:string, value:string ) =>
|