@hotmeshio/hotmesh 0.3.6 → 0.3.7

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.
Files changed (120) hide show
  1. package/build/index.d.ts +2 -1
  2. package/build/index.js +7 -1
  3. package/build/modules/key.js +1 -62
  4. package/build/modules/utils.js +1 -267
  5. package/build/package.json +12 -8
  6. package/build/services/activities/activity.js +1 -495
  7. package/build/services/activities/await.js +1 -109
  8. package/build/services/activities/cycle.js +1 -96
  9. package/build/services/activities/hook.js +1 -154
  10. package/build/services/activities/index.js +1 -20
  11. package/build/services/activities/interrupt.js +1 -149
  12. package/build/services/activities/signal.js +1 -118
  13. package/build/services/activities/trigger.js +1 -237
  14. package/build/services/activities/worker.js +1 -101
  15. package/build/services/collator/index.js +1 -197
  16. package/build/services/compiler/deployer.d.ts +3 -1
  17. package/build/services/compiler/deployer.js +1 -455
  18. package/build/services/compiler/index.d.ts +3 -1
  19. package/build/services/compiler/index.js +1 -91
  20. package/build/services/compiler/validator.js +1 -122
  21. package/build/services/engine/index.d.ts +5 -2
  22. package/build/services/engine/index.js +1 -562
  23. package/build/services/exporter/index.js +1 -93
  24. package/build/services/mapper/index.js +1 -67
  25. package/build/services/meshdata/index.d.ts +0 -1
  26. package/build/services/meshdata/index.js +16 -24
  27. package/build/services/meshflow/client.js +4 -8
  28. package/build/services/meshflow/exporter.js +1 -186
  29. package/build/services/meshflow/search.d.ts +4 -5
  30. package/build/services/meshflow/search.js +45 -35
  31. package/build/services/meshflow/workflow.d.ts +1 -1
  32. package/build/services/meshflow/workflow.js +3 -28
  33. package/build/services/pipe/functions/array.js +1 -74
  34. package/build/services/pipe/functions/bitwise.js +1 -24
  35. package/build/services/pipe/functions/conditional.js +1 -36
  36. package/build/services/pipe/functions/cron.js +1 -32
  37. package/build/services/pipe/functions/date.js +1 -164
  38. package/build/services/pipe/functions/index.js +1 -30
  39. package/build/services/pipe/functions/json.js +1 -12
  40. package/build/services/pipe/functions/logical.js +1 -12
  41. package/build/services/pipe/functions/math.js +1 -182
  42. package/build/services/pipe/functions/number.js +1 -60
  43. package/build/services/pipe/functions/object.js +1 -81
  44. package/build/services/pipe/functions/string.js +1 -69
  45. package/build/services/pipe/functions/symbol.js +1 -33
  46. package/build/services/pipe/functions/unary.js +1 -18
  47. package/build/services/pipe/index.js +1 -221
  48. package/build/services/quorum/index.d.ts +1 -1
  49. package/build/services/quorum/index.js +1 -219
  50. package/build/services/reporter/index.js +1 -331
  51. package/build/services/router/index.js +1 -420
  52. package/build/services/search/factory.d.ts +7 -0
  53. package/build/services/search/factory.js +20 -0
  54. package/build/services/search/index.d.ts +21 -0
  55. package/build/services/search/index.js +10 -0
  56. package/build/services/search/providers/redis/ioredis.d.ts +18 -0
  57. package/build/services/search/providers/redis/ioredis.js +1 -0
  58. package/build/services/search/providers/redis/redis.d.ts +18 -0
  59. package/build/services/search/providers/redis/redis.js +1 -0
  60. package/build/services/serializer/index.js +1 -265
  61. package/build/services/store/factory.d.ts +2 -1
  62. package/build/services/store/factory.js +2 -2
  63. package/build/services/store/index.d.ts +71 -97
  64. package/build/services/store/index.js +2 -939
  65. package/build/services/store/providers/postgres/postgres.d.ts +0 -0
  66. package/build/services/store/providers/postgres/postgres.js +0 -0
  67. package/build/services/store/providers/postgres/types/hash.d.ts +0 -0
  68. package/build/services/store/providers/postgres/types/hash.js +0 -0
  69. package/build/services/store/providers/postgres/types/list.d.ts +0 -0
  70. package/build/services/store/providers/postgres/types/list.js +0 -0
  71. package/build/services/store/providers/postgres/types/string.d.ts +0 -0
  72. package/build/services/store/providers/postgres/types/string.js +0 -0
  73. package/build/services/store/providers/postgres/types/zset.d.ts +0 -0
  74. package/build/services/store/providers/postgres/types/zset.js +0 -0
  75. package/build/services/store/providers/redis/_base.d.ts +98 -0
  76. package/build/services/store/providers/redis/_base.js +1 -0
  77. package/build/services/store/providers/redis/ioredis.d.ts +12 -0
  78. package/build/services/store/providers/redis/ioredis.js +1 -0
  79. package/build/services/store/providers/redis/redis.d.ts +13 -0
  80. package/build/services/store/providers/redis/redis.js +1 -0
  81. package/build/services/store/providers/store-initializable.d.ts +5 -0
  82. package/build/services/store/providers/store-initializable.js +1 -0
  83. package/build/services/stream/factory.d.ts +2 -1
  84. package/build/services/stream/factory.js +5 -5
  85. package/build/services/stream/index.d.ts +13 -14
  86. package/build/services/stream/index.js +3 -2
  87. package/build/services/stream/providers/postgres/_deploy.d.ts +4 -0
  88. package/build/services/stream/providers/postgres/_deploy.js +1 -0
  89. package/build/services/stream/providers/redis/ioredis.d.ts +21 -0
  90. package/build/services/stream/providers/redis/ioredis.js +1 -0
  91. package/build/services/stream/providers/redis/redis.d.ts +21 -0
  92. package/build/services/stream/providers/redis/redis.js +1 -0
  93. package/build/services/stream/providers/stream-initializable.d.ts +5 -0
  94. package/build/services/stream/providers/stream-initializable.js +1 -0
  95. package/build/services/sub/factory.d.ts +1 -1
  96. package/build/services/sub/factory.js +5 -5
  97. package/build/services/sub/index.d.ts +9 -7
  98. package/build/services/sub/index.js +3 -2
  99. package/build/services/sub/{clients → providers/redis}/ioredis.d.ts +7 -10
  100. package/build/services/sub/providers/redis/ioredis.js +1 -0
  101. package/build/services/sub/{clients → providers/redis}/redis.d.ts +7 -10
  102. package/build/services/sub/providers/redis/redis.js +1 -0
  103. package/build/services/task/index.js +1 -171
  104. package/build/services/telemetry/index.js +1 -225
  105. package/build/services/worker/index.d.ts +2 -2
  106. package/build/services/worker/index.js +1 -158
  107. package/build/types/redis.d.ts +5 -5
  108. package/index.ts +15 -1
  109. package/package.json +12 -8
  110. package/types/redis.ts +5 -5
  111. package/build/services/store/clients/ioredis.d.ts +0 -30
  112. package/build/services/store/clients/ioredis.js +0 -220
  113. package/build/services/store/clients/redis.d.ts +0 -32
  114. package/build/services/store/clients/redis.js +0 -319
  115. package/build/services/stream/clients/ioredis.d.ts +0 -24
  116. package/build/services/stream/clients/ioredis.js +0 -121
  117. package/build/services/stream/clients/redis.d.ts +0 -24
  118. package/build/services/stream/clients/redis.js +0 -161
  119. package/build/services/sub/clients/ioredis.js +0 -72
  120. package/build/services/sub/clients/redis.js +0 -63
@@ -1,319 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RedisStoreService = void 0;
4
- const index_1 = require("../index");
5
- const enums_1 = require("../../../modules/enums");
6
- class RedisStoreService extends index_1.StoreService {
7
- constructor(redisClient) {
8
- super(redisClient);
9
- this.commands = {
10
- get: 'GET',
11
- set: 'SET',
12
- setnx: 'SETNX',
13
- del: 'DEL',
14
- expire: 'EXPIRE',
15
- hscan: 'HSCAN',
16
- hset: 'HSET',
17
- hsetnx: 'HSETNX',
18
- hincrby: 'HINCRBY',
19
- hdel: 'HDEL',
20
- hget: 'HGET',
21
- hmget: 'HMGET',
22
- hgetall: 'HGETALL',
23
- hincrbyfloat: 'HINCRBYFLOAT',
24
- zrange: 'ZRANGE',
25
- zrangebyscore_withscores: 'ZRANGEBYSCORE_WITHSCORES',
26
- zrangebyscore: 'ZRANGEBYSCORE',
27
- zrem: 'ZREM',
28
- zadd: 'ZADD',
29
- lmove: 'LMOVE',
30
- lrange: 'LRANGE',
31
- llen: 'LLEN',
32
- lpop: 'LPOP',
33
- rename: 'RENAME',
34
- rpush: 'RPUSH',
35
- scan: 'SCAN',
36
- xack: 'XACK',
37
- xdel: 'XDEL',
38
- xlen: 'XLEN',
39
- };
40
- }
41
- getMulti() {
42
- const my = this;
43
- if (enums_1.HMSH_IS_CLUSTER) {
44
- const commands = [];
45
- const addCommand = (command, args) => {
46
- commands.push({ command: command.toUpperCase(), args });
47
- return multiInstance;
48
- };
49
- const multiInstance = {
50
- sendCommand(command, ...args) {
51
- return my.redisClient.sendCommand([command, ...args]);
52
- },
53
- async exec() {
54
- if (commands.length === 0)
55
- return [];
56
- const sameKey = commands.every((cmd) => {
57
- return cmd.args[0] === commands[0].args[0];
58
- });
59
- if (sameKey) {
60
- const multi = my.redisClient.multi();
61
- commands.forEach((cmd) => {
62
- if (cmd.command === 'ZADD') {
63
- return multi.ZADD(cmd.args[0], cmd.args[1], cmd.args[2]);
64
- }
65
- return multi[cmd.command](...cmd.args);
66
- });
67
- const results = await multi.exec();
68
- return results.map((item) => item);
69
- }
70
- else {
71
- return Promise.all(commands.map((cmd) => {
72
- if (cmd.command === 'ZADD') {
73
- return my.redisClient.ZADD(cmd.args[0], cmd.args[1], cmd.args[2]);
74
- }
75
- return my.redisClient[cmd.command](...cmd.args);
76
- }));
77
- }
78
- },
79
- XADD(key, id, fields, message) {
80
- return addCommand('XADD', [key, id, fields, message]);
81
- },
82
- XACK(key, group, id) {
83
- return addCommand('XACK', [key, group, id]);
84
- },
85
- XDEL(key, id) {
86
- return addCommand('XDEL', [key, id]);
87
- },
88
- XLEN(key) {
89
- return addCommand('XLEN', [key]);
90
- },
91
- XCLAIM(key, group, consumer, minIdleTime, id, ...args) {
92
- return addCommand('XCLAIM', [
93
- key,
94
- group,
95
- consumer,
96
- minIdleTime,
97
- id,
98
- ...args,
99
- ]);
100
- },
101
- XPENDING(key, group, start, end, count, consumer) {
102
- return addCommand('XPENDING', [
103
- key,
104
- group,
105
- start,
106
- end,
107
- count,
108
- consumer,
109
- ]);
110
- },
111
- DEL: function (key) {
112
- return addCommand('DEL', [key]);
113
- },
114
- EXPIRE: function (key, seconds) {
115
- return addCommand('EXPIRE', [key, seconds]);
116
- },
117
- HDEL(key, itemId) {
118
- return addCommand('HDEL', [key, itemId]);
119
- },
120
- HGET(key, itemId) {
121
- return addCommand('HGET', [key, itemId]);
122
- },
123
- HGETALL(key) {
124
- return addCommand('HGETALL', [key]);
125
- },
126
- HINCRBYFLOAT(key, itemId, value) {
127
- return addCommand('HINCRBYFLOAT', [key, itemId, value]);
128
- },
129
- HMGET(key, itemIds) {
130
- return addCommand('HMGET', [key, itemIds]);
131
- },
132
- HSET(key, values) {
133
- return addCommand('HSET', [key, values]);
134
- },
135
- LRANGE(key, start, end) {
136
- return addCommand('LRANGE', [key, start, end]);
137
- },
138
- RPUSH(key, items) {
139
- return addCommand('RPUSH', [key, items]);
140
- },
141
- ZADD(key, args, opts) {
142
- return addCommand('ZADD', [key, args, opts]);
143
- },
144
- XGROUP(command, key, groupName, id, mkStream) {
145
- return addCommand('XGROUP', [command, key, groupName, id, mkStream]);
146
- },
147
- EXISTS: function (key) {
148
- throw new Error('Function not implemented.');
149
- },
150
- HMPUSH: function (key, values) {
151
- throw new Error('Function not implemented.');
152
- },
153
- LPUSH: function (key, items) {
154
- throw new Error('Function not implemented.');
155
- },
156
- SET: function (key, value) {
157
- throw new Error('Function not implemented.');
158
- },
159
- ZRANGE_WITHSCORES: function (key, start, end) {
160
- throw new Error('Function not implemented.');
161
- },
162
- ZRANK: function (key, member) {
163
- throw new Error('Function not implemented.');
164
- },
165
- ZSCORE: function (key, value) {
166
- throw new Error('Function not implemented.');
167
- },
168
- };
169
- return multiInstance;
170
- }
171
- return this.redisClient.multi();
172
- }
173
- async exec(...args) {
174
- return await this.redisClient.sendCommand(args);
175
- }
176
- async setnxex(key, value, expireSeconds) {
177
- const status = await this.redisClient[this.commands.set](key, value, { NX: true, EX: expireSeconds });
178
- return this.isSuccessful(status);
179
- }
180
- async publish(keyType, message, appId, engineId) {
181
- const topic = this.mintKey(keyType, { appId, engineId });
182
- const status = await this.redisClient.publish(topic, JSON.stringify(message));
183
- return this.isSuccessful(status);
184
- }
185
- async zAdd(key, score, value, redisMulti) {
186
- return await (redisMulti || this.redisClient)[this.commands.zadd](key, {
187
- score: score,
188
- value: value.toString(),
189
- });
190
- }
191
- async zRangeByScoreWithScores(key, score, value) {
192
- const result = await this.redisClient[this.commands.zrangebyscore_withscores](key, score, value);
193
- if (result?.length > 0) {
194
- return result[0];
195
- }
196
- return null;
197
- }
198
- async zRangeByScore(key, score, value) {
199
- const result = await this.redisClient[this.commands.zrangebyscore](key, score, value);
200
- if (result?.length > 0) {
201
- return result[0];
202
- }
203
- return null;
204
- }
205
- async xgroup(command, key, groupName, id, mkStream) {
206
- const args = mkStream === 'MKSTREAM' ? ['MKSTREAM'] : [];
207
- try {
208
- return ((await this.redisClient.sendCommand([
209
- 'XGROUP',
210
- 'CREATE',
211
- key,
212
- groupName,
213
- id,
214
- ...args,
215
- ])) === 1);
216
- }
217
- catch (error) {
218
- const streamType = mkStream === 'MKSTREAM' ? 'with MKSTREAM' : 'without MKSTREAM';
219
- this.logger.debug(`x-group-error ${streamType} for key: ${key} and group: ${groupName}`, { ...error });
220
- throw error;
221
- }
222
- }
223
- async xadd(key, id, ...args) {
224
- let multi;
225
- if (typeof args[args.length - 1] !== 'string') {
226
- multi = args.pop();
227
- }
228
- try {
229
- return await (multi || this.redisClient).XADD(key, id, {
230
- [args[0]]: args[1],
231
- });
232
- }
233
- catch (error) {
234
- this.logger.error(`Error publishing 'xadd'; key: ${key}`, { ...error });
235
- throw error;
236
- }
237
- }
238
- async xpending(key, group, start, end, count, consumer) {
239
- try {
240
- const args = [key, group];
241
- if (start)
242
- args.push(start);
243
- if (end)
244
- args.push(end);
245
- if (count !== undefined)
246
- args.push(count.toString());
247
- if (consumer)
248
- args.push(consumer);
249
- return await this.redisClient.sendCommand(['XPENDING', ...args]);
250
- }
251
- catch (error) {
252
- this.logger.error(`Error in retrieving pending messages for group: ${group} in key: ${key}`, { ...error });
253
- throw error;
254
- }
255
- }
256
- async xclaim(key, group, consumer, minIdleTime, id, ...args) {
257
- try {
258
- return (await this.redisClient.sendCommand([
259
- 'XCLAIM',
260
- key,
261
- group,
262
- consumer,
263
- minIdleTime.toString(),
264
- id,
265
- ...args,
266
- ]));
267
- }
268
- catch (error) {
269
- this.logger.error(`Error in claiming message with id: ${id} in group: ${group} for key: ${key}`, { ...error });
270
- throw error;
271
- }
272
- }
273
- async xack(key, group, id, multi) {
274
- try {
275
- if (multi) {
276
- multi[this.commands.xack](key, group, id);
277
- return multi;
278
- }
279
- else {
280
- return await this.redisClient[this.commands.xack](key, group, id);
281
- }
282
- }
283
- catch (error) {
284
- this.logger.error(`Error in acknowledging messages in group: ${group} for key: ${key}`, { ...error });
285
- throw error;
286
- }
287
- }
288
- async xdel(key, id, multi) {
289
- try {
290
- if (multi) {
291
- multi[this.commands.xdel](key, id);
292
- return multi;
293
- }
294
- else {
295
- return await this.redisClient[this.commands.xdel](key, id);
296
- }
297
- }
298
- catch (error) {
299
- this.logger.error(`Error in deleting messages with ids: ${id} for key: ${key}`, { ...error });
300
- throw error;
301
- }
302
- }
303
- async xlen(key, multi) {
304
- try {
305
- if (multi) {
306
- multi.XLEN(key);
307
- return multi;
308
- }
309
- else {
310
- return await this.redisClient.XLEN(key);
311
- }
312
- }
313
- catch (error) {
314
- this.logger.error(`Error getting stream depth: ${key}`, { ...error });
315
- throw error;
316
- }
317
- }
318
- }
319
- exports.RedisStoreService = RedisStoreService;
@@ -1,24 +0,0 @@
1
- import { KeyStoreParams, KeyType } from '../../../modules/key';
2
- import { ILogger } from '../../logger';
3
- import { StreamService } from '../index';
4
- import { IORedisClientType as RedisClientType, IORedisMultiType as RedisMultiType } from '../../../types/redis';
5
- import { ReclaimedMessageType } from '../../../types/stream';
6
- declare class IORedisStreamService extends StreamService<RedisClientType, RedisMultiType> {
7
- redisClient: RedisClientType;
8
- namespace: string;
9
- logger: ILogger;
10
- appId: string;
11
- constructor(redisClient: RedisClientType);
12
- init(namespace: string, appId: string, logger: ILogger): Promise<void>;
13
- getMulti(): RedisMultiType;
14
- mintKey(type: KeyType, params: KeyStoreParams): string;
15
- xgroup(command: 'CREATE', key: string, groupName: string, id: string, mkStream?: 'MKSTREAM'): Promise<boolean>;
16
- xadd(key: string, id: string, messageId: string, messageValue: string, multi?: RedisMultiType): Promise<string | RedisMultiType>;
17
- xreadgroup(command: 'GROUP', groupName: string, consumerName: string, blockOption: 'BLOCK' | 'COUNT', blockTime: number | string, streamsOption: 'STREAMS', streamName: string, id: string): Promise<string[][][] | null | unknown[]>;
18
- xpending(key: string, group: string, start?: string, end?: string, count?: number, consumer?: string): Promise<[string, string, number, [string, number][]][] | [string, string, number, number] | unknown[]>;
19
- xclaim(key: string, group: string, consumer: string, minIdleTime: number, id: string, ...args: string[]): Promise<ReclaimedMessageType>;
20
- xack(key: string, group: string, id: string, multi?: RedisMultiType): Promise<number | RedisMultiType>;
21
- xdel(key: string, id: string, multi?: RedisMultiType): Promise<number | RedisMultiType>;
22
- xlen(key: string, multi?: RedisMultiType): Promise<number | RedisMultiType>;
23
- }
24
- export { IORedisStreamService };
@@ -1,121 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IORedisStreamService = void 0;
4
- const key_1 = require("../../../modules/key");
5
- const index_1 = require("../index");
6
- class IORedisStreamService extends index_1.StreamService {
7
- constructor(redisClient) {
8
- super(redisClient);
9
- }
10
- async init(namespace = key_1.HMNS, appId, logger) {
11
- this.namespace = namespace;
12
- this.logger = logger;
13
- this.appId = appId;
14
- }
15
- getMulti() {
16
- return this.redisClient.multi();
17
- }
18
- mintKey(type, params) {
19
- if (!this.namespace)
20
- throw new Error('namespace not set');
21
- return key_1.KeyService.mintKey(this.namespace, type, params);
22
- }
23
- async xgroup(command, key, groupName, id, mkStream) {
24
- if (mkStream === 'MKSTREAM') {
25
- try {
26
- return ((await this.redisClient.xgroup(command, key, groupName, id, mkStream)) === 'OK');
27
- }
28
- catch (error) {
29
- this.logger.debug('stream-mkstream-caught', { key, group: groupName });
30
- throw error;
31
- }
32
- }
33
- else {
34
- try {
35
- return ((await this.redisClient.xgroup(command, key, groupName, id)) === 'OK');
36
- }
37
- catch (error) {
38
- this.logger.info(`Consumer group not created for key: ${key} and group: ${groupName}`);
39
- throw error;
40
- }
41
- }
42
- }
43
- async xadd(key, id, messageId, messageValue, multi) {
44
- try {
45
- return await (multi || this.redisClient).xadd(key, id, messageId, messageValue);
46
- }
47
- catch (error) {
48
- this.logger.error(`Error publishing 'xadd'; key: ${key}`, { ...error });
49
- throw error;
50
- }
51
- }
52
- async xreadgroup(command, groupName, consumerName, blockOption, blockTime, streamsOption, streamName, id) {
53
- try {
54
- return await this.redisClient.xreadgroup(command, groupName, consumerName, blockOption, blockTime, streamsOption, streamName, id);
55
- }
56
- catch (error) {
57
- this.logger.error(`Error reading stream data [Stream ${streamName}] [Group ${groupName}]`, { ...error });
58
- throw error;
59
- }
60
- }
61
- async xpending(key, group, start, end, count, consumer) {
62
- try {
63
- const args = [key, group];
64
- if (start)
65
- args.push(start);
66
- if (end)
67
- args.push(end);
68
- if (count !== undefined)
69
- args.push(count.toString());
70
- if (consumer)
71
- args.push(consumer);
72
- try {
73
- return (await this.redisClient.call('XPENDING', ...args));
74
- }
75
- catch (error) {
76
- this.logger.error('err, args', { ...error }, args);
77
- }
78
- }
79
- catch (error) {
80
- this.logger.error(`Error in retrieving pending messages for [stream ${key}], [group ${group}]`, { ...error });
81
- throw error;
82
- }
83
- }
84
- async xclaim(key, group, consumer, minIdleTime, id, ...args) {
85
- try {
86
- return (await this.redisClient.xclaim(key, group, consumer, minIdleTime, id, ...args));
87
- }
88
- catch (error) {
89
- this.logger.error(`Error in claiming message with id: ${id} in group: ${group} for key: ${key}`, { ...error });
90
- throw error;
91
- }
92
- }
93
- async xack(key, group, id, multi) {
94
- try {
95
- return await (multi || this.redisClient).xack(key, group, id);
96
- }
97
- catch (error) {
98
- this.logger.error(`Error in acknowledging messages in group: ${group} for key: ${key}`, { ...error });
99
- throw error;
100
- }
101
- }
102
- async xdel(key, id, multi) {
103
- try {
104
- return await (multi || this.redisClient).xdel(key, id);
105
- }
106
- catch (error) {
107
- this.logger.error(`Error in deleting messages with id: ${id} for key: ${key}`, { ...error });
108
- throw error;
109
- }
110
- }
111
- async xlen(key, multi) {
112
- try {
113
- return await (multi || this.redisClient).xlen(key);
114
- }
115
- catch (error) {
116
- this.logger.error(`Error getting stream depth: ${key}`, { ...error });
117
- throw error;
118
- }
119
- }
120
- }
121
- exports.IORedisStreamService = IORedisStreamService;
@@ -1,24 +0,0 @@
1
- import { KeyStoreParams, KeyType } from '../../../modules/key';
2
- import { ILogger } from '../../logger';
3
- import { StreamService } from '../index';
4
- import { RedisRedisClientType as RedisClientType, RedisRedisMultiType as RedisMultiType } from '../../../types/redis';
5
- import { ReclaimedMessageType } from '../../../types/stream';
6
- declare class RedisStreamService extends StreamService<RedisClientType, RedisMultiType> {
7
- redisClient: RedisClientType;
8
- namespace: string;
9
- logger: ILogger;
10
- appId: string;
11
- constructor(redisClient: RedisClientType);
12
- init(namespace: string, appId: string, logger: ILogger): Promise<void>;
13
- getMulti(): RedisMultiType;
14
- mintKey(type: KeyType, params: KeyStoreParams): string;
15
- xgroup(command: 'CREATE', key: string, groupName: string, id: string, mkStream?: 'MKSTREAM'): Promise<boolean>;
16
- xadd(key: string, id: string, ...args: any[]): Promise<string | RedisMultiType>;
17
- xreadgroup(command: 'GROUP', groupName: string, consumerName: string, blockOption: 'BLOCK' | 'COUNT', blockTime: number | string, streamsOption: 'STREAMS', streamName: string, id: string): Promise<string[][][] | null>;
18
- xpending(key: string, group: string, start?: string, end?: string, count?: number, consumer?: string): Promise<[string, string, number, [string, number][]][] | [string, string, number, number]>;
19
- xclaim(key: string, group: string, consumer: string, minIdleTime: number, id: string, ...args: string[]): Promise<ReclaimedMessageType>;
20
- xack(key: string, group: string, id: string, multi?: RedisMultiType): Promise<number | RedisMultiType>;
21
- xdel(key: string, id: string, multi?: RedisMultiType): Promise<number | RedisMultiType>;
22
- xlen(key: string, multi?: RedisMultiType): Promise<number | RedisMultiType>;
23
- }
24
- export { RedisStreamService };
@@ -1,161 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RedisStreamService = void 0;
4
- const key_1 = require("../../../modules/key");
5
- const index_1 = require("../index");
6
- class RedisStreamService extends index_1.StreamService {
7
- constructor(redisClient) {
8
- super(redisClient);
9
- }
10
- async init(namespace = key_1.HMNS, appId, logger) {
11
- this.namespace = namespace;
12
- this.logger = logger;
13
- this.appId = appId;
14
- }
15
- getMulti() {
16
- return this.redisClient.multi();
17
- }
18
- mintKey(type, params) {
19
- if (!this.namespace)
20
- throw new Error('namespace not set');
21
- return key_1.KeyService.mintKey(this.namespace, type, params);
22
- }
23
- async xgroup(command, key, groupName, id, mkStream) {
24
- const args = mkStream === 'MKSTREAM' ? ['MKSTREAM'] : [];
25
- try {
26
- return ((await this.redisClient.sendCommand([
27
- 'XGROUP',
28
- 'CREATE',
29
- key,
30
- groupName,
31
- id,
32
- ...args,
33
- ])) === 1);
34
- }
35
- catch (error) {
36
- const streamType = mkStream === 'MKSTREAM' ? 'with MKSTREAM' : 'without MKSTREAM';
37
- this.logger.error(`x-group-error ${streamType} for key: ${key} and group: ${groupName}`, { ...error });
38
- throw error;
39
- }
40
- }
41
- async xadd(key, id, ...args) {
42
- let multi;
43
- if (typeof args[args.length - 1] !== 'string') {
44
- multi = args.pop();
45
- }
46
- try {
47
- return await (multi || this.redisClient).XADD(key, id, {
48
- [args[0]]: args[1],
49
- });
50
- }
51
- catch (error) {
52
- this.logger.error(`Error publishing 'xadd'; key: ${key}`, { ...error });
53
- throw error;
54
- }
55
- }
56
- async xreadgroup(command, groupName, consumerName, blockOption, blockTime, streamsOption, streamName, id) {
57
- try {
58
- return await this.redisClient.sendCommand([
59
- 'XREADGROUP',
60
- command,
61
- groupName,
62
- consumerName,
63
- blockOption,
64
- blockTime.toString(),
65
- streamsOption,
66
- streamName,
67
- id,
68
- ]);
69
- }
70
- catch (error) {
71
- this.logger.error(`Error reading stream data [Stream ${streamName}] [Group ${groupName}]`, { ...error });
72
- throw error;
73
- }
74
- }
75
- async xpending(key, group, start, end, count, consumer) {
76
- try {
77
- const args = [key, group];
78
- if (start)
79
- args.push(start);
80
- if (end)
81
- args.push(end);
82
- if (count !== undefined)
83
- args.push(count.toString());
84
- if (consumer)
85
- args.push(consumer);
86
- try {
87
- return await this.redisClient.sendCommand(['XPENDING', ...args]);
88
- }
89
- catch (error) {
90
- this.logger.error('error, args', { ...error }, args);
91
- }
92
- }
93
- catch (error) {
94
- this.logger.error(`Error retrieving pending messages for group: ${group} in key: ${key}`, { ...error });
95
- throw error;
96
- }
97
- }
98
- async xclaim(key, group, consumer, minIdleTime, id, ...args) {
99
- try {
100
- return (await this.redisClient.sendCommand([
101
- 'XCLAIM',
102
- key,
103
- group,
104
- consumer,
105
- minIdleTime.toString(),
106
- id,
107
- ...args,
108
- ]));
109
- }
110
- catch (error) {
111
- this.logger.error(`Error claiming message with id: ${id} in group: ${group} for key: ${key}`, { ...error });
112
- throw error;
113
- }
114
- }
115
- async xack(key, group, id, multi) {
116
- try {
117
- if (multi) {
118
- multi.XACK(key, group, id);
119
- return multi;
120
- }
121
- else {
122
- return await this.redisClient.XACK(key, group, id);
123
- }
124
- }
125
- catch (error) {
126
- this.logger.error(`Error acknowledging messages in group: ${group} for key: ${key}`, { ...error });
127
- throw error;
128
- }
129
- }
130
- async xdel(key, id, multi) {
131
- try {
132
- if (multi) {
133
- multi.XDEL(key, id);
134
- return multi;
135
- }
136
- else {
137
- return await this.redisClient.XDEL(key, id);
138
- }
139
- }
140
- catch (error) {
141
- this.logger.error(`Error deleting messages with ids: ${id} for key: ${key}`, { ...error });
142
- throw error;
143
- }
144
- }
145
- async xlen(key, multi) {
146
- try {
147
- if (multi) {
148
- multi.XLEN(key);
149
- return multi;
150
- }
151
- else {
152
- return await this.redisClient.XLEN(key);
153
- }
154
- }
155
- catch (error) {
156
- this.logger.error(`Error getting stream depth: ${key}`, { ...error });
157
- throw error;
158
- }
159
- }
160
- }
161
- exports.RedisStreamService = RedisStreamService;