@hotmeshio/hotmesh 0.0.55 → 0.0.56

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 (181) hide show
  1. package/build/modules/enums.js +1 -10
  2. package/build/modules/key.d.ts +0 -38
  3. package/build/modules/key.js +4 -46
  4. package/build/modules/utils.d.ts +0 -8
  5. package/build/modules/utils.js +0 -14
  6. package/build/package.json +11 -4
  7. package/build/services/activities/activity.d.ts +0 -28
  8. package/build/services/activities/activity.js +1 -46
  9. package/build/services/activities/await.js +0 -4
  10. package/build/services/activities/cycle.d.ts +0 -7
  11. package/build/services/activities/cycle.js +1 -16
  12. package/build/services/activities/hook.d.ts +0 -6
  13. package/build/services/activities/hook.js +2 -12
  14. package/build/services/activities/interrupt.js +0 -8
  15. package/build/services/activities/signal.d.ts +0 -6
  16. package/build/services/activities/signal.js +0 -15
  17. package/build/services/activities/trigger.d.ts +0 -4
  18. package/build/services/activities/trigger.js +1 -7
  19. package/build/services/activities/worker.js +0 -4
  20. package/build/services/collator/index.d.ts +0 -70
  21. package/build/services/collator/index.js +1 -91
  22. package/build/services/compiler/deployer.js +6 -38
  23. package/build/services/compiler/index.d.ts +0 -15
  24. package/build/services/compiler/index.js +0 -20
  25. package/build/services/compiler/validator.d.ts +0 -3
  26. package/build/services/compiler/validator.js +0 -25
  27. package/build/services/connector/clients/ioredis.d.ts +2 -2
  28. package/build/services/connector/clients/ioredis.js +0 -2
  29. package/build/services/connector/clients/redis.d.ts +4 -4
  30. package/build/services/connector/clients/redis.js +1 -3
  31. package/build/services/connector/index.d.ts +1 -1
  32. package/build/services/connector/index.js +0 -2
  33. package/build/services/durable/client.d.ts +1 -26
  34. package/build/services/durable/client.js +0 -56
  35. package/build/services/durable/exporter.d.ts +0 -22
  36. package/build/services/durable/exporter.js +1 -30
  37. package/build/services/durable/handle.d.ts +0 -36
  38. package/build/services/durable/handle.js +0 -46
  39. package/build/services/durable/index.d.ts +0 -4
  40. package/build/services/durable/index.js +0 -4
  41. package/build/services/durable/schemas/factory.d.ts +0 -29
  42. package/build/services/durable/schemas/factory.js +0 -29
  43. package/build/services/durable/search.d.ts +1 -36
  44. package/build/services/durable/search.js +57 -56
  45. package/build/services/durable/worker.js +2 -22
  46. package/build/services/durable/workflow.d.ts +0 -114
  47. package/build/services/durable/workflow.js +1 -141
  48. package/build/services/engine/index.d.ts +1 -6
  49. package/build/services/engine/index.js +1 -43
  50. package/build/services/exporter/index.d.ts +0 -27
  51. package/build/services/exporter/index.js +0 -33
  52. package/build/services/hotmesh/index.d.ts +2 -2
  53. package/build/services/hotmesh/index.js +1 -9
  54. package/build/services/logger/index.js +0 -2
  55. package/build/services/mapper/index.d.ts +0 -14
  56. package/build/services/mapper/index.js +0 -14
  57. package/build/services/pipe/functions/date.d.ts +0 -7
  58. package/build/services/pipe/functions/date.js +0 -7
  59. package/build/services/pipe/functions/math.js +0 -2
  60. package/build/services/pipe/index.d.ts +0 -15
  61. package/build/services/pipe/index.js +2 -23
  62. package/build/services/quorum/index.d.ts +0 -7
  63. package/build/services/quorum/index.js +0 -21
  64. package/build/services/reporter/index.d.ts +0 -5
  65. package/build/services/reporter/index.js +0 -9
  66. package/build/services/router/index.d.ts +0 -9
  67. package/build/services/router/index.js +2 -38
  68. package/build/services/serializer/index.js +7 -26
  69. package/build/services/store/cache.d.ts +0 -18
  70. package/build/services/store/cache.js +0 -18
  71. package/build/services/store/clients/ioredis.d.ts +1 -1
  72. package/build/services/store/clients/ioredis.js +0 -1
  73. package/build/services/store/clients/redis.d.ts +1 -1
  74. package/build/services/store/index.d.ts +0 -55
  75. package/build/services/store/index.js +5 -81
  76. package/build/services/stream/clients/ioredis.d.ts +1 -1
  77. package/build/services/stream/clients/ioredis.js +1 -4
  78. package/build/services/stream/clients/redis.d.ts +1 -1
  79. package/build/services/sub/clients/ioredis.d.ts +1 -1
  80. package/build/services/sub/clients/redis.d.ts +1 -1
  81. package/build/services/task/index.d.ts +0 -9
  82. package/build/services/task/index.js +0 -31
  83. package/build/services/telemetry/index.d.ts +0 -7
  84. package/build/services/telemetry/index.js +1 -13
  85. package/build/services/worker/index.d.ts +0 -4
  86. package/build/services/worker/index.js +2 -6
  87. package/build/types/activity.d.ts +0 -81
  88. package/build/types/durable.d.ts +25 -177
  89. package/build/types/exporter.d.ts +0 -13
  90. package/build/types/hotmesh.d.ts +4 -16
  91. package/build/types/hotmesh.js +0 -3
  92. package/build/types/index.d.ts +4 -6
  93. package/build/types/index.js +4 -3
  94. package/build/types/job.d.ts +1 -86
  95. package/build/types/pipe.d.ts +0 -65
  96. package/build/types/quorum.d.ts +15 -10
  97. package/build/types/redis.d.ts +225 -7
  98. package/build/types/redis.js +9 -0
  99. package/build/types/stream.d.ts +0 -58
  100. package/build/types/stream.js +0 -4
  101. package/package.json +11 -4
  102. package/types/durable.ts +121 -3
  103. package/types/hotmesh.ts +3 -6
  104. package/types/index.ts +23 -10
  105. package/types/job.ts +1 -1
  106. package/types/quorum.ts +22 -0
  107. package/types/redis.ts +267 -18
  108. package/build/types/ioredisclient.d.ts +0 -5
  109. package/build/types/ioredisclient.js +0 -5
  110. package/build/types/redisclient.d.ts +0 -26
  111. package/build/types/redisclient.js +0 -2
  112. package/modules/enums.ts +0 -62
  113. package/modules/errors.ts +0 -280
  114. package/modules/key.ts +0 -101
  115. package/modules/storage.ts +0 -3
  116. package/modules/utils.ts +0 -242
  117. package/services/activities/activity.ts +0 -589
  118. package/services/activities/await.ts +0 -113
  119. package/services/activities/cycle.ts +0 -115
  120. package/services/activities/hook.ts +0 -197
  121. package/services/activities/index.ts +0 -19
  122. package/services/activities/interrupt.ts +0 -172
  123. package/services/activities/signal.ts +0 -148
  124. package/services/activities/trigger.ts +0 -295
  125. package/services/activities/worker.ts +0 -107
  126. package/services/collator/README.md +0 -102
  127. package/services/collator/index.ts +0 -291
  128. package/services/compiler/deployer.ts +0 -504
  129. package/services/compiler/index.ts +0 -98
  130. package/services/compiler/validator.ts +0 -158
  131. package/services/connector/clients/ioredis.ts +0 -57
  132. package/services/connector/clients/redis.ts +0 -72
  133. package/services/connector/index.ts +0 -42
  134. package/services/durable/client.ts +0 -266
  135. package/services/durable/connection.ts +0 -10
  136. package/services/durable/exporter.ts +0 -232
  137. package/services/durable/handle.ts +0 -160
  138. package/services/durable/index.ts +0 -27
  139. package/services/durable/schemas/factory.ts +0 -2358
  140. package/services/durable/search.ts +0 -196
  141. package/services/durable/worker.ts +0 -401
  142. package/services/durable/workflow.ts +0 -557
  143. package/services/engine/index.ts +0 -761
  144. package/services/exporter/index.ts +0 -146
  145. package/services/hotmesh/index.ts +0 -237
  146. package/services/logger/index.ts +0 -79
  147. package/services/mapper/index.ts +0 -89
  148. package/services/pipe/functions/array.ts +0 -78
  149. package/services/pipe/functions/bitwise.ts +0 -27
  150. package/services/pipe/functions/conditional.ts +0 -35
  151. package/services/pipe/functions/date.ts +0 -220
  152. package/services/pipe/functions/index.ts +0 -27
  153. package/services/pipe/functions/json.ts +0 -11
  154. package/services/pipe/functions/logical.ts +0 -11
  155. package/services/pipe/functions/math.ts +0 -217
  156. package/services/pipe/functions/number.ts +0 -75
  157. package/services/pipe/functions/object.ts +0 -98
  158. package/services/pipe/functions/string.ts +0 -86
  159. package/services/pipe/functions/symbol.ts +0 -39
  160. package/services/pipe/functions/unary.ts +0 -19
  161. package/services/pipe/index.ts +0 -216
  162. package/services/quorum/index.ts +0 -319
  163. package/services/reporter/index.ts +0 -387
  164. package/services/router/index.ts +0 -426
  165. package/services/serializer/README.md +0 -10
  166. package/services/serializer/index.ts +0 -285
  167. package/services/store/cache.ts +0 -172
  168. package/services/store/clients/ioredis.ts +0 -145
  169. package/services/store/clients/redis.ts +0 -191
  170. package/services/store/index.ts +0 -1091
  171. package/services/stream/clients/ioredis.ts +0 -157
  172. package/services/stream/clients/redis.ts +0 -158
  173. package/services/stream/index.ts +0 -58
  174. package/services/sub/clients/ioredis.ts +0 -83
  175. package/services/sub/clients/redis.ts +0 -74
  176. package/services/sub/index.ts +0 -25
  177. package/services/task/index.ts +0 -250
  178. package/services/telemetry/index.ts +0 -273
  179. package/services/worker/index.ts +0 -248
  180. package/types/ioredisclient.ts +0 -10
  181. package/types/redisclient.ts +0 -30
@@ -1,248 +0,0 @@
1
- import { KeyType } from "../../modules/key";
2
- import { XSleepFor, formatISODate, getSystemHealth, identifyRedisType, sleepFor } from "../../modules/utils";
3
- import { ConnectorService } from "../connector";
4
- import { ILogger } from "../logger";
5
- import { Router } from "../router";
6
- import { StoreService } from '../store';
7
- import { IORedisStoreService as IORedisStore } from '../store/clients/ioredis';
8
- import { RedisStoreService as RedisStore } from '../store/clients/redis';
9
- import { StreamService } from '../stream';
10
- import { IORedisStreamService as IORedisStream } from '../stream/clients/ioredis';
11
- import { RedisStreamService as RedisStream } from '../stream/clients/redis';
12
- import { SubService } from '../sub';
13
- import { IORedisSubService as IORedisSub } from '../sub/clients/ioredis';
14
- import { RedisSubService as RedisSub } from '../sub/clients/redis';
15
- import { HotMeshConfig, HotMeshWorker } from "../../types/hotmesh";
16
- import { RedisClientType as IORedisClientType } from '../../types/ioredisclient';
17
- import {
18
- QuorumMessage,
19
- QuorumProfile,
20
- RollCallMessage,
21
- SubscriptionCallback } from "../../types/quorum";
22
- import { RedisClient, RedisMulti } from "../../types/redis";
23
- import { RedisClientType } from '../../types/redisclient';
24
- import { StreamData, StreamRole, StreamDataResponse } from "../../types/stream";
25
- import { HMSH_QUORUM_ROLLCALL_CYCLES } from "../../modules/enums";
26
-
27
- class WorkerService {
28
- namespace: string;
29
- appId: string;
30
- guid: string;
31
- topic: string;
32
- config: HotMeshConfig;
33
- callback: (streamData: StreamData) => Promise<StreamDataResponse|void>;
34
- store: StoreService<RedisClient, RedisMulti> | null;
35
- stream: StreamService<RedisClient, RedisMulti> | null;
36
- subscribe: SubService<RedisClient, RedisMulti> | null;
37
- router: Router | null;
38
- logger: ILogger;
39
- reporting = false;
40
- inited: string;
41
- rollCallInterval: NodeJS.Timeout;
42
-
43
- static async init(
44
- namespace: string,
45
- appId: string,
46
- guid: string,
47
- config: HotMeshConfig,
48
- logger: ILogger
49
- ): Promise<WorkerService[]> {
50
- const services: WorkerService[] = [];
51
- if (Array.isArray(config.workers)) {
52
- for (const worker of config.workers) {
53
-
54
- await ConnectorService.initRedisClients(
55
- worker.redis?.class,
56
- worker.redis?.options,
57
- worker,
58
- );
59
-
60
- const service = new WorkerService();
61
- service.verifyWorkerFields(worker);
62
- service.namespace = namespace;
63
- service.appId = appId;
64
- service.guid = guid;
65
- service.callback = worker.callback;
66
- service.topic = worker.topic;
67
- service.config = config;
68
- service.logger = logger;
69
-
70
- await service.initStoreChannel(service, worker.store);
71
- await service.initSubChannel(service, worker.sub);
72
- await service.subscribe.subscribe(KeyType.QUORUM, service.subscriptionHandler(), appId);
73
- await service.subscribe.subscribe(KeyType.QUORUM, service.subscriptionHandler(), appId, service.topic);
74
- await service.subscribe.subscribe(KeyType.QUORUM, service.subscriptionHandler(), appId, service.guid);
75
- await service.initStreamChannel(service, worker.stream);
76
- service.router = service.initRouter(worker, logger);
77
-
78
- const key = service.stream.mintKey(KeyType.STREAMS, { appId: service.appId, topic: worker.topic });
79
- await service.router.consumeMessages(
80
- key,
81
- 'WORKER',
82
- service.guid,
83
- worker.callback
84
- );
85
- service.inited = formatISODate(new Date());
86
- services.push(service);
87
- }
88
- }
89
- return services;
90
- }
91
-
92
- verifyWorkerFields(worker: HotMeshWorker) {
93
- if ((!identifyRedisType(worker.store) ||
94
- !identifyRedisType(worker.stream)||
95
- !identifyRedisType(worker.sub)) ||
96
- !(worker.topic && worker.callback)) {
97
- throw new Error('worker must include `store`, `stream`, and `sub` fields along with a callback function and topic.');
98
- }
99
- }
100
-
101
- async initStoreChannel(service: WorkerService, store: RedisClient) {
102
- if (identifyRedisType(store) === 'redis') {
103
- service.store = new RedisStore(store as RedisClientType);
104
- } else {
105
- service.store = new IORedisStore(store as IORedisClientType);
106
- }
107
- await service.store.init(
108
- service.namespace,
109
- service.appId,
110
- service.logger
111
- );
112
- }
113
-
114
- async initSubChannel(service: WorkerService, sub: RedisClient) {
115
- if (identifyRedisType(sub) === 'redis') {
116
- service.subscribe = new RedisSub(sub as RedisClientType);
117
- } else {
118
- service.subscribe = new IORedisSub(sub as IORedisClientType);
119
- }
120
- await service.subscribe.init(
121
- service.namespace,
122
- service.appId,
123
- service.guid,
124
- service.logger
125
- );
126
- }
127
-
128
- async initStreamChannel(service: WorkerService, stream: RedisClient) {
129
- if (identifyRedisType(stream) === 'redis') {
130
- service.stream = new RedisStream(stream as RedisClientType);
131
- } else {
132
- service.stream = new IORedisStream(stream as IORedisClientType);
133
- }
134
- await service.stream.init(
135
- service.namespace,
136
- service.appId,
137
- service.logger
138
- );
139
- }
140
-
141
- initRouter(worker: HotMeshWorker, logger: ILogger): Router {
142
- return new Router(
143
- {
144
- namespace: this.namespace,
145
- appId: this.appId,
146
- guid: this.guid,
147
- role: StreamRole.WORKER,
148
- topic: worker.topic,
149
- reclaimDelay: worker.reclaimDelay,
150
- reclaimCount: worker.reclaimCount,
151
- },
152
- this.stream,
153
- this.store,
154
- logger,
155
- );
156
- }
157
-
158
- subscriptionHandler(): SubscriptionCallback {
159
- const self = this;
160
- return async (topic: string, message: QuorumMessage) => {
161
- self.logger.debug('worker-event-received', { topic, type: message.type });
162
- if (message.type === 'throttle') {
163
- if (message.topic !== null) { //undefined allows passthrough
164
- self.throttle(message.throttle);
165
- }
166
- } else if(message.type === 'ping') {
167
- self.sayPong(self.appId, self.guid, message.originator, message.details);
168
- } else if(message.type === 'rollcall') {
169
- if (message.topic !== null) { //undefined allows passthrough
170
- self.doRollCall(message);
171
- }
172
- }
173
- };
174
- }
175
-
176
- /**
177
- * A quorum-wide command to broadcaset system details.
178
- *
179
- */
180
- async doRollCall(message: RollCallMessage) {
181
- let iteration = 0;
182
- let max = !isNaN(message.max) ? message.max : HMSH_QUORUM_ROLLCALL_CYCLES;
183
- if (this.rollCallInterval) clearTimeout(this.rollCallInterval);
184
- const base = (message.interval / 2);
185
- const amount = base + Math.ceil(Math.random() * base);
186
- do {
187
- await sleepFor(Math.ceil(Math.random() * 1000));
188
- await this.sayPong(this.appId, this.guid, null, true, message.signature);
189
- if (!message.interval) return;
190
- const { promise, timerId } = XSleepFor(amount * 1000);
191
- this.rollCallInterval = timerId;
192
- await promise;
193
- } while (this.rollCallInterval && iteration++ < max - 1);
194
- }
195
-
196
- cancelRollCall() {
197
- if (this.rollCallInterval) {
198
- clearTimeout(this.rollCallInterval);
199
- delete this.rollCallInterval;
200
- }
201
- }
202
-
203
- stop() {
204
- this.cancelRollCall();
205
- }
206
-
207
- async sayPong(appId: string, guid: string, originator?: string, details = false, signature = false) {
208
- let profile: QuorumProfile;
209
- if (details) {
210
- const params = {
211
- appId: this.appId,
212
- topic: this.topic,
213
- };
214
-
215
- profile = {
216
- engine_id: this.guid,
217
- namespace: this.namespace,
218
- app_id: this.appId,
219
- worker_topic: this.topic,
220
- stream: this.stream.mintKey(KeyType.STREAMS, params),
221
- counts: this.router.counts,
222
- timestamp: formatISODate(new Date()),
223
- inited: this.inited,
224
- throttle: this.router.throttle,
225
- reclaimDelay: this.router.reclaimDelay,
226
- reclaimCount: this.router.reclaimCount,
227
- system: await getSystemHealth(),
228
- signature: signature ? this.callback.toString() : undefined,
229
- };
230
- }
231
- this.store.publish(
232
- KeyType.QUORUM,
233
- {
234
- type: 'pong',
235
- guid,
236
- originator,
237
- profile,
238
- },
239
- appId,
240
- );
241
- }
242
-
243
- async throttle(delayInMillis: number) {
244
- this.router.setThrottle(delayInMillis);
245
- }
246
- }
247
-
248
- export { WorkerService };
@@ -1,10 +0,0 @@
1
- import { Redis, ChainableCommander, RedisOptions } from 'ioredis';
2
-
3
- type RedisClassType = { new (options: RedisOptions): Redis };
4
-
5
- export {
6
- RedisClassType,
7
- Redis as RedisClientType,
8
- ChainableCommander as RedisMultiType,
9
- RedisOptions as RedisClientOptions,
10
- }
@@ -1,30 +0,0 @@
1
- import { createClient, RedisClientOptions } from 'redis';
2
-
3
- type RedisClientType = ReturnType<typeof createClient>;
4
-
5
- interface RedisMultiType {
6
- XADD(key: string, id: string, fields: any): this;
7
- XACK(key: string, group: string, id: string): this;
8
- XDEL(key: string, id: string): this;
9
- XLEN(key: string): this;
10
- HDEL(key: string, itemId: string): this;
11
- HGET(key: string, itemId: string): this;
12
- HGETALL(key: string): this;
13
- HINCRBYFLOAT(key: string, itemId: string, value: number): this;
14
- HMGET(key: string, itemIds: string[]): this;
15
- HSET(key: string, values: Record<string, string>): this;
16
- LRANGE(key: string, start: number, end: number): this;
17
- RPUSH(key: string, value: string): this;
18
- ZADD(key: string, values: { score: string, value: string }): this;
19
- sendCommand(command: string[]): Promise<any>;
20
- exec: () => Promise<unknown[]>;
21
- }
22
-
23
- type RedisClassType = { createClient: (options: RedisClientOptions) => any };
24
-
25
- export {
26
- RedisClassType,
27
- RedisClientType,
28
- RedisMultiType,
29
- RedisClientOptions,
30
- }