@hotmeshio/hotmesh 0.0.60 → 0.1.1

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 (108) hide show
  1. package/README.md +1 -1
  2. package/build/modules/enums.d.ts +2 -1
  3. package/build/modules/enums.js +12 -3
  4. package/build/modules/errors.d.ts +3 -3
  5. package/build/modules/errors.js +8 -8
  6. package/build/modules/key.d.ts +1 -1
  7. package/build/modules/key.js +3 -3
  8. package/build/modules/utils.d.ts +6 -5
  9. package/build/modules/utils.js +24 -16
  10. package/build/package.json +41 -38
  11. package/build/services/activities/activity.js +40 -23
  12. package/build/services/activities/await.d.ts +1 -1
  13. package/build/services/activities/await.js +15 -7
  14. package/build/services/activities/cycle.d.ts +1 -1
  15. package/build/services/activities/cycle.js +16 -8
  16. package/build/services/activities/hook.d.ts +1 -1
  17. package/build/services/activities/hook.js +8 -4
  18. package/build/services/activities/interrupt.d.ts +1 -1
  19. package/build/services/activities/interrupt.js +14 -6
  20. package/build/services/activities/signal.d.ts +1 -1
  21. package/build/services/activities/signal.js +12 -4
  22. package/build/services/activities/trigger.d.ts +1 -1
  23. package/build/services/activities/trigger.js +19 -12
  24. package/build/services/activities/worker.d.ts +1 -1
  25. package/build/services/activities/worker.js +15 -7
  26. package/build/services/collator/index.js +12 -12
  27. package/build/services/compiler/deployer.js +17 -12
  28. package/build/services/compiler/index.js +4 -4
  29. package/build/services/compiler/validator.d.ts +3 -3
  30. package/build/services/compiler/validator.js +12 -3
  31. package/build/services/durable/client.d.ts +1 -1
  32. package/build/services/durable/client.js +18 -12
  33. package/build/services/durable/connection.d.ts +1 -1
  34. package/build/services/durable/exporter.d.ts +1 -1
  35. package/build/services/durable/exporter.js +3 -4
  36. package/build/services/durable/handle.d.ts +1 -1
  37. package/build/services/durable/handle.js +4 -1
  38. package/build/services/durable/index.d.ts +1 -1
  39. package/build/services/durable/index.js +2 -2
  40. package/build/services/durable/schemas/factory.d.ts +1 -1
  41. package/build/services/durable/search.js +19 -11
  42. package/build/services/durable/worker.js +50 -30
  43. package/build/services/durable/workflow.d.ts +5 -5
  44. package/build/services/durable/workflow.js +34 -18
  45. package/build/services/engine/index.js +33 -26
  46. package/build/services/exporter/index.d.ts +1 -1
  47. package/build/services/exporter/index.js +3 -3
  48. package/build/services/hotmesh/index.js +1 -1
  49. package/build/services/logger/index.js +1 -1
  50. package/build/services/mapper/index.js +3 -1
  51. package/build/services/pipe/functions/date.js +1 -1
  52. package/build/services/pipe/index.js +37 -10
  53. package/build/services/quorum/index.js +14 -11
  54. package/build/services/reporter/index.js +15 -12
  55. package/build/services/router/index.d.ts +2 -2
  56. package/build/services/router/index.js +73 -23
  57. package/build/services/serializer/index.js +48 -26
  58. package/build/services/store/cache.d.ts +5 -5
  59. package/build/services/store/cache.js +2 -2
  60. package/build/services/store/clients/ioredis.d.ts +6 -0
  61. package/build/services/store/clients/ioredis.js +85 -3
  62. package/build/services/store/clients/redis.d.ts +6 -0
  63. package/build/services/store/clients/redis.js +140 -4
  64. package/build/services/store/index.d.ts +9 -3
  65. package/build/services/store/index.js +121 -60
  66. package/build/services/stream/clients/ioredis.js +4 -4
  67. package/build/services/stream/clients/redis.js +31 -4
  68. package/build/services/task/index.js +8 -11
  69. package/build/services/telemetry/index.js +21 -14
  70. package/build/services/worker/index.d.ts +6 -6
  71. package/build/services/worker/index.js +12 -7
  72. package/build/types/activity.d.ts +3 -3
  73. package/build/types/durable.d.ts +81 -77
  74. package/build/types/exporter.d.ts +2 -2
  75. package/build/types/exporter.js +0 -6
  76. package/build/types/hook.d.ts +1 -1
  77. package/build/types/hotmesh.js +0 -1
  78. package/build/types/index.d.ts +13 -13
  79. package/build/types/job.d.ts +1 -1
  80. package/build/types/logger.js +0 -1
  81. package/build/types/quorum.d.ts +1 -1
  82. package/build/types/redis.d.ts +6 -1
  83. package/build/types/stats.d.ts +1 -1
  84. package/build/types/stream.d.ts +1 -2
  85. package/build/types/telemetry.d.ts +1 -1
  86. package/build/types/transition.d.ts +1 -1
  87. package/package.json +41 -38
  88. package/types/activity.ts +56 -39
  89. package/types/async.ts +2 -3
  90. package/types/collator.ts +5 -5
  91. package/types/durable.ts +90 -86
  92. package/types/error.ts +37 -37
  93. package/types/exporter.ts +14 -9
  94. package/types/hook.ts +11 -4
  95. package/types/hotmesh.ts +26 -25
  96. package/types/index.ts +54 -53
  97. package/types/job.ts +33 -33
  98. package/types/logger.ts +1 -1
  99. package/types/map.ts +1 -1
  100. package/types/pipe.ts +10 -8
  101. package/types/quorum.ts +20 -13
  102. package/types/redis.ts +96 -16
  103. package/types/serializer.ts +8 -6
  104. package/types/stats.ts +22 -6
  105. package/types/stream.ts +9 -9
  106. package/types/task.ts +7 -1
  107. package/types/telemetry.ts +2 -1
  108. package/types/transition.ts +8 -8
@@ -7,7 +7,89 @@ class IORedisStoreService extends index_1.StoreService {
7
7
  constructor(redisClient) {
8
8
  super(redisClient);
9
9
  }
10
+ /**
11
+ * When in cluster mode, the getMulti wrapper only
12
+ * sends commands to the same node/shard.
13
+ * All other commands are sent simultaneously
14
+ * using Promise.all and are then collated
15
+ */
10
16
  getMulti() {
17
+ const my = this;
18
+ if (process.env.HMSH_IS_CLUSTER === 'true') {
19
+ const commands = [];
20
+ const addCommand = (command, args) => {
21
+ commands.push({ command, args });
22
+ return multiInstance;
23
+ };
24
+ const multiInstance = {
25
+ sendCommand(command) {
26
+ return my.redisClient.sendCommand(command);
27
+ },
28
+ async exec() {
29
+ if (commands.length === 0)
30
+ return [];
31
+ const sameCommand = commands.every(cmd => cmd.command === commands[0].command);
32
+ if (sameCommand) {
33
+ const multi = my.redisClient.multi();
34
+ commands.forEach(cmd => multi[cmd.command](...cmd.args));
35
+ const results = await multi.exec();
36
+ return results.map(item => item); // Extract the results from multi.exec response format
37
+ }
38
+ else {
39
+ return Promise.all(commands.map(cmd => my.redisClient[cmd.command](...cmd.args)));
40
+ }
41
+ },
42
+ xadd(key, id, fields, message) {
43
+ return addCommand('xadd', [key, id, fields, message]);
44
+ },
45
+ xack(key, group, id) {
46
+ return addCommand('xack', [key, group, id]);
47
+ },
48
+ xdel(key, id) {
49
+ return addCommand('xdel', [key, id]);
50
+ },
51
+ xlen(key) {
52
+ return addCommand('xlen', [key]);
53
+ },
54
+ xpending(key, group, start, end, count, consumer) {
55
+ return addCommand('xpending', [key, group, start, end, count, consumer]);
56
+ },
57
+ xclaim(key, group, consumer, minIdleTime, id, ...args) {
58
+ return addCommand('xclaim', [key, group, consumer, minIdleTime, id, ...args]);
59
+ },
60
+ hdel(key, itemId) {
61
+ return addCommand('hdel', [key, itemId]);
62
+ },
63
+ hget(key, itemId) {
64
+ return addCommand('hget', [key, itemId]);
65
+ },
66
+ hgetall(key) {
67
+ return addCommand('hgetall', [key]);
68
+ },
69
+ hincrbyfloat(key, itemId, value) {
70
+ return addCommand('hincrbyfloat', [key, itemId, value]);
71
+ },
72
+ hmget(key, itemIds) {
73
+ return addCommand('hmget', [key, itemIds]);
74
+ },
75
+ hset(key, values) {
76
+ return addCommand('hset', [key, values]);
77
+ },
78
+ lrange(key, start, end) {
79
+ return addCommand('lrange', [key, start, end]);
80
+ },
81
+ rpush(key, value) {
82
+ return addCommand('rpush', [key, value]);
83
+ },
84
+ zadd(...args) {
85
+ return addCommand('zadd', args);
86
+ },
87
+ xgroup(command, key, groupName, id, mkStream) {
88
+ return addCommand('xgroup', [command, key, groupName, id, mkStream]);
89
+ }
90
+ };
91
+ return multiInstance;
92
+ }
11
93
  return this.redisClient.multi();
12
94
  }
13
95
  async exec(...args) {
@@ -43,7 +125,7 @@ class IORedisStoreService extends index_1.StoreService {
43
125
  async xgroup(command, key, groupName, id, mkStream) {
44
126
  if (mkStream === 'MKSTREAM') {
45
127
  try {
46
- return (await this.redisClient.xgroup(command, key, groupName, id, mkStream)) === 'OK';
128
+ return ((await this.redisClient.xgroup(command, key, groupName, id, mkStream)) === 'OK');
47
129
  }
48
130
  catch (err) {
49
131
  this.logger.debug(`Consumer group not created with MKSTREAM for key: ${key} and group: ${groupName}`);
@@ -52,7 +134,7 @@ class IORedisStoreService extends index_1.StoreService {
52
134
  }
53
135
  else {
54
136
  try {
55
- return (await this.redisClient.xgroup(command, key, groupName, id)) === 'OK';
137
+ return ((await this.redisClient.xgroup(command, key, groupName, id)) === 'OK');
56
138
  }
57
139
  catch (err) {
58
140
  this.logger.debug(`Consumer group not created for key: ${key} and group: ${groupName}`);
@@ -80,7 +162,7 @@ class IORedisStoreService extends index_1.StoreService {
80
162
  }
81
163
  async xclaim(key, group, consumer, minIdleTime, id, ...args) {
82
164
  try {
83
- return await this.redisClient.xclaim(key, group, consumer, minIdleTime, id, ...args);
165
+ return (await this.redisClient.xclaim(key, group, consumer, minIdleTime, id, ...args));
84
166
  }
85
167
  catch (error) {
86
168
  this.logger.error(`Error in claiming message with id: ${id} in group: ${group} for key: ${key}`, { ...error });
@@ -14,6 +14,12 @@ declare class RedisStoreService extends StoreService<RedisClientType, RedisMulti
14
14
  serializer: Serializer;
15
15
  commands: Record<string, string>;
16
16
  constructor(redisClient: RedisClientType);
17
+ /**
18
+ * When in cluster mode, the getMulti wrapper only
19
+ * sends commands to the same node/shard.
20
+ * All other commands are sent simultaneously
21
+ * using Promise.all and are then collated
22
+ */
17
23
  getMulti(): RedisMultiType;
18
24
  exec(...args: any[]): Promise<string | string[] | string[][]>;
19
25
  publish(keyType: KeyType.QUORUM, message: Record<string, any>, appId: string, engineId?: string): Promise<boolean>;
@@ -36,7 +36,123 @@ class RedisStoreService extends index_1.StoreService {
36
36
  xlen: 'XLEN',
37
37
  };
38
38
  }
39
+ /**
40
+ * When in cluster mode, the getMulti wrapper only
41
+ * sends commands to the same node/shard.
42
+ * All other commands are sent simultaneously
43
+ * using Promise.all and are then collated
44
+ */
39
45
  getMulti() {
46
+ const my = this;
47
+ if (process.env.HMSH_IS_CLUSTER === 'true') {
48
+ const commands = [];
49
+ const addCommand = (command, args) => {
50
+ commands.push({ command: command.toUpperCase(), args });
51
+ return multiInstance;
52
+ };
53
+ const multiInstance = {
54
+ sendCommand(command, ...args) {
55
+ return my.redisClient.sendCommand([command, ...args]);
56
+ },
57
+ async exec() {
58
+ if (commands.length === 0)
59
+ return [];
60
+ const sameCommand = commands.every(cmd => cmd.command === commands[0].command);
61
+ if (sameCommand) {
62
+ const multi = my.redisClient.multi();
63
+ commands.forEach(cmd => {
64
+ if (cmd.command === 'ZADD') {
65
+ return multi.ZADD(cmd.args[0], cmd.args[1], cmd.args[2]);
66
+ }
67
+ return multi[cmd.command](...cmd.args);
68
+ });
69
+ const results = await multi.exec();
70
+ return results.map(item => item); // Extract the results from multi.exec response format
71
+ }
72
+ else {
73
+ return Promise.all(commands.map(cmd => {
74
+ if (cmd.command === 'ZADD') {
75
+ return my.redisClient.ZADD(cmd.args[0], cmd.args[1], cmd.args[2]);
76
+ }
77
+ return my.redisClient[cmd.command](...cmd.args);
78
+ }));
79
+ }
80
+ },
81
+ XADD(key, id, fields, message) {
82
+ return addCommand('XADD', [key, id, fields, message]);
83
+ },
84
+ XACK(key, group, id) {
85
+ return addCommand('XACK', [key, group, id]);
86
+ },
87
+ XDEL(key, id) {
88
+ return addCommand('XDEL', [key, id]);
89
+ },
90
+ XLEN(key) {
91
+ return addCommand('XLEN', [key]);
92
+ },
93
+ XCLAIM(key, group, consumer, minIdleTime, id, ...args) {
94
+ return addCommand('XCLAIM', [key, group, consumer, minIdleTime, id, ...args]);
95
+ },
96
+ XPENDING(key, group, start, end, count, consumer) {
97
+ return addCommand('XPENDING', [key, group, start, end, count, consumer]);
98
+ },
99
+ HDEL(key, itemId) {
100
+ return addCommand('HDEL', [key, itemId]);
101
+ },
102
+ HGET(key, itemId) {
103
+ return addCommand('HGET', [key, itemId]);
104
+ },
105
+ HGETALL(key) {
106
+ return addCommand('HGETALL', [key]);
107
+ },
108
+ HINCRBYFLOAT(key, itemId, value) {
109
+ return addCommand('HINCRBYFLOAT', [key, itemId, value]);
110
+ },
111
+ HMGET(key, itemIds) {
112
+ return addCommand('HMGET', [key, itemIds]);
113
+ },
114
+ HSET(key, values) {
115
+ return addCommand('HSET', [key, values]);
116
+ },
117
+ LRANGE(key, start, end) {
118
+ return addCommand('LRANGE', [key, start, end]);
119
+ },
120
+ RPUSH(key, items) {
121
+ return addCommand('RPUSH', [key, items]);
122
+ },
123
+ ZADD(key, args, opts) {
124
+ return addCommand('ZADD', [key, args, opts]);
125
+ },
126
+ XGROUP(command, key, groupName, id, mkStream) {
127
+ return addCommand('XGROUP', [command, key, groupName, id, mkStream]);
128
+ },
129
+ DEL: function (key) {
130
+ throw new Error('Function not implemented.');
131
+ },
132
+ EXISTS: function (key) {
133
+ throw new Error('Function not implemented.');
134
+ },
135
+ HMPUSH: function (key, values) {
136
+ throw new Error('Function not implemented.');
137
+ },
138
+ LPUSH: function (key, items) {
139
+ throw new Error('Function not implemented.');
140
+ },
141
+ SET: function (key, value) {
142
+ throw new Error('Function not implemented.');
143
+ },
144
+ ZRANGE_WITHSCORES: function (key, start, end) {
145
+ throw new Error('Function not implemented.');
146
+ },
147
+ ZRANK: function (key, member) {
148
+ throw new Error('Function not implemented.');
149
+ },
150
+ ZSCORE: function (key, value) {
151
+ throw new Error('Function not implemented.');
152
+ }
153
+ };
154
+ return multiInstance;
155
+ }
40
156
  return this.redisClient.multi();
41
157
  }
42
158
  async exec(...args) {
@@ -48,7 +164,10 @@ class RedisStoreService extends index_1.StoreService {
48
164
  return this.isSuccessful(status);
49
165
  }
50
166
  async zAdd(key, score, value, redisMulti) {
51
- return await (redisMulti || this.redisClient)[this.commands.zadd](key, { score: score, value: value.toString() });
167
+ return await (redisMulti || this.redisClient)[this.commands.zadd](key, {
168
+ score: score,
169
+ value: value.toString(),
170
+ });
52
171
  }
53
172
  async zRangeByScoreWithScores(key, score, value) {
54
173
  const result = await this.redisClient[this.commands.zrangebyscore_withscores](key, score, value);
@@ -67,7 +186,14 @@ class RedisStoreService extends index_1.StoreService {
67
186
  async xgroup(command, key, groupName, id, mkStream) {
68
187
  const args = mkStream === 'MKSTREAM' ? ['MKSTREAM'] : [];
69
188
  try {
70
- return (await this.redisClient.sendCommand(['XGROUP', 'CREATE', key, groupName, id, ...args])) === 1;
189
+ return ((await this.redisClient.sendCommand([
190
+ 'XGROUP',
191
+ 'CREATE',
192
+ key,
193
+ groupName,
194
+ id,
195
+ ...args,
196
+ ])) === 1);
71
197
  }
72
198
  catch (error) {
73
199
  const streamType = mkStream === 'MKSTREAM' ? 'with MKSTREAM' : 'without MKSTREAM';
@@ -81,7 +207,9 @@ class RedisStoreService extends index_1.StoreService {
81
207
  multi = args.pop();
82
208
  }
83
209
  try {
84
- return await (multi || this.redisClient).XADD(key, id, { [args[0]]: args[1] });
210
+ return await (multi || this.redisClient).XADD(key, id, {
211
+ [args[0]]: args[1],
212
+ });
85
213
  }
86
214
  catch (error) {
87
215
  this.logger.error(`Error publishing 'xadd'; key: ${key}`, { ...error });
@@ -108,7 +236,15 @@ class RedisStoreService extends index_1.StoreService {
108
236
  }
109
237
  async xclaim(key, group, consumer, minIdleTime, id, ...args) {
110
238
  try {
111
- return await this.redisClient.sendCommand(['XCLAIM', key, group, consumer, minIdleTime.toString(), id, ...args]);
239
+ return (await this.redisClient.sendCommand([
240
+ 'XCLAIM',
241
+ key,
242
+ group,
243
+ consumer,
244
+ minIdleTime.toString(),
245
+ id,
246
+ ...args,
247
+ ]));
112
248
  }
113
249
  catch (error) {
114
250
  this.logger.error(`Error in claiming message with id: ${id} in group: ${group} for key: ${key}`, { ...error });
@@ -1,7 +1,6 @@
1
1
  import { KeyStoreParams, KeyType } from '../../modules/key';
2
2
  import { ILogger } from '../logger';
3
3
  import { SerializerService as Serializer } from '../serializer';
4
- import { Cache } from './cache';
5
4
  import { ActivityType, Consumes } from '../../types/activity';
6
5
  import { AppVID } from '../../types/app';
7
6
  import { HookRule, HookSignal } from '../../types/hook';
@@ -12,6 +11,7 @@ import { Transitions } from '../../types/transition';
12
11
  import { ReclaimedMessageType } from '../../types/stream';
13
12
  import { JobCompletionOptions, JobInterruptOptions } from '../../types/job';
14
13
  import { WorkListTaskType } from '../../types/task';
14
+ import { Cache } from './cache';
15
15
  interface AbstractRedisClient {
16
16
  exec(): any;
17
17
  }
@@ -50,7 +50,7 @@ declare abstract class StoreService<T, U extends AbstractRedisClient> {
50
50
  releaseScoutRole(scoutType: 'time' | 'signal' | 'activate'): Promise<boolean>;
51
51
  getSettings(bCreate?: boolean): Promise<HotMeshSettings>;
52
52
  setSettings(manifest: HotMeshSettings): Promise<any>;
53
- reserveSymbolRange(target: string, size: number, type: 'JOB' | 'ACTIVITY'): Promise<[number, number, Symbols]>;
53
+ reserveSymbolRange(target: string, size: number, type: 'JOB' | 'ACTIVITY', tryCount?: number): Promise<[number, number, Symbols]>;
54
54
  getAllSymbols(): Promise<Symbols>;
55
55
  getSymbols(activityId: string): Promise<Symbols>;
56
56
  addSymbols(activityId: string, symbols: Symbols): Promise<boolean>;
@@ -134,7 +134,13 @@ declare abstract class StoreService<T, U extends AbstractRedisClient> {
134
134
  * organized into 'n'-second blocks (LISTS))
135
135
  */
136
136
  registerTimeHook(jobId: string, gId: string, activityId: string, type: WorkListTaskType, deletionTime: number, dad: string, multi?: U): Promise<void>;
137
- getNextTask(listKey?: string): Promise<[listKey: string, jobId: string, gId: string, activityId: string, type: WorkListTaskType] | boolean>;
137
+ getNextTask(listKey?: string): Promise<[
138
+ listKey: string,
139
+ jobId: string,
140
+ gId: string,
141
+ activityId: string,
142
+ type: WorkListTaskType
143
+ ] | boolean>;
138
144
  /**
139
145
  * when processing time jobs, the target LIST ID returned
140
146
  * from the ZSET query can be prefixed to denote what to