@hotmeshio/hotmesh 0.3.6 → 0.3.8

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 (124) hide show
  1. package/README.md +13 -1
  2. package/build/index.d.ts +3 -1
  3. package/build/index.js +10 -1
  4. package/build/modules/key.js +1 -62
  5. package/build/modules/utils.js +1 -267
  6. package/build/package.json +12 -8
  7. package/build/services/activities/activity.js +1 -495
  8. package/build/services/activities/await.js +1 -109
  9. package/build/services/activities/cycle.js +1 -96
  10. package/build/services/activities/hook.js +1 -154
  11. package/build/services/activities/index.js +1 -20
  12. package/build/services/activities/interrupt.js +1 -149
  13. package/build/services/activities/signal.js +1 -118
  14. package/build/services/activities/trigger.js +1 -237
  15. package/build/services/activities/worker.js +1 -101
  16. package/build/services/collator/index.js +1 -197
  17. package/build/services/compiler/deployer.d.ts +3 -1
  18. package/build/services/compiler/deployer.js +1 -455
  19. package/build/services/compiler/index.d.ts +3 -1
  20. package/build/services/compiler/index.js +1 -91
  21. package/build/services/compiler/validator.js +1 -122
  22. package/build/services/engine/index.d.ts +5 -2
  23. package/build/services/engine/index.js +1 -562
  24. package/build/services/exporter/index.js +1 -93
  25. package/build/services/mapper/index.js +1 -67
  26. package/build/services/meshdata/index.d.ts +0 -1
  27. package/build/services/meshdata/index.js +16 -24
  28. package/build/services/meshflow/client.js +4 -8
  29. package/build/services/meshflow/exporter.js +1 -186
  30. package/build/services/meshflow/index.d.ts +2 -0
  31. package/build/services/meshflow/index.js +2 -0
  32. package/build/services/meshflow/search.d.ts +4 -5
  33. package/build/services/meshflow/search.js +45 -35
  34. package/build/services/meshflow/workflow.d.ts +1 -1
  35. package/build/services/meshflow/workflow.js +3 -28
  36. package/build/services/pipe/functions/array.js +1 -74
  37. package/build/services/pipe/functions/bitwise.js +1 -24
  38. package/build/services/pipe/functions/conditional.js +1 -36
  39. package/build/services/pipe/functions/cron.js +1 -32
  40. package/build/services/pipe/functions/date.js +1 -164
  41. package/build/services/pipe/functions/index.js +1 -30
  42. package/build/services/pipe/functions/json.js +1 -12
  43. package/build/services/pipe/functions/logical.js +1 -12
  44. package/build/services/pipe/functions/math.js +1 -182
  45. package/build/services/pipe/functions/number.js +1 -60
  46. package/build/services/pipe/functions/object.js +1 -81
  47. package/build/services/pipe/functions/string.js +1 -69
  48. package/build/services/pipe/functions/symbol.js +1 -33
  49. package/build/services/pipe/functions/unary.js +1 -18
  50. package/build/services/pipe/index.js +1 -221
  51. package/build/services/quorum/index.d.ts +1 -1
  52. package/build/services/quorum/index.js +1 -219
  53. package/build/services/reporter/index.js +1 -331
  54. package/build/services/router/index.js +1 -420
  55. package/build/services/search/factory.d.ts +7 -0
  56. package/build/services/search/factory.js +20 -0
  57. package/build/services/search/index.d.ts +21 -0
  58. package/build/services/search/index.js +10 -0
  59. package/build/services/search/providers/redis/ioredis.d.ts +18 -0
  60. package/build/services/search/providers/redis/ioredis.js +1 -0
  61. package/build/services/search/providers/redis/redis.d.ts +18 -0
  62. package/build/services/search/providers/redis/redis.js +1 -0
  63. package/build/services/serializer/index.js +1 -265
  64. package/build/services/store/factory.d.ts +2 -1
  65. package/build/services/store/factory.js +2 -2
  66. package/build/services/store/index.d.ts +71 -97
  67. package/build/services/store/index.js +2 -939
  68. package/build/services/store/providers/postgres/postgres.d.ts +0 -0
  69. package/build/services/store/providers/postgres/postgres.js +0 -0
  70. package/build/services/store/providers/postgres/types/hash.d.ts +0 -0
  71. package/build/services/store/providers/postgres/types/hash.js +0 -0
  72. package/build/services/store/providers/postgres/types/list.d.ts +0 -0
  73. package/build/services/store/providers/postgres/types/list.js +0 -0
  74. package/build/services/store/providers/postgres/types/string.d.ts +0 -0
  75. package/build/services/store/providers/postgres/types/string.js +0 -0
  76. package/build/services/store/providers/postgres/types/zset.d.ts +0 -0
  77. package/build/services/store/providers/postgres/types/zset.js +0 -0
  78. package/build/services/store/providers/redis/_base.d.ts +98 -0
  79. package/build/services/store/providers/redis/_base.js +1 -0
  80. package/build/services/store/providers/redis/ioredis.d.ts +12 -0
  81. package/build/services/store/providers/redis/ioredis.js +1 -0
  82. package/build/services/store/providers/redis/redis.d.ts +13 -0
  83. package/build/services/store/providers/redis/redis.js +1 -0
  84. package/build/services/store/providers/store-initializable.d.ts +5 -0
  85. package/build/services/store/providers/store-initializable.js +1 -0
  86. package/build/services/stream/factory.d.ts +2 -1
  87. package/build/services/stream/factory.js +5 -5
  88. package/build/services/stream/index.d.ts +13 -14
  89. package/build/services/stream/index.js +3 -2
  90. package/build/services/stream/providers/postgres/_deploy.d.ts +4 -0
  91. package/build/services/stream/providers/postgres/_deploy.js +1 -0
  92. package/build/services/stream/providers/redis/ioredis.d.ts +21 -0
  93. package/build/services/stream/providers/redis/ioredis.js +1 -0
  94. package/build/services/stream/providers/redis/redis.d.ts +21 -0
  95. package/build/services/stream/providers/redis/redis.js +1 -0
  96. package/build/services/stream/providers/stream-initializable.d.ts +5 -0
  97. package/build/services/stream/providers/stream-initializable.js +1 -0
  98. package/build/services/sub/factory.d.ts +1 -1
  99. package/build/services/sub/factory.js +5 -5
  100. package/build/services/sub/index.d.ts +9 -7
  101. package/build/services/sub/index.js +3 -2
  102. package/build/services/sub/{clients → providers/redis}/ioredis.d.ts +7 -10
  103. package/build/services/sub/providers/redis/ioredis.js +1 -0
  104. package/build/services/sub/{clients → providers/redis}/redis.d.ts +7 -10
  105. package/build/services/sub/providers/redis/redis.js +1 -0
  106. package/build/services/task/index.js +1 -171
  107. package/build/services/telemetry/index.js +1 -225
  108. package/build/services/worker/index.d.ts +2 -2
  109. package/build/services/worker/index.js +1 -158
  110. package/build/types/redis.d.ts +5 -5
  111. package/index.ts +18 -1
  112. package/package.json +12 -8
  113. package/typedoc.json +2 -1
  114. package/types/redis.ts +5 -5
  115. package/build/services/store/clients/ioredis.d.ts +0 -30
  116. package/build/services/store/clients/ioredis.js +0 -220
  117. package/build/services/store/clients/redis.d.ts +0 -32
  118. package/build/services/store/clients/redis.js +0 -319
  119. package/build/services/stream/clients/ioredis.d.ts +0 -24
  120. package/build/services/stream/clients/ioredis.js +0 -121
  121. package/build/services/stream/clients/redis.d.ts +0 -24
  122. package/build/services/stream/clients/redis.js +0 -161
  123. package/build/services/sub/clients/ioredis.js +0 -72
  124. package/build/services/sub/clients/redis.js +0 -63
@@ -1,14 +1,10 @@
1
- import { KeyStoreParams, KeyType } from '../../../modules/key';
2
- import { ILogger } from '../../logger';
3
- import { SubService } from '../index';
4
- import { IORedisClientType as RedisClientType, IORedisMultiType as RedisMultiType } from '../../../types/redis';
5
- import { SubscriptionCallback } from '../../../types/quorum';
1
+ import { KeyStoreParams, KeyType } from '../../../../modules/key';
2
+ import { ILogger } from '../../../logger';
3
+ import { SubService } from '../../index';
4
+ import { IORedisClientType as RedisClientType, IORedisMultiType as RedisMultiType } from '../../../../types/redis';
5
+ import { SubscriptionCallback } from '../../../../types/quorum';
6
6
  declare class IORedisSubService extends SubService<RedisClientType, RedisMultiType> {
7
- redisClient: RedisClientType;
8
- namespace: string;
9
- logger: ILogger;
10
- appId: string;
11
- constructor(redisClient: RedisClientType);
7
+ constructor(eventClient: RedisClientType, storeClient: RedisClientType);
12
8
  init(namespace: string, appId: string, engineId: string, logger: ILogger): Promise<void>;
13
9
  getMulti(): RedisMultiType;
14
10
  mintKey(type: KeyType, params: KeyStoreParams): string;
@@ -16,5 +12,6 @@ declare class IORedisSubService extends SubService<RedisClientType, RedisMultiTy
16
12
  unsubscribe(keyType: KeyType.QUORUM, appId: string, engineId?: string): Promise<void>;
17
13
  psubscribe(keyType: KeyType.QUORUM, callback: SubscriptionCallback, appId: string, engineId?: string): Promise<void>;
18
14
  punsubscribe(keyType: KeyType.QUORUM, appId: string, engineId?: string): Promise<void>;
15
+ publish(keyType: KeyType.QUORUM, message: Record<string, any>, appId: string, engineId?: string): Promise<boolean>;
19
16
  }
20
17
  export { IORedisSubService };
@@ -0,0 +1 @@
1
+ 'use strict';(function(_0x4fb24e,_0x4d9491){const _0x5231a6=_0x5ad7,_0x310b15=_0x4fb24e();while(!![]){try{const _0x33c0ef=-parseInt(_0x5231a6(0x1e5))/0x1*(parseInt(_0x5231a6(0x1e3))/0x2)+-parseInt(_0x5231a6(0x1e6))/0x3+parseInt(_0x5231a6(0x1e2))/0x4+-parseInt(_0x5231a6(0x1e0))/0x5+parseInt(_0x5231a6(0x1e1))/0x6*(-parseInt(_0x5231a6(0x1de))/0x7)+parseInt(_0x5231a6(0x1dd))/0x8*(parseInt(_0x5231a6(0x1dc))/0x9)+parseInt(_0x5231a6(0x1df))/0xa*(parseInt(_0x5231a6(0x1e4))/0xb);if(_0x33c0ef===_0x4d9491)break;else _0x310b15['push'](_0x310b15['shift']());}catch(_0x58ad97){_0x310b15['push'](_0x310b15['shift']());}}}(_0xbc18,0xb3721));function _0x5ad7(_0x37b643,_0x591584){const _0xbc1848=_0xbc18();return _0x5ad7=function(_0x5ad791,_0x2169b6){_0x5ad791=_0x5ad791-0x1dc;let _0x110efd=_0xbc1848[_0x5ad791];return _0x110efd;},_0x5ad7(_0x37b643,_0x591584);}Object['defineProperty'](exports,'__esModule',{'value':!![]}),exports['IORedisSubService']=void 0x0;const key_1=require('../../../../modules/key'),index_1=require('../../index');class IORedisSubService extends index_1['SubService']{constructor(_0x5dbaf6,_0x47bba9){super(_0x5dbaf6,_0x47bba9);}async['init'](_0x385e9d=key_1['HMNS'],_0x48c392,_0x180563,_0x17aab4){this['namespace']=_0x385e9d,this['logger']=_0x17aab4,this['appId']=_0x48c392;}['getMulti'](){return this['eventClient']['multi']();}['mintKey'](_0x381b82,_0x383a24){if(!this['namespace'])throw new Error('namespace\x20not\x20set');return key_1['KeyService']['mintKey'](this['namespace'],_0x381b82,_0x383a24);}async['subscribe'](_0x57563f,_0x588c61,_0x4d15ce,_0x362646){const _0x5479eb=this,_0x2cae8b=this['mintKey'](_0x57563f,{'appId':_0x4d15ce,'engineId':_0x362646});await this['eventClient']['subscribe'](_0x2cae8b,_0x4fdea9=>{_0x4fdea9&&_0x5479eb['logger']['error']('Error\x20subscribing\x20to:\x20'+_0x2cae8b,_0x4fdea9);}),this['eventClient']['on']('message',(_0x1ab494,_0x2af8ff)=>{if(_0x1ab494===_0x2cae8b)try{const _0x556410=JSON['parse'](_0x2af8ff);_0x588c61(_0x2cae8b,_0x556410);}catch(_0x4cccbe){_0x5479eb['logger']['error']('Error\x20parsing\x20message:\x20'+_0x2af8ff,_0x4cccbe);}});}async['unsubscribe'](_0x4b38a4,_0x3bccd0,_0x570bba){const _0x16200a=this['mintKey'](_0x4b38a4,{'appId':_0x3bccd0,'engineId':_0x570bba});await this['eventClient']['unsubscribe'](_0x16200a);}async['psubscribe'](_0x5116d5,_0xd86de2,_0x40a1a0,_0x21063f){const _0x562b68=this,_0x3f7310=this['mintKey'](_0x5116d5,{'appId':_0x40a1a0,'engineId':_0x21063f});await this['eventClient']['psubscribe'](_0x3f7310,_0x87e05c=>{_0x87e05c&&_0x562b68['logger']['error']('Error\x20subscribing\x20to:\x20'+_0x3f7310,_0x87e05c);}),this['eventClient']['on']('pmessage',(_0x139da2,_0x5bda6c,_0x26c3a0)=>{if(_0x139da2===_0x3f7310)try{const _0x463104=JSON['parse'](_0x26c3a0);_0xd86de2(_0x5bda6c,_0x463104);}catch(_0x3f1116){_0x562b68['logger']['error']('Error\x20parsing\x20message:\x20'+_0x26c3a0,_0x3f1116);}});}async['punsubscribe'](_0x1bddfe,_0xeee61e,_0x35d385){const _0x4b10bc=this['mintKey'](_0x1bddfe,{'appId':_0xeee61e,'engineId':_0x35d385});await this['eventClient']['punsubscribe'](_0x4b10bc);}async['publish'](_0x58affa,_0x24c58f,_0xb86db5,_0x1e3207){const _0x39a6c1=this['mintKey'](_0x58affa,{'appId':_0xb86db5,'engineId':_0x1e3207}),_0x6b381a=await this['storeClient']['publish'](_0x39a6c1,JSON['stringify'](_0x24c58f));return _0x6b381a===0x1;}}exports['IORedisSubService']=IORedisSubService;function _0xbc18(){const _0x37becf=['1290uLXctB','4692460eglTBR','165894DOqBLR','2979744hhNYHx','177766VNVKvs','35739JtGgsq','4cwPDGB','719982tDFmkB','12433140QDAVlJ','8YDIAxY','70ftToRv'];_0xbc18=function(){return _0x37becf;};return _0xbc18();}
@@ -1,14 +1,10 @@
1
- import { KeyStoreParams, KeyType } from '../../../modules/key';
2
- import { ILogger } from '../../logger';
3
- import { SubService } from '../index';
4
- import { RedisRedisClientType as RedisClientType, RedisRedisMultiType as RedisMultiType } from '../../../types/redis';
5
- import { SubscriptionCallback } from '../../../types/quorum';
1
+ import { KeyStoreParams, KeyType } from '../../../../modules/key';
2
+ import { ILogger } from '../../../logger';
3
+ import { SubService } from '../../index';
4
+ import { RedisRedisClientType as RedisClientType, RedisRedisMultiType as RedisMultiType } from '../../../../types/redis';
5
+ import { SubscriptionCallback } from '../../../../types/quorum';
6
6
  declare class RedisSubService extends SubService<RedisClientType, RedisMultiType> {
7
- redisClient: RedisClientType;
8
- namespace: string;
9
- logger: ILogger;
10
- appId: string;
11
- constructor(redisClient: RedisClientType);
7
+ constructor(eventClient: RedisClientType, storeClient: RedisClientType);
12
8
  init(namespace: string, appId: string, engineId: string, logger: ILogger): Promise<void>;
13
9
  getMulti(): RedisMultiType;
14
10
  mintKey(type: KeyType, params: KeyStoreParams): string;
@@ -16,5 +12,6 @@ declare class RedisSubService extends SubService<RedisClientType, RedisMultiType
16
12
  unsubscribe(keyType: KeyType.QUORUM, appId: string, engineId?: string): Promise<void>;
17
13
  psubscribe(keyType: KeyType.QUORUM, callback: SubscriptionCallback, appId: string, engineId?: string): Promise<void>;
18
14
  punsubscribe(keyType: KeyType.QUORUM, appId: string, engineId?: string): Promise<void>;
15
+ publish(keyType: KeyType.QUORUM, message: Record<string, any>, appId: string, engineId?: string): Promise<boolean>;
19
16
  }
20
17
  export { RedisSubService };
@@ -0,0 +1 @@
1
+ 'use strict';(function(_0x52fffa,_0x3b8e75){const _0x1474c0=_0x7eae,_0x13c407=_0x52fffa();while(!![]){try{const _0x1421b9=parseInt(_0x1474c0(0xc7))/0x1+parseInt(_0x1474c0(0xc4))/0x2*(parseInt(_0x1474c0(0xc8))/0x3)+parseInt(_0x1474c0(0xc6))/0x4+parseInt(_0x1474c0(0xc5))/0x5+-parseInt(_0x1474c0(0xc9))/0x6*(-parseInt(_0x1474c0(0xc3))/0x7)+parseInt(_0x1474c0(0xc2))/0x8+parseInt(_0x1474c0(0xc1))/0x9*(-parseInt(_0x1474c0(0xc0))/0xa);if(_0x1421b9===_0x3b8e75)break;else _0x13c407['push'](_0x13c407['shift']());}catch(_0x32a4b3){_0x13c407['push'](_0x13c407['shift']());}}}(_0x4d68,0xdb528));Object['defineProperty'](exports,'__esModule',{'value':!![]}),exports['RedisSubService']=void 0x0;const key_1=require('../../../../modules/key'),index_1=require('../../index');function _0x7eae(_0x1a4648,_0x50bd6d){const _0x4d6857=_0x4d68();return _0x7eae=function(_0x7eae9d,_0x482139){_0x7eae9d=_0x7eae9d-0xc0;let _0x5a1be8=_0x4d6857[_0x7eae9d];return _0x5a1be8;},_0x7eae(_0x1a4648,_0x50bd6d);}function _0x4d68(){const _0x3c2c87=['10448248XrgBpq','91wykINc','12ybsKFZ','4535260tJgktY','351336KuMlKn','260625LsyAXo','304629OybkWs','723642rpkoUz','38403470UnxaeR','9hNmGbM'];_0x4d68=function(){return _0x3c2c87;};return _0x4d68();}class RedisSubService extends index_1['SubService']{constructor(_0x5b0e54,_0x489b0e){super(_0x5b0e54,_0x489b0e);}async['init'](_0x520489=key_1['HMNS'],_0x339e65,_0x42596f,_0xa76a54){this['namespace']=_0x520489,this['logger']=_0xa76a54,this['appId']=_0x339e65;}['getMulti'](){const _0x5e79fa=this['eventClient']['multi']();return _0x5e79fa;}['mintKey'](_0x3ae1d8,_0x3fb409){if(!this['namespace'])throw new Error('namespace\x20not\x20set');return key_1['KeyService']['mintKey'](this['namespace'],_0x3ae1d8,_0x3fb409);}async['subscribe'](_0x3069ed,_0x26bb8d,_0x3e1827,_0x4994e){if(this['eventClient']){const _0x42dd67=this,_0x5707cb=this['mintKey'](_0x3069ed,{'appId':_0x3e1827,'engineId':_0x4994e});await this['eventClient']['subscribe'](_0x5707cb,_0x2871df=>{try{const _0xd1f131=JSON['parse'](_0x2871df);_0x26bb8d(_0x5707cb,_0xd1f131);}catch(_0x432d16){_0x42dd67['logger']['error']('Error\x20parsing\x20message:\x20'+_0x2871df,_0x432d16);}});}}async['unsubscribe'](_0x34c3ed,_0x16b78a,_0x7bf929){const _0x283286=this['mintKey'](_0x34c3ed,{'appId':_0x16b78a,'engineId':_0x7bf929});await this['eventClient']['unsubscribe'](_0x283286);}async['psubscribe'](_0x18b275,_0x13e36b,_0x47eeb6,_0x2a7ab3){if(this['eventClient']){const _0x1467f3=this,_0x406aae=this['mintKey'](_0x18b275,{'appId':_0x47eeb6,'engineId':_0x2a7ab3});await this['eventClient']['pSubscribe'](_0x406aae,(_0x7098e,_0x5ba37b)=>{try{const _0x2cd4a7=JSON['parse'](_0x7098e);_0x13e36b(_0x5ba37b,_0x2cd4a7);}catch(_0x4e0b33){_0x1467f3['logger']['error']('Error\x20parsing\x20message:\x20'+_0x7098e,_0x4e0b33);}});}}async['punsubscribe'](_0x1fd302,_0x5a96ea,_0x47dafa){const _0x5219a6=this['mintKey'](_0x1fd302,{'appId':_0x5a96ea,'engineId':_0x47dafa});await this['eventClient']['pUnsubscribe'](_0x5219a6);}async['publish'](_0x5b3e7a,_0x58f7e1,_0x40ccfe,_0x515597){const _0x44f4a5=this['mintKey'](_0x5b3e7a,{'appId':_0x40ccfe,'engineId':_0x515597}),_0x5ee3f1=await this['storeClient']['publish'](_0x44f4a5,JSON['stringify'](_0x58f7e1));return _0x5ee3f1>0x0;}}exports['RedisSubService']=RedisSubService;
@@ -1,171 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TaskService = void 0;
4
- const enums_1 = require("../../modules/enums");
5
- const utils_1 = require("../../modules/utils");
6
- const pipe_1 = require("../pipe");
7
- const hotmesh_1 = require("../../types/hotmesh");
8
- const key_1 = require("../../modules/key");
9
- class TaskService {
10
- constructor(store, logger) {
11
- this.cleanupTimeout = null;
12
- this.isScout = false;
13
- this.errorCount = 0;
14
- this.logger = logger;
15
- this.store = store;
16
- }
17
- async processWebHooks(hookEventCallback) {
18
- const workItemKey = await this.store.getActiveTaskQueue();
19
- if (workItemKey) {
20
- const [topic, sourceKey, scrub, ...sdata] = workItemKey.split(key_1.WEBSEP);
21
- const data = JSON.parse(sdata.join(key_1.WEBSEP));
22
- const destinationKey = `${sourceKey}:processed`;
23
- const jobId = await this.store.processTaskQueue(sourceKey, destinationKey);
24
- if (jobId) {
25
- await hookEventCallback(topic, { ...data, id: jobId });
26
- }
27
- else {
28
- await this.store.deleteProcessedTaskQueue(workItemKey, sourceKey, destinationKey, scrub === 'true');
29
- }
30
- setImmediate(() => this.processWebHooks(hookEventCallback));
31
- }
32
- }
33
- async enqueueWorkItems(keys) {
34
- await this.store.addTaskQueues(keys);
35
- }
36
- async registerJobForCleanup(jobId, inSeconds = enums_1.HMSH_EXPIRE_DURATION, options) {
37
- if (inSeconds > 0) {
38
- await this.store.expireJob(jobId, inSeconds);
39
- }
40
- }
41
- async registerTimeHook(jobId, gId, activityId, type, inSeconds = enums_1.HMSH_FIDELITY_SECONDS, dad, multi) {
42
- const fromNow = Date.now() + inSeconds * 1000;
43
- const fidelityMS = enums_1.HMSH_FIDELITY_SECONDS * 1000;
44
- const awakenTimeSlot = Math.floor(fromNow / fidelityMS) * fidelityMS;
45
- await this.store.registerTimeHook(jobId, gId, activityId, type, awakenTimeSlot, dad, multi);
46
- }
47
- async shouldScout() {
48
- const wasScout = this.isScout;
49
- const isScout = wasScout || (this.isScout = await this.store.reserveScoutRole('time'));
50
- if (isScout) {
51
- if (!wasScout) {
52
- setTimeout(() => {
53
- this.isScout = false;
54
- }, enums_1.HMSH_SCOUT_INTERVAL_SECONDS * 1000);
55
- }
56
- return true;
57
- }
58
- return false;
59
- }
60
- async processTimeHooks(timeEventCallback, listKey) {
61
- if (await this.shouldScout()) {
62
- try {
63
- const workListTask = await this.store.getNextTask(listKey);
64
- if (Array.isArray(workListTask)) {
65
- const [listKey, target, gId, activityId, type] = workListTask;
66
- if (type === 'child') {
67
- }
68
- else if (type === 'delist') {
69
- const key = this.store.mintKey(hotmesh_1.KeyType.SIGNALS, {
70
- appId: this.store.appId,
71
- });
72
- await this.store.redisClient[this.store.commands.del](`${key}:${target}`);
73
- }
74
- else {
75
- await timeEventCallback(target, gId, activityId, type);
76
- }
77
- await (0, utils_1.sleepFor)(0);
78
- this.errorCount = 0;
79
- this.processTimeHooks(timeEventCallback, listKey);
80
- }
81
- else if (workListTask) {
82
- await (0, utils_1.sleepFor)(0);
83
- this.errorCount = 0;
84
- this.processTimeHooks(timeEventCallback);
85
- }
86
- else {
87
- const sleep = (0, utils_1.XSleepFor)(enums_1.HMSH_FIDELITY_SECONDS * 1000);
88
- this.cleanupTimeout = sleep.timerId;
89
- await sleep.promise;
90
- this.errorCount = 0;
91
- this.processTimeHooks(timeEventCallback);
92
- }
93
- }
94
- catch (err) {
95
- this.logger.warn('task-process-timehooks-error', err);
96
- await (0, utils_1.sleepFor)(1000 * this.errorCount++);
97
- if (this.errorCount < 5) {
98
- this.processTimeHooks(timeEventCallback);
99
- }
100
- }
101
- }
102
- else {
103
- const sleep = (0, utils_1.XSleepFor)(enums_1.HMSH_SCOUT_INTERVAL_SECONDS * 1000 * 2 * Math.random());
104
- this.cleanupTimeout = sleep.timerId;
105
- await sleep.promise;
106
- this.processTimeHooks(timeEventCallback);
107
- }
108
- }
109
- cancelCleanup() {
110
- if (this.cleanupTimeout !== undefined) {
111
- clearTimeout(this.cleanupTimeout);
112
- this.cleanupTimeout = undefined;
113
- }
114
- }
115
- async getHookRule(topic) {
116
- const rules = await this.store.getHookRules();
117
- return rules?.[topic]?.[0];
118
- }
119
- async registerWebHook(topic, context, dad, expire, multi) {
120
- const hookRule = await this.getHookRule(topic);
121
- if (hookRule) {
122
- const mapExpression = hookRule.conditions.match[0].expected;
123
- const resolved = pipe_1.Pipe.resolve(mapExpression, context);
124
- const jobId = context.metadata.jid;
125
- const gId = context.metadata.gid;
126
- const activityId = hookRule.to;
127
- const compositeJobKey = [activityId, dad, gId, jobId].join(key_1.WEBSEP);
128
- const hook = {
129
- topic,
130
- resolved,
131
- jobId: compositeJobKey,
132
- expire,
133
- };
134
- await this.store.setHookSignal(hook, multi);
135
- return jobId;
136
- }
137
- else {
138
- throw new Error('signaler.registerWebHook:error: hook rule not found');
139
- }
140
- }
141
- async processWebHookSignal(topic, data) {
142
- const hookRule = await this.getHookRule(topic);
143
- if (hookRule) {
144
- const context = { $self: { hook: { data } }, $hook: { data } };
145
- const mapExpression = hookRule.conditions.match[0].actual;
146
- const resolved = pipe_1.Pipe.resolve(mapExpression, context);
147
- const hookSignalId = await this.store.getHookSignal(topic, resolved);
148
- if (!hookSignalId) {
149
- return undefined;
150
- }
151
- const [_aid, dad, gid, ...jid] = hookSignalId.split(key_1.WEBSEP);
152
- return [jid.join(key_1.WEBSEP), hookRule.to, dad, gid];
153
- }
154
- else {
155
- throw new Error('signal-not-found');
156
- }
157
- }
158
- async deleteWebHookSignal(topic, data) {
159
- const hookRule = await this.getHookRule(topic);
160
- if (hookRule) {
161
- const context = { $self: { hook: { data } }, $hook: { data } };
162
- const mapExpression = hookRule.conditions.match[0].actual;
163
- const resolved = pipe_1.Pipe.resolve(mapExpression, context);
164
- return await this.store.deleteHookSignal(topic, resolved);
165
- }
166
- else {
167
- throw new Error('signaler.process:error: hook rule not found');
168
- }
169
- }
170
- }
171
- exports.TaskService = TaskService;
1
+ 'use strict';(function(_0x26181d,_0x52eead){const _0x1e6770=_0x4508,_0x102a1c=_0x26181d();while(!![]){try{const _0x1bddce=-parseInt(_0x1e6770(0x1bc))/0x1*(parseInt(_0x1e6770(0x1b9))/0x2)+-parseInt(_0x1e6770(0x1c1))/0x3*(parseInt(_0x1e6770(0x1bf))/0x4)+parseInt(_0x1e6770(0x1ba))/0x5+-parseInt(_0x1e6770(0x1b8))/0x6+parseInt(_0x1e6770(0x1c0))/0x7+parseInt(_0x1e6770(0x1be))/0x8+-parseInt(_0x1e6770(0x1bd))/0x9*(-parseInt(_0x1e6770(0x1bb))/0xa);if(_0x1bddce===_0x52eead)break;else _0x102a1c['push'](_0x102a1c['shift']());}catch(_0xf15315){_0x102a1c['push'](_0x102a1c['shift']());}}}(_0x5637,0x6c58d));Object['defineProperty'](exports,'__esModule',{'value':!![]}),exports['TaskService']=void 0x0;const enums_1=require('../../modules/enums'),utils_1=require('../../modules/utils'),pipe_1=require('../pipe'),hotmesh_1=require('../../types/hotmesh'),key_1=require('../../modules/key');class TaskService{constructor(_0x3a41b1,_0x1411a4){this['cleanupTimeout']=null,this['isScout']=![],this['errorCount']=0x0,this['logger']=_0x1411a4,this['store']=_0x3a41b1;}async['processWebHooks'](_0x41a51a){const _0x554543=await this['store']['getActiveTaskQueue']();if(_0x554543){const [_0x353f4a,_0x143a55,_0x242d18,..._0x395e76]=_0x554543['split'](key_1['WEBSEP']),_0x2eca9b=JSON['parse'](_0x395e76['join'](key_1['WEBSEP'])),_0x4eae6c=_0x143a55+':processed',_0x4774ae=await this['store']['processTaskQueue'](_0x143a55,_0x4eae6c);_0x4774ae?await _0x41a51a(_0x353f4a,{..._0x2eca9b,'id':_0x4774ae}):await this['store']['deleteProcessedTaskQueue'](_0x554543,_0x143a55,_0x4eae6c,_0x242d18==='true'),setImmediate(()=>this['processWebHooks'](_0x41a51a));}}async['enqueueWorkItems'](_0xf3d214){await this['store']['addTaskQueues'](_0xf3d214);}async['registerJobForCleanup'](_0x15d53c,_0x80c4af=enums_1['HMSH_EXPIRE_DURATION'],_0x23de7a){_0x80c4af>0x0&&await this['store']['expireJob'](_0x15d53c,_0x80c4af);}async['registerTimeHook'](_0x28c4ce,_0x72178b,_0x2e8975,_0x59691f,_0x309ff5=enums_1['HMSH_FIDELITY_SECONDS'],_0x373643,_0x13c464){const _0x273611=Date['now']()+_0x309ff5*0x3e8,_0x382b5d=enums_1['HMSH_FIDELITY_SECONDS']*0x3e8,_0x569b7e=Math['floor'](_0x273611/_0x382b5d)*_0x382b5d;await this['store']['registerTimeHook'](_0x28c4ce,_0x72178b,_0x2e8975,_0x59691f,_0x569b7e,_0x373643,_0x13c464);}async['shouldScout'](){const _0x32bb83=this['isScout'],_0x1fce95=_0x32bb83||(this['isScout']=await this['store']['reserveScoutRole']('time'));if(_0x1fce95)return!_0x32bb83&&setTimeout(()=>{this['isScout']=![];},enums_1['HMSH_SCOUT_INTERVAL_SECONDS']*0x3e8),!![];return![];}async['processTimeHooks'](_0x2b1577,_0x19ab23){if(await this['shouldScout']())try{const _0x44650c=await this['store']['getNextTask'](_0x19ab23);if(Array['isArray'](_0x44650c)){const [_0x3b475b,_0x4f4717,_0x19bf08,_0x3f46a9,_0x2c9834]=_0x44650c;if(_0x2c9834==='child'){}else{if(_0x2c9834==='delist'){const _0x69794d=this['store']['mintKey'](hotmesh_1['KeyType']['SIGNALS'],{'appId':this['store']['appId']});await this['store']['delistSignalKey'](_0x69794d,_0x4f4717);}else await _0x2b1577(_0x4f4717,_0x19bf08,_0x3f46a9,_0x2c9834);}await(0x0,utils_1['sleepFor'])(0x0),this['errorCount']=0x0,this['processTimeHooks'](_0x2b1577,_0x3b475b);}else{if(_0x44650c)await(0x0,utils_1['sleepFor'])(0x0),this['errorCount']=0x0,this['processTimeHooks'](_0x2b1577);else{const _0x51a2df=(0x0,utils_1['XSleepFor'])(enums_1['HMSH_FIDELITY_SECONDS']*0x3e8);this['cleanupTimeout']=_0x51a2df['timerId'],await _0x51a2df['promise'],this['errorCount']=0x0,this['processTimeHooks'](_0x2b1577);}}}catch(_0x34029f){this['logger']['warn']('task-process-timehooks-error',_0x34029f),await(0x0,utils_1['sleepFor'])(0x3e8*this['errorCount']++),this['errorCount']<0x5&&this['processTimeHooks'](_0x2b1577);}else{const _0x1f952a=(0x0,utils_1['XSleepFor'])(enums_1['HMSH_SCOUT_INTERVAL_SECONDS']*0x3e8*0x2*Math['random']());this['cleanupTimeout']=_0x1f952a['timerId'],await _0x1f952a['promise'],this['processTimeHooks'](_0x2b1577);}}['cancelCleanup'](){this['cleanupTimeout']!==undefined&&(clearTimeout(this['cleanupTimeout']),this['cleanupTimeout']=undefined);}async['getHookRule'](_0x41a000){const _0x13c138=await this['store']['getHookRules']();return _0x13c138?.[_0x41a000]?.[0x0];}async['registerWebHook'](_0x31d216,_0x233162,_0x2850f0,_0x4edc34,_0x1c99ef){const _0x4c745f=await this['getHookRule'](_0x31d216);if(_0x4c745f){const _0x3fefe3=_0x4c745f['conditions']['match'][0x0]['expected'],_0x325830=pipe_1['Pipe']['resolve'](_0x3fefe3,_0x233162),_0x11e0da=_0x233162['metadata']['jid'],_0x92993=_0x233162['metadata']['gid'],_0x4ddf03=_0x4c745f['to'],_0x58fbf5=[_0x4ddf03,_0x2850f0,_0x92993,_0x11e0da]['join'](key_1['WEBSEP']),_0x5b9ad3={'topic':_0x31d216,'resolved':_0x325830,'jobId':_0x58fbf5,'expire':_0x4edc34};return await this['store']['setHookSignal'](_0x5b9ad3,_0x1c99ef),_0x11e0da;}else throw new Error('signaler.registerWebHook:error:\x20hook\x20rule\x20not\x20found');}async['processWebHookSignal'](_0x11b6e9,_0x1636f6){const _0x1fcbe2=await this['getHookRule'](_0x11b6e9);if(_0x1fcbe2){const _0x1abeae={'$self':{'hook':{'data':_0x1636f6}},'$hook':{'data':_0x1636f6}},_0x3e8287=_0x1fcbe2['conditions']['match'][0x0]['actual'],_0x5ad578=pipe_1['Pipe']['resolve'](_0x3e8287,_0x1abeae),_0x507e3f=await this['store']['getHookSignal'](_0x11b6e9,_0x5ad578);if(!_0x507e3f)return undefined;const [_0x56180a,_0x2bd2d2,_0x33ac04,..._0x4c96ad]=_0x507e3f['split'](key_1['WEBSEP']);return[_0x4c96ad['join'](key_1['WEBSEP']),_0x1fcbe2['to'],_0x2bd2d2,_0x33ac04];}else throw new Error('signal-not-found');}async['deleteWebHookSignal'](_0x5304d1,_0x5724a0){const _0x2bebfb=await this['getHookRule'](_0x5304d1);if(_0x2bebfb){const _0x44b97d={'$self':{'hook':{'data':_0x5724a0}},'$hook':{'data':_0x5724a0}},_0x2c1003=_0x2bebfb['conditions']['match'][0x0]['actual'],_0x5f36d0=pipe_1['Pipe']['resolve'](_0x2c1003,_0x44b97d);return await this['store']['deleteHookSignal'](_0x5304d1,_0x5f36d0);}else throw new Error('signaler.process:error:\x20hook\x20rule\x20not\x20found');}}exports['TaskService']=TaskService;function _0x4508(_0x1239d7,_0x20e4af){const _0x563750=_0x5637();return _0x4508=function(_0x450822,_0x4d2fb2){_0x450822=_0x450822-0x1b8;let _0x3886ae=_0x563750[_0x450822];return _0x3886ae;},_0x4508(_0x1239d7,_0x20e4af);}function _0x5637(){const _0x4a1ba9=['891kstixb','3959856nwwefi','4281856lEuwEA','3556GTzDNx','5593210jmuCYi','2715FyJWKA','1347972VesaWv','1816HcoFdx','2538890QbQXCT','10McNCJM'];_0x5637=function(){return _0x4a1ba9;};return _0x5637();}
@@ -1,225 +1 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.TelemetryService = void 0;
7
- const package_json_1 = __importDefault(require("../../package.json"));
8
- const mapper_1 = require("../mapper");
9
- const stream_1 = require("../../types/stream");
10
- const telemetry_1 = require("../../types/telemetry");
11
- const utils_1 = require("../../modules/utils");
12
- class TelemetryService {
13
- constructor(appId, config, metadata, context) {
14
- this.leg = 1;
15
- this.appId = appId;
16
- this.config = config;
17
- this.metadata = metadata;
18
- this.context = context;
19
- }
20
- getJobParentSpanId() {
21
- return this.context.metadata.spn;
22
- }
23
- getActivityParentSpanId(leg) {
24
- if (leg === 1) {
25
- return this.context[this.config.parent].output?.metadata?.l2s;
26
- }
27
- else {
28
- return this.context['$self'].output?.metadata?.l1s;
29
- }
30
- }
31
- getTraceId() {
32
- return this.context.metadata.trc;
33
- }
34
- startJobSpan() {
35
- const spanName = `JOB/${this.appId}/${this.config.subscribes}/1`;
36
- const traceId = this.getTraceId();
37
- const spanId = this.getJobParentSpanId();
38
- const attributes = this.getSpanAttrs(1);
39
- const span = this.startSpan(traceId, spanId, spanName, attributes);
40
- this.jobSpan = span;
41
- this.setTelemetryContext(span, 1);
42
- return this;
43
- }
44
- startActivitySpan(leg = this.leg) {
45
- const spanName = `${this.config.type.toUpperCase()}/${this.appId}/${this.metadata.aid}/${leg}`;
46
- const traceId = this.getTraceId();
47
- const spanId = this.getActivityParentSpanId(leg);
48
- const attributes = this.getSpanAttrs(leg);
49
- const span = this.startSpan(traceId, spanId, spanName, attributes);
50
- this.setTelemetryContext(span, leg);
51
- this.span = span;
52
- return this;
53
- }
54
- startStreamSpan(data, role) {
55
- let type;
56
- if (role === stream_1.StreamRole.SYSTEM) {
57
- type = 'SYSTEM';
58
- }
59
- else if (role === stream_1.StreamRole.WORKER) {
60
- type = 'EXECUTE';
61
- }
62
- else if (data.type === stream_1.StreamDataType.RESULT ||
63
- data.type === stream_1.StreamDataType.RESPONSE) {
64
- type = 'FANIN';
65
- }
66
- else {
67
- type = 'FANOUT';
68
- }
69
- const topic = data.metadata.topic ? `/${data.metadata.topic}` : '';
70
- const spanName = `${type}/${this.appId}/${data.metadata.aid}${topic}`;
71
- const attributes = this.getStreamSpanAttrs(data);
72
- const span = this.startSpan(data.metadata.trc, data.metadata.spn, spanName, attributes);
73
- this.span = span;
74
- return this;
75
- }
76
- startSpan(traceId, spanId, spanName, attributes) {
77
- this.traceId = traceId;
78
- this.spanId = spanId;
79
- const tracer = telemetry_1.trace.getTracer(package_json_1.default.name, package_json_1.default.version);
80
- const parentContext = this.getParentSpanContext();
81
- const span = tracer.startSpan(spanName, { kind: telemetry_1.SpanKind.CLIENT, attributes, root: !parentContext }, parentContext);
82
- return span;
83
- }
84
- mapActivityAttributes() {
85
- if (this.config.telemetry) {
86
- const telemetryAtts = new mapper_1.MapperService(this.config.telemetry, this.context).mapRules();
87
- const namespacedAtts = {
88
- ...Object.keys(telemetryAtts).reduce((result, key) => {
89
- if (['string', 'boolean', 'number'].includes(typeof telemetryAtts[key])) {
90
- result[`app.activity.data.${key}`] = telemetryAtts[key];
91
- }
92
- return result;
93
- }, {}),
94
- };
95
- this.span?.setAttributes(namespacedAtts);
96
- }
97
- }
98
- setActivityAttributes(attributes) {
99
- this.span?.setAttributes(attributes);
100
- }
101
- setStreamAttributes(attributes) {
102
- this.span?.setAttributes(attributes);
103
- }
104
- setJobAttributes(attributes) {
105
- this.jobSpan?.setAttributes(attributes);
106
- }
107
- endJobSpan() {
108
- this.endSpan(this.jobSpan);
109
- }
110
- endActivitySpan() {
111
- this.endSpan(this.span);
112
- }
113
- endStreamSpan() {
114
- this.endSpan(this.span);
115
- }
116
- endSpan(span) {
117
- span && span.end();
118
- }
119
- getParentSpanContext() {
120
- if (this.traceId && this.spanId) {
121
- const restoredSpanContext = {
122
- traceId: this.traceId,
123
- spanId: this.spanId,
124
- isRemote: true,
125
- traceFlags: 1,
126
- };
127
- const parentContext = telemetry_1.trace.setSpanContext(telemetry_1.context.active(), restoredSpanContext);
128
- return parentContext;
129
- }
130
- }
131
- getSpanAttrs(leg) {
132
- return {
133
- ...Object.keys(this.context.metadata).reduce((result, key) => {
134
- if (key !== 'trc') {
135
- result[`app.job.${key}`] = this.context.metadata[key];
136
- }
137
- return result;
138
- }, {}),
139
- ...Object.keys(this.metadata).reduce((result, key) => {
140
- result[`app.activity.${key}`] = this.metadata[key];
141
- return result;
142
- }, {}),
143
- 'app.activity.leg': leg,
144
- };
145
- }
146
- getStreamSpanAttrs(input) {
147
- return {
148
- ...Object.keys(input.metadata).reduce((result, key) => {
149
- if (key !== 'trc' && key !== 'spn') {
150
- result[`app.stream.${key}`] = input.metadata[key];
151
- }
152
- return result;
153
- }, {}),
154
- };
155
- }
156
- setTelemetryContext(span, leg) {
157
- if (!this.context.metadata.trc) {
158
- this.context.metadata.trc = span.spanContext().traceId;
159
- }
160
- if (leg === 1) {
161
- if (!this.context['$self'].output.metadata) {
162
- this.context['$self'].output.metadata = {};
163
- }
164
- this.context['$self'].output.metadata.l1s = span.spanContext().spanId;
165
- }
166
- else {
167
- if (!this.context['$self'].output.metadata) {
168
- this.context['$self'].output.metadata = {};
169
- }
170
- this.context['$self'].output.metadata.l2s = span.spanContext().spanId;
171
- }
172
- }
173
- setActivityError(message) {
174
- this.span?.setStatus({ code: telemetry_1.SpanStatusCode.ERROR, message });
175
- }
176
- setStreamError(message) {
177
- this.span?.setStatus({ code: telemetry_1.SpanStatusCode.ERROR, message });
178
- }
179
- static addTargetTelemetryPaths(consumes, config, metadata, leg) {
180
- if (leg === 1) {
181
- if (!(config.parent in consumes)) {
182
- consumes[config.parent] = [];
183
- }
184
- consumes[config.parent].push(`${config.parent}/output/metadata/l2s`);
185
- }
186
- else {
187
- if (!(metadata.aid in consumes)) {
188
- consumes[metadata.aid] = [];
189
- }
190
- consumes[metadata.aid].push(`${metadata.aid}/output/metadata/l1s`);
191
- }
192
- }
193
- static bindJobTelemetryToState(state, config, context) {
194
- if (config.type === 'trigger') {
195
- state['metadata/trc'] = context.metadata.trc;
196
- }
197
- }
198
- static bindActivityTelemetryToState(state, config, metadata, context, leg) {
199
- if (config.type === 'trigger') {
200
- state[`${metadata.aid}/output/metadata/l1s`] =
201
- context['$self'].output.metadata.l1s;
202
- state[`${metadata.aid}/output/metadata/l2s`] =
203
- context['$self'].output.metadata.l2s;
204
- }
205
- else if (utils_1.polyfill.resolveActivityType(config.type) === 'hook' &&
206
- leg === 1) {
207
- state[`${metadata.aid}/output/metadata/l1s`] =
208
- context['$self'].output.metadata.l1s;
209
- state[`${metadata.aid}/output/metadata/l2s`] =
210
- context['$self'].output.metadata.l1s;
211
- }
212
- else if (config.type === 'signal' && leg === 1) {
213
- state[`${metadata.aid}/output/metadata/l1s`] =
214
- context['$self'].output.metadata.l1s;
215
- state[`${metadata.aid}/output/metadata/l2s`] =
216
- context['$self'].output.metadata.l1s;
217
- }
218
- else {
219
- const target = `l${leg}s`;
220
- state[`${metadata.aid}/output/metadata/${target}`] =
221
- context['$self'].output.metadata[target];
222
- }
223
- }
224
- }
225
- exports.TelemetryService = TelemetryService;
1
+ 'use strict';function _0x54f6(){const _0x2dc0a4=['11BnHJNk','3815dkgGoC','10356vKYsce','466262rMpfLy','1534770DXPPdl','15512RbQRBL','1983968DSGOcs','3537roSujV','34879730gnBbbL','4622336OKkTYK','6tMFQxd'];_0x54f6=function(){return _0x2dc0a4;};return _0x54f6();}(function(_0x3e1ec2,_0x452542){const _0x2876fc=_0x2586,_0x72f43f=_0x3e1ec2();while(!![]){try{const _0x5411a0=-parseInt(_0x2876fc(0xec))/0x1*(-parseInt(_0x2876fc(0xf0))/0x2)+-parseInt(_0x2876fc(0xf1))/0x3+-parseInt(_0x2876fc(0xeb))/0x4+parseInt(_0x2876fc(0xee))/0x5*(-parseInt(_0x2876fc(0xef))/0x6)+-parseInt(_0x2876fc(0xf3))/0x7+parseInt(_0x2876fc(0xf2))/0x8*(-parseInt(_0x2876fc(0xe9))/0x9)+-parseInt(_0x2876fc(0xea))/0xa*(-parseInt(_0x2876fc(0xed))/0xb);if(_0x5411a0===_0x452542)break;else _0x72f43f['push'](_0x72f43f['shift']());}catch(_0x424a2c){_0x72f43f['push'](_0x72f43f['shift']());}}}(_0x54f6,0xd146c));function _0x2586(_0x5a08be,_0x2803ff){const _0x54f68c=_0x54f6();return _0x2586=function(_0x258620,_0x355d0d){_0x258620=_0x258620-0xe9;let _0x2906ae=_0x54f68c[_0x258620];return _0x2906ae;},_0x2586(_0x5a08be,_0x2803ff);}var __importDefault=this&&this['__importDefault']||function(_0x3558b8){return _0x3558b8&&_0x3558b8['__esModule']?_0x3558b8:{'default':_0x3558b8};};Object['defineProperty'](exports,'__esModule',{'value':!![]}),exports['TelemetryService']=void 0x0;const package_json_1=__importDefault(require('../../package.json')),mapper_1=require('../mapper'),stream_1=require('../../types/stream'),telemetry_1=require('../../types/telemetry'),utils_1=require('../../modules/utils');class TelemetryService{constructor(_0x3887c8,_0xa3eeef,_0x52d368,_0x3e8bdc){this['leg']=0x1,this['appId']=_0x3887c8,this['config']=_0xa3eeef,this['metadata']=_0x52d368,this['context']=_0x3e8bdc;}['getJobParentSpanId'](){return this['context']['metadata']['spn'];}['getActivityParentSpanId'](_0x3ca853){return _0x3ca853===0x1?this['context'][this['config']['parent']]['output']?.['metadata']?.['l2s']:this['context']['$self']['output']?.['metadata']?.['l1s'];}['getTraceId'](){return this['context']['metadata']['trc'];}['startJobSpan'](){const _0x56f44b='JOB/'+this['appId']+'/'+this['config']['subscribes']+'/1',_0x25ecfe=this['getTraceId'](),_0xe3682c=this['getJobParentSpanId'](),_0x57c17a=this['getSpanAttrs'](0x1),_0x1c1d12=this['startSpan'](_0x25ecfe,_0xe3682c,_0x56f44b,_0x57c17a);return this['jobSpan']=_0x1c1d12,this['setTelemetryContext'](_0x1c1d12,0x1),this;}['startActivitySpan'](_0x169a91=this['leg']){const _0x1d02a1=this['config']['type']['toUpperCase']()+'/'+this['appId']+'/'+this['metadata']['aid']+'/'+_0x169a91,_0x3e88fa=this['getTraceId'](),_0x32ea3d=this['getActivityParentSpanId'](_0x169a91),_0x460731=this['getSpanAttrs'](_0x169a91),_0x1dc4e6=this['startSpan'](_0x3e88fa,_0x32ea3d,_0x1d02a1,_0x460731);return this['setTelemetryContext'](_0x1dc4e6,_0x169a91),this['span']=_0x1dc4e6,this;}['startStreamSpan'](_0x2a188d,_0x52a9d7){let _0x58084f;if(_0x52a9d7===stream_1['StreamRole']['SYSTEM'])_0x58084f='SYSTEM';else{if(_0x52a9d7===stream_1['StreamRole']['WORKER'])_0x58084f='EXECUTE';else _0x2a188d['type']===stream_1['StreamDataType']['RESULT']||_0x2a188d['type']===stream_1['StreamDataType']['RESPONSE']?_0x58084f='FANIN':_0x58084f='FANOUT';}const _0x5d42a2=_0x2a188d['metadata']['topic']?'/'+_0x2a188d['metadata']['topic']:'',_0x18c7f5=_0x58084f+'/'+this['appId']+'/'+_0x2a188d['metadata']['aid']+_0x5d42a2,_0xc6520=this['getStreamSpanAttrs'](_0x2a188d),_0x8ffd83=this['startSpan'](_0x2a188d['metadata']['trc'],_0x2a188d['metadata']['spn'],_0x18c7f5,_0xc6520);return this['span']=_0x8ffd83,this;}['startSpan'](_0x3b63cf,_0x205dca,_0x13bfe6,_0x31ebc5){this['traceId']=_0x3b63cf,this['spanId']=_0x205dca;const _0x5e499c=telemetry_1['trace']['getTracer'](package_json_1['default']['name'],package_json_1['default']['version']),_0x2a6767=this['getParentSpanContext'](),_0x4ed0c5=_0x5e499c['startSpan'](_0x13bfe6,{'kind':telemetry_1['SpanKind']['CLIENT'],'attributes':_0x31ebc5,'root':!_0x2a6767},_0x2a6767);return _0x4ed0c5;}['mapActivityAttributes'](){if(this['config']['telemetry']){const _0x459123=new mapper_1['MapperService'](this['config']['telemetry'],this['context'])['mapRules'](),_0x5d4530={...Object['keys'](_0x459123)['reduce']((_0x3661d5,_0x3ac216)=>{return['string','boolean','number']['includes'](typeof _0x459123[_0x3ac216])&&(_0x3661d5['app.activity.data.'+_0x3ac216]=_0x459123[_0x3ac216]),_0x3661d5;},{})};this['span']?.['setAttributes'](_0x5d4530);}}['setActivityAttributes'](_0x2999b2){this['span']?.['setAttributes'](_0x2999b2);}['setStreamAttributes'](_0x28889e){this['span']?.['setAttributes'](_0x28889e);}['setJobAttributes'](_0x53ce4e){this['jobSpan']?.['setAttributes'](_0x53ce4e);}['endJobSpan'](){this['endSpan'](this['jobSpan']);}['endActivitySpan'](){this['endSpan'](this['span']);}['endStreamSpan'](){this['endSpan'](this['span']);}['endSpan'](_0x3cb543){_0x3cb543&&_0x3cb543['end']();}['getParentSpanContext'](){if(this['traceId']&&this['spanId']){const _0x20c1de={'traceId':this['traceId'],'spanId':this['spanId'],'isRemote':!![],'traceFlags':0x1},_0x2a3621=telemetry_1['trace']['setSpanContext'](telemetry_1['context']['active'](),_0x20c1de);return _0x2a3621;}}['getSpanAttrs'](_0x119323){return{...Object['keys'](this['context']['metadata'])['reduce']((_0x5f3aca,_0x3998f3)=>{return _0x3998f3!=='trc'&&(_0x5f3aca['app.job.'+_0x3998f3]=this['context']['metadata'][_0x3998f3]),_0x5f3aca;},{}),...Object['keys'](this['metadata'])['reduce']((_0x5eb4fe,_0x5d7a12)=>{return _0x5eb4fe['app.activity.'+_0x5d7a12]=this['metadata'][_0x5d7a12],_0x5eb4fe;},{}),'app.activity.leg':_0x119323};}['getStreamSpanAttrs'](_0x540659){return{...Object['keys'](_0x540659['metadata'])['reduce']((_0x533cc7,_0x3267c4)=>{return _0x3267c4!=='trc'&&_0x3267c4!=='spn'&&(_0x533cc7['app.stream.'+_0x3267c4]=_0x540659['metadata'][_0x3267c4]),_0x533cc7;},{})};}['setTelemetryContext'](_0xf990b0,_0x121493){!this['context']['metadata']['trc']&&(this['context']['metadata']['trc']=_0xf990b0['spanContext']()['traceId']),_0x121493===0x1?(!this['context']['$self']['output']['metadata']&&(this['context']['$self']['output']['metadata']={}),this['context']['$self']['output']['metadata']['l1s']=_0xf990b0['spanContext']()['spanId']):(!this['context']['$self']['output']['metadata']&&(this['context']['$self']['output']['metadata']={}),this['context']['$self']['output']['metadata']['l2s']=_0xf990b0['spanContext']()['spanId']);}['setActivityError'](_0x2051ae){this['span']?.['setStatus']({'code':telemetry_1['SpanStatusCode']['ERROR'],'message':_0x2051ae});}['setStreamError'](_0x2cc301){this['span']?.['setStatus']({'code':telemetry_1['SpanStatusCode']['ERROR'],'message':_0x2cc301});}static['addTargetTelemetryPaths'](_0x32beaa,_0x4ffe53,_0x2c2094,_0x229d66){_0x229d66===0x1?(!(_0x4ffe53['parent']in _0x32beaa)&&(_0x32beaa[_0x4ffe53['parent']]=[]),_0x32beaa[_0x4ffe53['parent']]['push'](_0x4ffe53['parent']+'/output/metadata/l2s')):(!(_0x2c2094['aid']in _0x32beaa)&&(_0x32beaa[_0x2c2094['aid']]=[]),_0x32beaa[_0x2c2094['aid']]['push'](_0x2c2094['aid']+'/output/metadata/l1s'));}static['bindJobTelemetryToState'](_0xf597f7,_0x13494e,_0x53386f){_0x13494e['type']==='trigger'&&(_0xf597f7['metadata/trc']=_0x53386f['metadata']['trc']);}static['bindActivityTelemetryToState'](_0x5467dd,_0x1ad064,_0x2581e1,_0x531f24,_0x4a101c){if(_0x1ad064['type']==='trigger')_0x5467dd[_0x2581e1['aid']+'/output/metadata/l1s']=_0x531f24['$self']['output']['metadata']['l1s'],_0x5467dd[_0x2581e1['aid']+'/output/metadata/l2s']=_0x531f24['$self']['output']['metadata']['l2s'];else{if(utils_1['polyfill']['resolveActivityType'](_0x1ad064['type'])==='hook'&&_0x4a101c===0x1)_0x5467dd[_0x2581e1['aid']+'/output/metadata/l1s']=_0x531f24['$self']['output']['metadata']['l1s'],_0x5467dd[_0x2581e1['aid']+'/output/metadata/l2s']=_0x531f24['$self']['output']['metadata']['l1s'];else{if(_0x1ad064['type']==='signal'&&_0x4a101c===0x1)_0x5467dd[_0x2581e1['aid']+'/output/metadata/l1s']=_0x531f24['$self']['output']['metadata']['l1s'],_0x5467dd[_0x2581e1['aid']+'/output/metadata/l2s']=_0x531f24['$self']['output']['metadata']['l1s'];else{const _0xa91000='l'+_0x4a101c+'s';_0x5467dd[_0x2581e1['aid']+'/output/metadata/'+_0xa91000]=_0x531f24['$self']['output']['metadata'][_0xa91000];}}}}}exports['TelemetryService']=TelemetryService;
@@ -27,8 +27,8 @@ declare class WorkerService {
27
27
  static init(namespace: string, appId: string, guid: string, config: HotMeshConfig, logger: ILogger): Promise<WorkerService[]>;
28
28
  verifyWorkerFields(worker: HotMeshWorker): void;
29
29
  initStoreChannel(service: WorkerService, store: RedisClient): Promise<void>;
30
- initSubChannel(service: WorkerService, sub: RedisClient): Promise<void>;
31
- initStreamChannel(service: WorkerService, stream: RedisClient): Promise<void>;
30
+ initSubChannel(service: WorkerService, sub: RedisClient, store: RedisClient): Promise<void>;
31
+ initStreamChannel(service: WorkerService, stream: RedisClient, store: RedisClient): Promise<void>;
32
32
  initRouter(worker: HotMeshWorker, logger: ILogger): Promise<Router>;
33
33
  subscriptionHandler(): SubscriptionCallback;
34
34
  doRollCall(message: RollCallMessage): Promise<void>;