@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,158 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WorkerService = void 0;
4
- const key_1 = require("../../modules/key");
5
- const utils_1 = require("../../modules/utils");
6
- const connector_1 = require("../connector");
7
- const router_1 = require("../router");
8
- const stream_1 = require("../../types/stream");
9
- const enums_1 = require("../../modules/enums");
10
- const factory_1 = require("../stream/factory");
11
- const factory_2 = require("../sub/factory");
12
- const factory_3 = require("../store/factory");
13
- class WorkerService {
14
- constructor() {
15
- this.reporting = false;
16
- }
17
- static async init(namespace, appId, guid, config, logger) {
18
- const services = [];
19
- if (Array.isArray(config.workers)) {
20
- for (const worker of config.workers) {
21
- await connector_1.ConnectorService.initRedisClients(worker.redis?.class, worker.redis?.options, worker);
22
- const service = new WorkerService();
23
- service.verifyWorkerFields(worker);
24
- service.namespace = namespace;
25
- service.appId = appId;
26
- service.guid = guid;
27
- service.callback = worker.callback;
28
- service.topic = worker.topic;
29
- service.config = config;
30
- service.logger = logger;
31
- await service.initStoreChannel(service, worker.store);
32
- await service.initSubChannel(service, worker.sub);
33
- await service.subscribe.subscribe(key_1.KeyType.QUORUM, service.subscriptionHandler(), appId);
34
- await service.subscribe.subscribe(key_1.KeyType.QUORUM, service.subscriptionHandler(), appId, service.topic);
35
- await service.subscribe.subscribe(key_1.KeyType.QUORUM, service.subscriptionHandler(), appId, service.guid);
36
- await service.initStreamChannel(service, worker.stream);
37
- service.router = await service.initRouter(worker, logger);
38
- const key = service.stream.mintKey(key_1.KeyType.STREAMS, {
39
- appId: service.appId,
40
- topic: worker.topic,
41
- });
42
- await service.router.consumeMessages(key, 'WORKER', service.guid, worker.callback);
43
- service.inited = (0, utils_1.formatISODate)(new Date());
44
- services.push(service);
45
- }
46
- }
47
- return services;
48
- }
49
- verifyWorkerFields(worker) {
50
- if (!(0, utils_1.identifyRedisType)(worker.store) ||
51
- !(0, utils_1.identifyRedisType)(worker.stream) ||
52
- !(0, utils_1.identifyRedisType)(worker.sub) ||
53
- !(worker.topic && worker.callback)) {
54
- throw new Error('worker must include `store`, `stream`, and `sub` fields along with a callback function and topic.');
55
- }
56
- }
57
- async initStoreChannel(service, store) {
58
- service.store = await factory_3.StoreServiceFactory.init(store, service.namespace, service.appId, service.logger);
59
- }
60
- async initSubChannel(service, sub) {
61
- service.subscribe = await factory_2.SubServiceFactory.init(sub, service.namespace, service.appId, service.guid, service.logger);
62
- }
63
- async initStreamChannel(service, stream) {
64
- service.stream = await factory_1.StreamServiceFactory.init(stream, service.namespace, service.appId, service.logger);
65
- }
66
- async initRouter(worker, logger) {
67
- const throttle = await this.store.getThrottleRate(worker.topic);
68
- return new router_1.Router({
69
- namespace: this.namespace,
70
- appId: this.appId,
71
- guid: this.guid,
72
- role: stream_1.StreamRole.WORKER,
73
- topic: worker.topic,
74
- reclaimDelay: worker.reclaimDelay,
75
- reclaimCount: worker.reclaimCount,
76
- throttle,
77
- }, this.stream, this.store, logger);
78
- }
79
- subscriptionHandler() {
80
- const self = this;
81
- return async (topic, message) => {
82
- self.logger.debug('worker-event-received', { topic, type: message.type });
83
- if (message.type === 'throttle') {
84
- if (message.topic !== null) {
85
- self.throttle(message.throttle);
86
- }
87
- }
88
- else if (message.type === 'ping') {
89
- self.sayPong(self.appId, self.guid, message.originator, message.details);
90
- }
91
- else if (message.type === 'rollcall') {
92
- if (message.topic !== null) {
93
- self.doRollCall(message);
94
- }
95
- }
96
- };
97
- }
98
- async doRollCall(message) {
99
- let iteration = 0;
100
- const max = !isNaN(message.max) ? message.max : enums_1.HMSH_QUORUM_ROLLCALL_CYCLES;
101
- if (this.rollCallInterval)
102
- clearTimeout(this.rollCallInterval);
103
- const base = message.interval / 2;
104
- const amount = base + Math.ceil(Math.random() * base);
105
- do {
106
- await (0, utils_1.sleepFor)(Math.ceil(Math.random() * 1000));
107
- await this.sayPong(this.appId, this.guid, null, true, message.signature);
108
- if (!message.interval)
109
- return;
110
- const { promise, timerId } = (0, utils_1.XSleepFor)(amount * 1000);
111
- this.rollCallInterval = timerId;
112
- await promise;
113
- } while (this.rollCallInterval && iteration++ < max - 1);
114
- }
115
- cancelRollCall() {
116
- if (this.rollCallInterval) {
117
- clearTimeout(this.rollCallInterval);
118
- delete this.rollCallInterval;
119
- }
120
- }
121
- stop() {
122
- this.cancelRollCall();
123
- }
124
- async sayPong(appId, guid, originator, details = false, signature = false) {
125
- let profile;
126
- if (details) {
127
- const params = {
128
- appId: this.appId,
129
- topic: this.topic,
130
- };
131
- profile = {
132
- engine_id: this.guid,
133
- namespace: this.namespace,
134
- app_id: this.appId,
135
- worker_topic: this.topic,
136
- stream: this.stream.mintKey(key_1.KeyType.STREAMS, params),
137
- counts: this.router.counts,
138
- timestamp: (0, utils_1.formatISODate)(new Date()),
139
- inited: this.inited,
140
- throttle: this.router.throttle,
141
- reclaimDelay: this.router.reclaimDelay,
142
- reclaimCount: this.router.reclaimCount,
143
- system: await (0, utils_1.getSystemHealth)(),
144
- signature: signature ? this.callback.toString() : undefined,
145
- };
146
- }
147
- this.store.publish(key_1.KeyType.QUORUM, {
148
- type: 'pong',
149
- guid,
150
- originator,
151
- profile,
152
- }, appId);
153
- }
154
- async throttle(delayInMillis) {
155
- this.router.setThrottle(delayInMillis);
156
- }
157
- }
158
- exports.WorkerService = WorkerService;
1
+ 'use strict';function _0x497c(_0x38dc5f,_0x462aee){const _0x25abf1=_0x25ab();return _0x497c=function(_0x497cd5,_0x22ecb7){_0x497cd5=_0x497cd5-0x84;let _0x86423=_0x25abf1[_0x497cd5];return _0x86423;},_0x497c(_0x38dc5f,_0x462aee);}(function(_0x1274a7,_0x1fe865){const _0x2e7ce1=_0x497c,_0x4d508a=_0x1274a7();while(!![]){try{const _0x57250b=-parseInt(_0x2e7ce1(0x89))/0x1+parseInt(_0x2e7ce1(0x8c))/0x2+parseInt(_0x2e7ce1(0x88))/0x3*(parseInt(_0x2e7ce1(0x86))/0x4)+-parseInt(_0x2e7ce1(0x84))/0x5*(-parseInt(_0x2e7ce1(0x8b))/0x6)+-parseInt(_0x2e7ce1(0x8a))/0x7+-parseInt(_0x2e7ce1(0x8d))/0x8+-parseInt(_0x2e7ce1(0x87))/0x9*(-parseInt(_0x2e7ce1(0x85))/0xa);if(_0x57250b===_0x1fe865)break;else _0x4d508a['push'](_0x4d508a['shift']());}catch(_0x2a083c){_0x4d508a['push'](_0x4d508a['shift']());}}}(_0x25ab,0x673a4));function _0x25ab(){const _0x150e97=['984954DLiNBV','5436104YqaBpX','5wBQIEU','543070QtxOpk','103088sLWsde','63dTsUKK','72FfkDdv','437999mtVKFR','4981067xBLTrV','4564554xZBENy'];_0x25ab=function(){return _0x150e97;};return _0x25ab();}Object['defineProperty'](exports,'__esModule',{'value':!![]}),exports['WorkerService']=void 0x0;const key_1=require('../../modules/key'),utils_1=require('../../modules/utils'),connector_1=require('../connector'),router_1=require('../router'),stream_1=require('../../types/stream'),enums_1=require('../../modules/enums'),factory_1=require('../stream/factory'),factory_2=require('../sub/factory'),factory_3=require('../store/factory');class WorkerService{constructor(){this['reporting']=![];}static async['init'](_0x3bfd1e,_0x47f5b0,_0x3ad826,_0x23c0b1,_0x20aacf){const _0x2b66a5=[];if(Array['isArray'](_0x23c0b1['workers']))for(const _0x3047fd of _0x23c0b1['workers']){await connector_1['ConnectorService']['initRedisClients'](_0x3047fd['redis']?.['class'],_0x3047fd['redis']?.['options'],_0x3047fd);const _0x5820fd=new WorkerService();_0x5820fd['verifyWorkerFields'](_0x3047fd),_0x5820fd['namespace']=_0x3bfd1e,_0x5820fd['appId']=_0x47f5b0,_0x5820fd['guid']=_0x3ad826,_0x5820fd['callback']=_0x3047fd['callback'],_0x5820fd['topic']=_0x3047fd['topic'],_0x5820fd['config']=_0x23c0b1,_0x5820fd['logger']=_0x20aacf,await _0x5820fd['initStoreChannel'](_0x5820fd,_0x3047fd['store']),await _0x5820fd['initSubChannel'](_0x5820fd,_0x3047fd['sub'],_0x3047fd['store']),await _0x5820fd['subscribe']['subscribe'](key_1['KeyType']['QUORUM'],_0x5820fd['subscriptionHandler'](),_0x47f5b0),await _0x5820fd['subscribe']['subscribe'](key_1['KeyType']['QUORUM'],_0x5820fd['subscriptionHandler'](),_0x47f5b0,_0x5820fd['topic']),await _0x5820fd['subscribe']['subscribe'](key_1['KeyType']['QUORUM'],_0x5820fd['subscriptionHandler'](),_0x47f5b0,_0x5820fd['guid']),await _0x5820fd['initStreamChannel'](_0x5820fd,_0x3047fd['stream'],_0x3047fd['store']),_0x5820fd['router']=await _0x5820fd['initRouter'](_0x3047fd,_0x20aacf);const _0x29a4c1=_0x5820fd['store']['mintKey'](key_1['KeyType']['STREAMS'],{'appId':_0x5820fd['appId'],'topic':_0x3047fd['topic']});await _0x5820fd['router']['consumeMessages'](_0x29a4c1,'WORKER',_0x5820fd['guid'],_0x3047fd['callback']),_0x5820fd['inited']=(0x0,utils_1['formatISODate'])(new Date()),_0x2b66a5['push'](_0x5820fd);}return _0x2b66a5;}['verifyWorkerFields'](_0x5640c6){if(!(0x0,utils_1['identifyRedisType'])(_0x5640c6['store'])||!(0x0,utils_1['identifyRedisType'])(_0x5640c6['stream'])||!(0x0,utils_1['identifyRedisType'])(_0x5640c6['sub'])||!(_0x5640c6['topic']&&_0x5640c6['callback']))throw new Error('worker\x20must\x20include\x20`store`,\x20`stream`,\x20and\x20`sub`\x20fields\x20along\x20with\x20a\x20callback\x20function\x20and\x20topic.');}async['initStoreChannel'](_0x396a24,_0x116528){_0x396a24['store']=await factory_3['StoreServiceFactory']['init'](_0x116528,_0x396a24['namespace'],_0x396a24['appId'],_0x396a24['logger']);}async['initSubChannel'](_0x4b1730,_0x359445,_0x13abeb){_0x4b1730['subscribe']=await factory_2['SubServiceFactory']['init'](_0x359445,_0x13abeb,_0x4b1730['namespace'],_0x4b1730['appId'],_0x4b1730['guid'],_0x4b1730['logger']);}async['initStreamChannel'](_0x49ac67,_0x21cdbd,_0x33524a){_0x49ac67['stream']=await factory_1['StreamServiceFactory']['init'](_0x21cdbd,_0x33524a,_0x49ac67['namespace'],_0x49ac67['appId'],_0x49ac67['logger']);}async['initRouter'](_0x59b70a,_0x3c7f56){const _0x52c934=await this['store']['getThrottleRate'](_0x59b70a['topic']);return new router_1['Router']({'namespace':this['namespace'],'appId':this['appId'],'guid':this['guid'],'role':stream_1['StreamRole']['WORKER'],'topic':_0x59b70a['topic'],'reclaimDelay':_0x59b70a['reclaimDelay'],'reclaimCount':_0x59b70a['reclaimCount'],'throttle':_0x52c934},this['stream'],this['store'],_0x3c7f56);}['subscriptionHandler'](){const _0x28c6df=this;return async(_0x53f0b2,_0x40885f)=>{_0x28c6df['logger']['debug']('worker-event-received',{'topic':_0x53f0b2,'type':_0x40885f['type']});if(_0x40885f['type']==='throttle')_0x40885f['topic']!==null&&_0x28c6df['throttle'](_0x40885f['throttle']);else{if(_0x40885f['type']==='ping')_0x28c6df['sayPong'](_0x28c6df['appId'],_0x28c6df['guid'],_0x40885f['originator'],_0x40885f['details']);else _0x40885f['type']==='rollcall'&&(_0x40885f['topic']!==null&&_0x28c6df['doRollCall'](_0x40885f));}};}async['doRollCall'](_0x49073f){let _0x133a93=0x0;const _0x45d300=!isNaN(_0x49073f['max'])?_0x49073f['max']:enums_1['HMSH_QUORUM_ROLLCALL_CYCLES'];if(this['rollCallInterval'])clearTimeout(this['rollCallInterval']);const _0x332c8e=_0x49073f['interval']/0x2,_0x364b69=_0x332c8e+Math['ceil'](Math['random']()*_0x332c8e);do{await(0x0,utils_1['sleepFor'])(Math['ceil'](Math['random']()*0x3e8)),await this['sayPong'](this['appId'],this['guid'],null,!![],_0x49073f['signature']);if(!_0x49073f['interval'])return;const {promise:_0x4fba86,timerId:_0xa19f6}=(0x0,utils_1['XSleepFor'])(_0x364b69*0x3e8);this['rollCallInterval']=_0xa19f6,await _0x4fba86;}while(this['rollCallInterval']&&_0x133a93++<_0x45d300-0x1);}['cancelRollCall'](){this['rollCallInterval']&&(clearTimeout(this['rollCallInterval']),delete this['rollCallInterval']);}['stop'](){this['cancelRollCall']();}async['sayPong'](_0x11a836,_0x4b2c72,_0x186aa5,_0x2238a7=![],_0x5bb69c=![]){let _0x31e7d8;if(_0x2238a7){const _0x534459={'appId':this['appId'],'topic':this['topic']};_0x31e7d8={'engine_id':this['guid'],'namespace':this['namespace'],'app_id':this['appId'],'worker_topic':this['topic'],'stream':this['store']['mintKey'](key_1['KeyType']['STREAMS'],_0x534459),'counts':this['router']['counts'],'timestamp':(0x0,utils_1['formatISODate'])(new Date()),'inited':this['inited'],'throttle':this['router']['throttle'],'reclaimDelay':this['router']['reclaimDelay'],'reclaimCount':this['router']['reclaimCount'],'system':await(0x0,utils_1['getSystemHealth'])(),'signature':_0x5bb69c?this['callback']['toString']():undefined};}this['subscribe']['publish'](key_1['KeyType']['QUORUM'],{'type':'pong','guid':_0x4b2c72,'originator':_0x186aa5,'profile':_0x31e7d8},_0x11a836);}async['throttle'](_0x4e7086){this['router']['setThrottle'](_0x4e7086);}}exports['WorkerService']=WorkerService;
@@ -66,7 +66,7 @@ interface RedisRedisMultiType {
66
66
  DEL(key: string): this;
67
67
  EXISTS(key: string): this;
68
68
  EXPIRE(key: string, seconds: number): this;
69
- HDEL(key: string, itemId: string): this;
69
+ HDEL(key: string, fields: string[] | string): this;
70
70
  HGET(key: string, itemId: string): this;
71
71
  HGETALL(key: string): this;
72
72
  HINCRBYFLOAT(key: string, itemId: string, value: number): this;
@@ -115,12 +115,12 @@ interface RedisRedisClientType {
115
115
  XLEN(key: string): Promise<number>;
116
116
  DEL(key: string): Promise<number>;
117
117
  EXISTS(key: string): Promise<number>;
118
- HDEL(key: string, itemId: string): Promise<number>;
118
+ HDEL(key: string, fields: string[] | string): Promise<number>;
119
119
  HGET(key: string, itemId: string): Promise<string | null>;
120
120
  HGETALL(key: string): Promise<StringStringType>;
121
121
  HINCRBYFLOAT(key: string, itemId: string, value: number): Promise<number>;
122
122
  HMGET(key: string, itemIds: string[]): Promise<string[]>;
123
- HSET(key: string, values: Record<string, string>): this;
123
+ HSET(key: string, values: Record<string, string>): Promise<number>;
124
124
  LPUSH(key: string, items: string[]): Promise<number>;
125
125
  LRANGE(key: string, start: number, end: number): Promise<string[]>;
126
126
  RPUSH(key: string, items: string[]): Promise<number>;
@@ -185,12 +185,12 @@ interface IORedisClient {
185
185
  del(key: string): Promise<number>;
186
186
  exists(key: string): Promise<number>;
187
187
  get(key: string): Promise<string | null>;
188
- hdel(key: string, itemId: string): Promise<number>;
188
+ hdel(key: string, ...fields: string[]): Promise<number>;
189
189
  hget(key: string, itemId: string): Promise<string | null>;
190
190
  hgetall(key: string): Promise<StringStringType>;
191
191
  hincrbyfloat(key: string, itemId: string, value: number): Promise<number>;
192
192
  hmget(key: string, itemIds: string[]): Promise<string[]>;
193
- hset(key: string, values: Record<string, string>): this;
193
+ hset(key: string, values: Record<string, string>): Promise<number>;
194
194
  lpush(key: string, ...args: string[]): Promise<number>;
195
195
  lrange(key: string, start: number, end: number): Promise<string[]>;
196
196
  on(event: string, callback: (...args: any[]) => void): void;
package/index.ts CHANGED
@@ -5,6 +5,20 @@ import { MeshFlow } from './services/meshflow';
5
5
  import { MeshData } from './services/meshdata';
6
6
  import { MeshOS } from './services/meshos';
7
7
 
8
- export { HotMesh, HotMeshConfig, MeshCall, MeshData, MeshFlow, MeshOS };
8
+ const { Client, Connection, Search, Worker, workflow} = MeshFlow;
9
+
10
+ export {
11
+ HotMesh,
12
+ HotMeshConfig,
13
+ MeshCall,
14
+ MeshData,
15
+ MeshOS,
16
+ MeshFlow,
17
+ Client,
18
+ Connection,
19
+ Search,
20
+ Worker,
21
+ workflow,
22
+ };
9
23
 
10
24
  export * as Types from './types';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hotmeshio/hotmesh",
3
- "version": "0.3.6",
3
+ "version": "0.3.7",
4
4
  "description": "Unbreakable Workflows",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -13,9 +13,11 @@
13
13
  "access": "public"
14
14
  },
15
15
  "scripts": {
16
- "build": "tsc --build tsconfig.json",
17
16
  "clean": "rimraf ./build",
17
+ "build": "tsc --build tsconfig.json",
18
+ "obfuscate": "ts-node scripts/obfuscate.ts",
18
19
  "clean-build": "npm run clean && npm run build",
20
+ "clean-build-obfuscate": "npm run clean-build && npm run obfuscate",
19
21
  "lint": "eslint . --ext .ts",
20
22
  "lint:fix": "eslint . --fix --ext .ts",
21
23
  "start": "ts-node src/index.ts",
@@ -51,17 +53,18 @@
51
53
  "test:quorum": "HMSH_IS_CLUSTER=true NODE_ENV=test jest ./tests/functional/quorum/index.test.ts --detectOpenHandles --forceExit --verbose",
52
54
  "test:reclaim": "NODE_ENV=test jest ./tests/functional/reclaim/index.test.ts --detectOpenHandles --forceExit --verbose",
53
55
  "test:redeploy": "NODE_ENV=test jest ./tests/functional/redeploy/index.test.ts --detectOpenHandles --forceExit --verbose",
56
+ "test:reporter": "NODE_ENV=test jest ./tests/unit/services/reporter/index.test.ts --detectOpenHandles --forceExit --verbose",
54
57
  "test:reentrant": "NODE_ENV=test jest ./tests/functional/reentrant/index.test.ts --detectOpenHandles --forceExit --verbose",
55
58
  "test:retry": "NODE_ENV=test jest ./tests/functional/retry/index.test.ts --detectOpenHandles --forceExit --verbose",
56
59
  "test:sequence": "NODE_ENV=test jest ./tests/functional/sequence/index.test.ts --detectOpenHandles --forceExit --verbose",
57
60
  "test:signal": "NODE_ENV=test jest ./tests/functional/signal/index.test.ts --detectOpenHandles --forceExit --verbose",
58
61
  "test:status": "NODE_ENV=test jest ./tests/functional/status/index.test.ts --detectOpenHandles --forceExit --verbose",
59
- "test:store:ioredis": "NODE_ENV=test jest ./tests/functional/store/clients/ioredis.test.ts --detectOpenHandles --forceExit --verbose",
60
- "test:store:redis": "NODE_ENV=test jest ./tests/functional/store/clients/redis.test.ts --detectOpenHandles --forceExit --verbose",
61
- "test:stream:ioredis": "NODE_ENV=test jest ./tests/functional/stream/clients/ioredis.test.ts --detectOpenHandles --forceExit --verbose",
62
- "test:stream:redis": "NODE_ENV=test jest ./tests/functional/stream/clients/redis.test.ts --detectOpenHandles --forceExit --verbose",
63
- "test:sub:ioredis": "NODE_ENV=test jest ./tests/functional/sub/clients/ioredis.test.ts --detectOpenHandles --forceExit --verbose",
64
- "test:sub:redis": "NODE_ENV=test jest ./tests/functional/sub/clients/redis.test.ts --detectOpenHandles --forceExit --verbose",
62
+ "test:store:ioredis": "NODE_ENV=test jest ./tests/functional/store/providers/redis/ioredis.test.ts --detectOpenHandles --forceExit --verbose",
63
+ "test:store:redis": "NODE_ENV=test jest ./tests/functional/store/providers/redis/redis.test.ts --detectOpenHandles --forceExit --verbose",
64
+ "test:stream:ioredis": "NODE_ENV=test jest ./tests/functional/stream/providers/redis/ioredis.test.ts --detectOpenHandles --forceExit --verbose",
65
+ "test:stream:redis": "NODE_ENV=test jest ./tests/functional/stream/providers/redis/redis.test.ts --detectOpenHandles --forceExit --verbose",
66
+ "test:sub:ioredis": "NODE_ENV=test jest ./tests/functional/sub/providers/redis/ioredis.test.ts --detectOpenHandles --forceExit --verbose",
67
+ "test:sub:redis": "NODE_ENV=test jest ./tests/functional/sub/providers/redis/redis.test.ts --detectOpenHandles --forceExit --verbose",
65
68
  "test:trigger": "NODE_ENV=test jest ./tests/unit/services/activities/trigger.test.ts --detectOpenHandles --forceExit --verbose",
66
69
  "test:meshdata": "NODE_ENV=test HMSH_IS_CLUSTER=true jest ./tests/meshdata/index.test.ts --forceExit --verbose --detectOpenHandles",
67
70
  "test:meshos": "NODE_ENV=test HMSH_IS_CLUSTER=true jest ./tests/meshos/index.test.ts --forceExit --verbose --detectOpenHandles",
@@ -100,6 +103,7 @@
100
103
  "eslint-plugin-import": "^2.29.1",
101
104
  "eslint-plugin-prettier": "^5.1.3",
102
105
  "ioredis": "^5.3.2",
106
+ "javascript-obfuscator": "^4.1.1",
103
107
  "jest": "^29.5.0",
104
108
  "redis": "^4.6.13",
105
109
  "rimraf": "^4.4.1",
package/types/redis.ts CHANGED
@@ -75,7 +75,7 @@ interface RedisRedisMultiType {
75
75
  DEL(key: string): this;
76
76
  EXISTS(key: string): this;
77
77
  EXPIRE(key: string, seconds: number): this;
78
- HDEL(key: string, itemId: string): this;
78
+ HDEL(key: string, fields: string[] | string): this;
79
79
  HGET(key: string, itemId: string): this;
80
80
  HGETALL(key: string): this;
81
81
  HINCRBYFLOAT(key: string, itemId: string, value: number): this;
@@ -151,12 +151,12 @@ interface RedisRedisClientType {
151
151
  XLEN(key: string): Promise<number>;
152
152
  DEL(key: string): Promise<number>;
153
153
  EXISTS(key: string): Promise<number>;
154
- HDEL(key: string, itemId: string): Promise<number>;
154
+ HDEL(key: string, fields: string[] | string): Promise<number>;
155
155
  HGET(key: string, itemId: string): Promise<string | null>;
156
156
  HGETALL(key: string): Promise<StringStringType>;
157
157
  HINCRBYFLOAT(key: string, itemId: string, value: number): Promise<number>;
158
158
  HMGET(key: string, itemIds: string[]): Promise<string[]>;
159
- HSET(key: string, values: Record<string, string>): this;
159
+ HSET(key: string, values: Record<string, string>): Promise<number>;
160
160
  LPUSH(key: string, items: string[]): Promise<number>;
161
161
  LRANGE(key: string, start: number, end: number): Promise<string[]>;
162
162
  RPUSH(key: string, items: string[]): Promise<number>;
@@ -250,12 +250,12 @@ interface IORedisClient {
250
250
  del(key: string): Promise<number>;
251
251
  exists(key: string): Promise<number>;
252
252
  get(key: string): Promise<string | null>;
253
- hdel(key: string, itemId: string): Promise<number>;
253
+ hdel(key: string, ...fields: string[]): Promise<number>;
254
254
  hget(key: string, itemId: string): Promise<string | null>;
255
255
  hgetall(key: string): Promise<StringStringType>;
256
256
  hincrbyfloat(key: string, itemId: string, value: number): Promise<number>;
257
257
  hmget(key: string, itemIds: string[]): Promise<string[]>;
258
- hset(key: string, values: Record<string, string>): this;
258
+ hset(key: string, values: Record<string, string>): Promise<number>;
259
259
  lpush(key: string, ...args: string[]): Promise<number>;
260
260
  lrange(key: string, start: number, end: number): Promise<string[]>;
261
261
  on(event: string, callback: (...args: any[]) => void): void;
@@ -1,30 +0,0 @@
1
- import { KeyType } from '../../../modules/key';
2
- import { ILogger } from '../../logger';
3
- import { SerializerService as Serializer } from '../../serializer';
4
- import { Cache } from '../cache';
5
- import { StoreService } from '../index';
6
- import { IORedisClientType as RedisClientType, IORedisMultiType as RedisMultiType } from '../../../types/redis';
7
- import { ReclaimedMessageType } from '../../../types/stream';
8
- declare class IORedisStoreService extends StoreService<RedisClientType, RedisMultiType> {
9
- redisClient: RedisClientType;
10
- cache: Cache;
11
- namespace: string;
12
- appId: string;
13
- logger: ILogger;
14
- serializer: Serializer;
15
- constructor(redisClient: RedisClientType);
16
- getMulti(): RedisMultiType;
17
- exec(...args: any[]): Promise<string | string[] | string[][]>;
18
- setnxex(key: string, value: string, expireSeconds: number): Promise<boolean>;
19
- hGetAllResult(result: any): any;
20
- addTaskQueues(keys: string[]): Promise<void>;
21
- publish(keyType: KeyType.QUORUM, message: Record<string, any>, appId: string, engineId?: string): Promise<boolean>;
22
- xgroup(command: 'CREATE', key: string, groupName: string, id: string, mkStream?: 'MKSTREAM'): Promise<boolean>;
23
- xadd(key: string, id: string, messageId: string, messageValue: string, multi?: RedisMultiType): Promise<string | RedisMultiType>;
24
- xpending(key: string, group: string, start?: string, end?: string, count?: number, consumer?: string): Promise<[string, string, number, [string, number][]][] | [string, string, number, number] | unknown[]>;
25
- xclaim(key: string, group: string, consumer: string, minIdleTime: number, id: string, ...args: string[]): Promise<ReclaimedMessageType>;
26
- xack(key: string, group: string, id: string, multi?: RedisMultiType): Promise<number | RedisMultiType>;
27
- xdel(key: string, id: string, multi?: RedisMultiType): Promise<number | RedisMultiType>;
28
- xlen(key: string, multi?: RedisMultiType): Promise<number | RedisMultiType>;
29
- }
30
- export { IORedisStoreService };
@@ -1,220 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IORedisStoreService = void 0;
4
- const key_1 = require("../../../modules/key");
5
- const index_1 = require("../index");
6
- const enums_1 = require("../../../modules/enums");
7
- class IORedisStoreService extends index_1.StoreService {
8
- constructor(redisClient) {
9
- super(redisClient);
10
- }
11
- getMulti() {
12
- const my = this;
13
- if (enums_1.HMSH_IS_CLUSTER) {
14
- const commands = [];
15
- const addCommand = (command, args) => {
16
- commands.push({ command, args });
17
- return multiInstance;
18
- };
19
- const multiInstance = {
20
- sendCommand(command) {
21
- return my.redisClient.sendCommand(command);
22
- },
23
- async exec() {
24
- if (commands.length === 0)
25
- return [];
26
- const sameKey = commands.every((cmd) => {
27
- return cmd.args[0] === commands[0].args[0];
28
- });
29
- if (sameKey) {
30
- const multi = my.redisClient.multi();
31
- commands.forEach((cmd) => multi[cmd.command](...cmd.args));
32
- const results = await multi.exec();
33
- return results.map((item) => item);
34
- }
35
- else {
36
- return Promise.all(commands.map((cmd) => my.redisClient[cmd.command](...cmd.args)));
37
- }
38
- },
39
- xadd(key, id, fields, message) {
40
- return addCommand('xadd', [key, id, fields, message]);
41
- },
42
- xack(key, group, id) {
43
- return addCommand('xack', [key, group, id]);
44
- },
45
- xdel(key, id) {
46
- return addCommand('xdel', [key, id]);
47
- },
48
- xlen(key) {
49
- return addCommand('xlen', [key]);
50
- },
51
- xpending(key, group, start, end, count, consumer) {
52
- return addCommand('xpending', [
53
- key,
54
- group,
55
- start,
56
- end,
57
- count,
58
- consumer,
59
- ]);
60
- },
61
- xclaim(key, group, consumer, minIdleTime, id, ...args) {
62
- return addCommand('xclaim', [
63
- key,
64
- group,
65
- consumer,
66
- minIdleTime,
67
- id,
68
- ...args,
69
- ]);
70
- },
71
- del(key) {
72
- return addCommand('del', [key]);
73
- },
74
- expire: function (key, seconds) {
75
- return addCommand('expire', [key, seconds]);
76
- },
77
- hdel(key, itemId) {
78
- return addCommand('hdel', [key, itemId]);
79
- },
80
- hget(key, itemId) {
81
- return addCommand('hget', [key, itemId]);
82
- },
83
- hgetall(key) {
84
- return addCommand('hgetall', [key]);
85
- },
86
- hincrbyfloat(key, itemId, value) {
87
- return addCommand('hincrbyfloat', [key, itemId, value]);
88
- },
89
- hmget(key, itemIds) {
90
- return addCommand('hmget', [key, itemIds]);
91
- },
92
- hset(key, values) {
93
- return addCommand('hset', [key, values]);
94
- },
95
- lrange(key, start, end) {
96
- return addCommand('lrange', [key, start, end]);
97
- },
98
- rpush(key, value) {
99
- return addCommand('rpush', [key, value]);
100
- },
101
- zadd(...args) {
102
- return addCommand('zadd', args);
103
- },
104
- xgroup(command, key, groupName, id, mkStream) {
105
- return addCommand('xgroup', [command, key, groupName, id, mkStream]);
106
- },
107
- };
108
- return multiInstance;
109
- }
110
- return this.redisClient.multi();
111
- }
112
- async exec(...args) {
113
- const response = await this.redisClient.call.apply(this.redisClient, args);
114
- if (typeof response === 'string') {
115
- return response;
116
- }
117
- else if (Array.isArray(response)) {
118
- if (Array.isArray(response[0])) {
119
- return response;
120
- }
121
- return response;
122
- }
123
- return response;
124
- }
125
- async setnxex(key, value, expireSeconds) {
126
- const status = await this.redisClient[this.commands.set](key, value, 'NX', 'EX', expireSeconds.toString());
127
- return this.isSuccessful(status);
128
- }
129
- hGetAllResult(result) {
130
- return result[1];
131
- }
132
- async addTaskQueues(keys) {
133
- const multi = this.redisClient.multi();
134
- const zsetKey = this.mintKey(key_1.KeyType.WORK_ITEMS, { appId: this.appId });
135
- for (const key of keys) {
136
- multi.zadd(zsetKey, 'NX', Date.now(), key);
137
- }
138
- await multi.exec();
139
- }
140
- async publish(keyType, message, appId, engineId) {
141
- const topic = this.mintKey(keyType, { appId, engineId });
142
- const status = await this.redisClient.publish(topic, JSON.stringify(message));
143
- return status === 1;
144
- }
145
- async xgroup(command, key, groupName, id, mkStream) {
146
- if (mkStream === 'MKSTREAM') {
147
- try {
148
- return ((await this.redisClient.xgroup(command, key, groupName, id, mkStream)) === 'OK');
149
- }
150
- catch (err) {
151
- this.logger.debug('stream-mkstream-caught', { key, group: groupName });
152
- throw err;
153
- }
154
- }
155
- else {
156
- try {
157
- return ((await this.redisClient.xgroup(command, key, groupName, id)) === 'OK');
158
- }
159
- catch (err) {
160
- this.logger.debug(`Consumer group not created for key: ${key} and group: ${groupName}`);
161
- throw err;
162
- }
163
- }
164
- }
165
- async xadd(key, id, messageId, messageValue, multi) {
166
- try {
167
- return await (multi || this.redisClient).xadd(key, id, messageId, messageValue);
168
- }
169
- catch (error) {
170
- this.logger.error(`Error publishing 'xadd'; key: ${key}`, { ...error });
171
- throw error;
172
- }
173
- }
174
- async xpending(key, group, start, end, count, consumer) {
175
- try {
176
- return await this.redisClient.xpending(key, group, start, end, count, consumer);
177
- }
178
- catch (error) {
179
- this.logger.error(`Error in retrieving pending messages for [stream ${key}], [group ${group}]`, { ...error });
180
- throw error;
181
- }
182
- }
183
- async xclaim(key, group, consumer, minIdleTime, id, ...args) {
184
- try {
185
- return (await this.redisClient.xclaim(key, group, consumer, minIdleTime, id, ...args));
186
- }
187
- catch (error) {
188
- this.logger.error(`Error in claiming message with id: ${id} in group: ${group} for key: ${key}`, { ...error });
189
- throw error;
190
- }
191
- }
192
- async xack(key, group, id, multi) {
193
- try {
194
- return await (multi || this.redisClient).xack(key, group, id);
195
- }
196
- catch (error) {
197
- this.logger.error(`Error in acknowledging messages in group: ${group} for key: ${key}`, { ...error });
198
- throw error;
199
- }
200
- }
201
- async xdel(key, id, multi) {
202
- try {
203
- return await (multi || this.redisClient).xdel(key, id);
204
- }
205
- catch (error) {
206
- this.logger.error(`Error in deleting messages with id: ${id} for key: ${key}`, { ...error });
207
- throw error;
208
- }
209
- }
210
- async xlen(key, multi) {
211
- try {
212
- return await (multi || this.redisClient).xlen(key);
213
- }
214
- catch (error) {
215
- this.logger.error(`Error getting stream depth: ${key}`, { ...error });
216
- throw error;
217
- }
218
- }
219
- }
220
- exports.IORedisStoreService = IORedisStoreService;
@@ -1,32 +0,0 @@
1
- import { KeyType } from '../../../modules/key';
2
- import { ILogger } from '../../logger';
3
- import { SerializerService as Serializer } from '../../serializer';
4
- import { Cache } from '../cache';
5
- import { StoreService } from '../index';
6
- import { RedisRedisClientType as RedisClientType, RedisRedisMultiType as RedisMultiType } from '../../../types/redis';
7
- import { ReclaimedMessageType } from '../../../types/stream';
8
- declare class RedisStoreService extends StoreService<RedisClientType, RedisMultiType> {
9
- redisClient: RedisClientType;
10
- cache: Cache;
11
- namespace: string;
12
- appId: string;
13
- logger: ILogger;
14
- serializer: Serializer;
15
- commands: Record<string, string>;
16
- constructor(redisClient: RedisClientType);
17
- getMulti(): RedisMultiType;
18
- exec(...args: any[]): Promise<string | string[] | string[][]>;
19
- setnxex(key: string, value: string, expireSeconds: number): Promise<boolean>;
20
- publish(keyType: KeyType.QUORUM, message: Record<string, any>, appId: string, engineId?: string): Promise<boolean>;
21
- zAdd(key: string, score: number | string, value: string | number, redisMulti?: RedisMultiType): Promise<any>;
22
- zRangeByScoreWithScores(key: string, score: number | string, value: string | number): Promise<string | null>;
23
- zRangeByScore(key: string, score: number | string, value: string | number): Promise<string | null>;
24
- xgroup(command: 'CREATE', key: string, groupName: string, id: string, mkStream?: 'MKSTREAM'): Promise<boolean>;
25
- xadd(key: string, id: string, ...args: any[]): Promise<string | RedisMultiType>;
26
- xpending(key: string, group: string, start?: string, end?: string, count?: number, consumer?: string): Promise<[string, string, number, [string, number][]][] | [string, string, number, number]>;
27
- xclaim(key: string, group: string, consumer: string, minIdleTime: number, id: string, ...args: string[]): Promise<ReclaimedMessageType>;
28
- xack(key: string, group: string, id: string, multi?: RedisMultiType): Promise<number | RedisMultiType>;
29
- xdel(key: string, id: string, multi?: RedisMultiType): Promise<number | RedisMultiType>;
30
- xlen(key: string, multi?: RedisMultiType): Promise<number | RedisMultiType>;
31
- }
32
- export { RedisStoreService };