woonplan-packages-redishelper 1.0.90 → 1.0.93

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.
@@ -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 };
@@ -10,12 +10,63 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (_) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
13
49
  Object.defineProperty(exports, "__esModule", { value: true });
14
50
  exports.filterStream = void 0;
15
51
  var memdb_1 = require("./memdb");
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
- return getStreamInfo(config, streamname, 0)
52
+ var getStreamInfo = function (config, streamname, count) { return __awaiter(void 0, void 0, void 0, function () {
53
+ var _a;
54
+ return __generator(this, function (_b) {
55
+ switch (_b.label) {
56
+ case 0:
57
+ _b.trys.push([0, 2, , 3]);
58
+ return [4 /*yield*/, (0, memdb_1.getRedisClient)(config).xinfo('stream', streamname, 'FULL', 'COUNT', count)];
59
+ case 1: return [2 /*return*/, _b.sent()];
60
+ case 2:
61
+ _a = _b.sent();
62
+ return [2 /*return*/, []];
63
+ case 3: return [2 /*return*/];
64
+ }
65
+ });
66
+ }); };
67
+ var getEntriesFromStream = function (config, streamname, count) {
68
+ if (count === void 0) { count = 0; }
69
+ return getStreamInfo(config, streamname, count)
19
70
  .then(function (result) {
20
71
  var redisStreamResult = getObjectFromStreamResult(result);
21
72
  if (!redisStreamResult.entries)
@@ -34,8 +85,9 @@ var getObjectFromStreamResult = function (arr) { return arr.reduce(function (obj
34
85
  obj[current] = arr[n + 1];
35
86
  return obj;
36
87
  }, {}); };
37
- var filterStream = function (config, streamname, key, value) {
38
- return getEntriesFromStream(config, streamname)
88
+ var filterStream = function (config, streamname, key, value, count) {
89
+ if (count === void 0) { count = 0; }
90
+ return getEntriesFromStream(config, streamname, count)
39
91
  .then(function (entries) { return entries.filter(function (entry) {
40
92
  return Object.keys(entry.message).indexOf(key) > -1 && entry.message[key] == value;
41
93
  }); });
package/eventsource.ts CHANGED
@@ -1,10 +1,16 @@
1
1
  import { getRedisClient } from "./memdb"
2
2
  import { RedisConfig, RedisStreamEntry, RedisMessage } from "./types"
3
3
 
4
- const getStreamInfo = ( config:RedisConfig, streamname:string, count:number ) => getRedisClient( config ).xinfo('stream', streamname,'FULL', 'COUNT', count )
5
-
6
- const getEntriesFromStream = ( config:RedisConfig, streamname:string ) =>
7
- getStreamInfo( config, streamname, 0 )
4
+ const getStreamInfo = async ( config:RedisConfig, streamname:string, count:number ) => {
5
+ try{
6
+ return await getRedisClient( config ).xinfo('stream', streamname,'FULL', 'COUNT', count )
7
+ }catch{
8
+ return []
9
+ }
10
+ }
11
+
12
+ const getEntriesFromStream = ( config:RedisConfig, streamname:string, count:number = 0 ) =>
13
+ getStreamInfo( config, streamname, count )
8
14
  .then(( result:any[] ) => {
9
15
  const redisStreamResult = getObjectFromStreamResult( result )
10
16
  if( !redisStreamResult.entries ) return []
@@ -24,8 +30,8 @@ const getObjectFromStreamResult = ( arr:any[] ) => arr.reduce( (obj,current,n:nu
24
30
  }, {} )
25
31
 
26
32
 
27
- const filterStream = ( config:RedisConfig, streamname:string, key:string, value:string ) =>
28
- getEntriesFromStream( config, streamname )
33
+ const filterStream = ( config:RedisConfig, streamname:string, key:string, value:string, count:number = 0 ) =>
34
+ getEntriesFromStream( config, streamname, count )
29
35
  .then((entries:RedisStreamEntry[]) => entries.filter( entry => {
30
36
  return Object.keys( entry.message ).indexOf( key ) > -1 && entry.message[key] == value
31
37
  }))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "woonplan-packages-redishelper",
3
- "version": "1.0.90",
3
+ "version": "1.0.93",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -13,14 +13,13 @@
13
13
  "author": "Jasper Denk",
14
14
  "license": "ISC",
15
15
  "devDependencies": {
16
- "@types/ioredis": "^4.28.4",
17
16
  "@types/node": "^16.11.13",
18
17
  "@types/uuid": "^8.3.4",
19
18
  "typescript": "^4.2.3"
20
19
  },
21
20
  "dependencies": {
22
- "@types/ioredis": "^4.28.5",
23
- "ioredis": "^4.28.2",
21
+ "@types/ioredis": "5.0.4",
22
+ "ioredis": "^5.0.4",
24
23
  "uuid": "^8.3.2"
25
24
  }
26
25
  }