@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.
- package/build/index.d.ts +2 -1
- package/build/index.js +7 -1
- package/build/modules/key.js +1 -62
- package/build/modules/utils.js +1 -267
- package/build/package.json +12 -8
- package/build/services/activities/activity.js +1 -495
- package/build/services/activities/await.js +1 -109
- package/build/services/activities/cycle.js +1 -96
- package/build/services/activities/hook.js +1 -154
- package/build/services/activities/index.js +1 -20
- package/build/services/activities/interrupt.js +1 -149
- package/build/services/activities/signal.js +1 -118
- package/build/services/activities/trigger.js +1 -237
- package/build/services/activities/worker.js +1 -101
- package/build/services/collator/index.js +1 -197
- package/build/services/compiler/deployer.d.ts +3 -1
- package/build/services/compiler/deployer.js +1 -455
- package/build/services/compiler/index.d.ts +3 -1
- package/build/services/compiler/index.js +1 -91
- package/build/services/compiler/validator.js +1 -122
- package/build/services/engine/index.d.ts +5 -2
- package/build/services/engine/index.js +1 -562
- package/build/services/exporter/index.js +1 -93
- package/build/services/mapper/index.js +1 -67
- package/build/services/meshdata/index.d.ts +0 -1
- package/build/services/meshdata/index.js +16 -24
- package/build/services/meshflow/client.js +4 -8
- package/build/services/meshflow/exporter.js +1 -186
- package/build/services/meshflow/search.d.ts +4 -5
- package/build/services/meshflow/search.js +45 -35
- package/build/services/meshflow/workflow.d.ts +1 -1
- package/build/services/meshflow/workflow.js +3 -28
- package/build/services/pipe/functions/array.js +1 -74
- package/build/services/pipe/functions/bitwise.js +1 -24
- package/build/services/pipe/functions/conditional.js +1 -36
- package/build/services/pipe/functions/cron.js +1 -32
- package/build/services/pipe/functions/date.js +1 -164
- package/build/services/pipe/functions/index.js +1 -30
- package/build/services/pipe/functions/json.js +1 -12
- package/build/services/pipe/functions/logical.js +1 -12
- package/build/services/pipe/functions/math.js +1 -182
- package/build/services/pipe/functions/number.js +1 -60
- package/build/services/pipe/functions/object.js +1 -81
- package/build/services/pipe/functions/string.js +1 -69
- package/build/services/pipe/functions/symbol.js +1 -33
- package/build/services/pipe/functions/unary.js +1 -18
- package/build/services/pipe/index.js +1 -221
- package/build/services/quorum/index.d.ts +1 -1
- package/build/services/quorum/index.js +1 -219
- package/build/services/reporter/index.js +1 -331
- package/build/services/router/index.js +1 -420
- package/build/services/search/factory.d.ts +7 -0
- package/build/services/search/factory.js +20 -0
- package/build/services/search/index.d.ts +21 -0
- package/build/services/search/index.js +10 -0
- package/build/services/search/providers/redis/ioredis.d.ts +18 -0
- package/build/services/search/providers/redis/ioredis.js +1 -0
- package/build/services/search/providers/redis/redis.d.ts +18 -0
- package/build/services/search/providers/redis/redis.js +1 -0
- package/build/services/serializer/index.js +1 -265
- package/build/services/store/factory.d.ts +2 -1
- package/build/services/store/factory.js +2 -2
- package/build/services/store/index.d.ts +71 -97
- package/build/services/store/index.js +2 -939
- package/build/services/store/providers/postgres/postgres.d.ts +0 -0
- package/build/services/store/providers/postgres/postgres.js +0 -0
- package/build/services/store/providers/postgres/types/hash.d.ts +0 -0
- package/build/services/store/providers/postgres/types/hash.js +0 -0
- package/build/services/store/providers/postgres/types/list.d.ts +0 -0
- package/build/services/store/providers/postgres/types/list.js +0 -0
- package/build/services/store/providers/postgres/types/string.d.ts +0 -0
- package/build/services/store/providers/postgres/types/string.js +0 -0
- package/build/services/store/providers/postgres/types/zset.d.ts +0 -0
- package/build/services/store/providers/postgres/types/zset.js +0 -0
- package/build/services/store/providers/redis/_base.d.ts +98 -0
- package/build/services/store/providers/redis/_base.js +1 -0
- package/build/services/store/providers/redis/ioredis.d.ts +12 -0
- package/build/services/store/providers/redis/ioredis.js +1 -0
- package/build/services/store/providers/redis/redis.d.ts +13 -0
- package/build/services/store/providers/redis/redis.js +1 -0
- package/build/services/store/providers/store-initializable.d.ts +5 -0
- package/build/services/store/providers/store-initializable.js +1 -0
- package/build/services/stream/factory.d.ts +2 -1
- package/build/services/stream/factory.js +5 -5
- package/build/services/stream/index.d.ts +13 -14
- package/build/services/stream/index.js +3 -2
- package/build/services/stream/providers/postgres/_deploy.d.ts +4 -0
- package/build/services/stream/providers/postgres/_deploy.js +1 -0
- package/build/services/stream/providers/redis/ioredis.d.ts +21 -0
- package/build/services/stream/providers/redis/ioredis.js +1 -0
- package/build/services/stream/providers/redis/redis.d.ts +21 -0
- package/build/services/stream/providers/redis/redis.js +1 -0
- package/build/services/stream/providers/stream-initializable.d.ts +5 -0
- package/build/services/stream/providers/stream-initializable.js +1 -0
- package/build/services/sub/factory.d.ts +1 -1
- package/build/services/sub/factory.js +5 -5
- package/build/services/sub/index.d.ts +9 -7
- package/build/services/sub/index.js +3 -2
- package/build/services/sub/{clients → providers/redis}/ioredis.d.ts +7 -10
- package/build/services/sub/providers/redis/ioredis.js +1 -0
- package/build/services/sub/{clients → providers/redis}/redis.d.ts +7 -10
- package/build/services/sub/providers/redis/redis.js +1 -0
- package/build/services/task/index.js +1 -171
- package/build/services/telemetry/index.js +1 -225
- package/build/services/worker/index.d.ts +2 -2
- package/build/services/worker/index.js +1 -158
- package/build/types/redis.d.ts +5 -5
- package/index.ts +15 -1
- package/package.json +12 -8
- package/types/redis.ts +5 -5
- package/build/services/store/clients/ioredis.d.ts +0 -30
- package/build/services/store/clients/ioredis.js +0 -220
- package/build/services/store/clients/redis.d.ts +0 -32
- package/build/services/store/clients/redis.js +0 -319
- package/build/services/stream/clients/ioredis.d.ts +0 -24
- package/build/services/stream/clients/ioredis.js +0 -121
- package/build/services/stream/clients/redis.d.ts +0 -24
- package/build/services/stream/clients/redis.js +0 -161
- package/build/services/sub/clients/ioredis.js +0 -72
- package/build/services/sub/clients/redis.js +0 -63
|
@@ -1,221 +1 @@
|
|
|
1
|
-
|
|
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.Pipe = void 0;
|
|
7
|
-
const functions_1 = __importDefault(require("./functions"));
|
|
8
|
-
class Pipe {
|
|
9
|
-
constructor(rules, jobData, context) {
|
|
10
|
-
this.rules = rules;
|
|
11
|
-
this.jobData = jobData;
|
|
12
|
-
this.context = context;
|
|
13
|
-
}
|
|
14
|
-
isPipeType(currentRow) {
|
|
15
|
-
return !Array.isArray(currentRow) && '@pipe' in currentRow;
|
|
16
|
-
}
|
|
17
|
-
isreduceType(currentRow) {
|
|
18
|
-
return !Array.isArray(currentRow) && '@reduce' in currentRow;
|
|
19
|
-
}
|
|
20
|
-
static isPipeObject(obj) {
|
|
21
|
-
return (typeof obj === 'object' &&
|
|
22
|
-
obj !== null &&
|
|
23
|
-
!Array.isArray(obj) &&
|
|
24
|
-
'@pipe' in obj);
|
|
25
|
-
}
|
|
26
|
-
static resolve(unresolved, context) {
|
|
27
|
-
let pipe;
|
|
28
|
-
if (Pipe.isPipeObject(unresolved)) {
|
|
29
|
-
pipe = new Pipe(unresolved['@pipe'], context);
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
pipe = new Pipe([[unresolved]], context);
|
|
33
|
-
}
|
|
34
|
-
return pipe.process();
|
|
35
|
-
}
|
|
36
|
-
process(resolved = null) {
|
|
37
|
-
let index = 0;
|
|
38
|
-
if (!(resolved ||
|
|
39
|
-
this.isPipeType(this.rules[0]) ||
|
|
40
|
-
this.isreduceType(this.rules[0]))) {
|
|
41
|
-
resolved = this.processCells(this.rules[0]);
|
|
42
|
-
index = 1;
|
|
43
|
-
}
|
|
44
|
-
const len = this.rules.length;
|
|
45
|
-
const subPipeQueue = [];
|
|
46
|
-
for (let i = index; i < len; i++) {
|
|
47
|
-
resolved = this.processRow(this.rules[i], resolved, subPipeQueue);
|
|
48
|
-
}
|
|
49
|
-
return resolved[0];
|
|
50
|
-
}
|
|
51
|
-
cloneUnknown(value) {
|
|
52
|
-
if (value === null || typeof value !== 'object') {
|
|
53
|
-
return value;
|
|
54
|
-
}
|
|
55
|
-
if (value instanceof Date) {
|
|
56
|
-
return new Date(value.getTime());
|
|
57
|
-
}
|
|
58
|
-
if (value instanceof RegExp) {
|
|
59
|
-
return new RegExp(value);
|
|
60
|
-
}
|
|
61
|
-
if (Array.isArray(value)) {
|
|
62
|
-
return value.map((item) => this.cloneUnknown(item));
|
|
63
|
-
}
|
|
64
|
-
const clonedObj = {};
|
|
65
|
-
for (const key in value) {
|
|
66
|
-
if (Object.prototype.hasOwnProperty.call(value, key)) {
|
|
67
|
-
clonedObj[key] = this.cloneUnknown(value[key]);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return clonedObj;
|
|
71
|
-
}
|
|
72
|
-
reduce(input) {
|
|
73
|
-
let resolved = this.cloneUnknown(input[1] ?? null);
|
|
74
|
-
if (Array.isArray(input[0])) {
|
|
75
|
-
for (let index = 0; index < input[0].length; index++) {
|
|
76
|
-
this.context = {
|
|
77
|
-
$input: input[0],
|
|
78
|
-
$output: resolved,
|
|
79
|
-
$item: input[0][index],
|
|
80
|
-
$key: index.toString(),
|
|
81
|
-
$index: index,
|
|
82
|
-
};
|
|
83
|
-
resolved = this.process([resolved]);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
let index = -1;
|
|
88
|
-
for (const $key in input[0]) {
|
|
89
|
-
index++;
|
|
90
|
-
this.context = {
|
|
91
|
-
$input: input[0],
|
|
92
|
-
$output: resolved,
|
|
93
|
-
$item: input[0][$key],
|
|
94
|
-
$key,
|
|
95
|
-
$index: index,
|
|
96
|
-
};
|
|
97
|
-
resolved = this.process([resolved]);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
return [resolved];
|
|
101
|
-
}
|
|
102
|
-
processRow(currentRow, resolvedPriorRow, subPipeQueue) {
|
|
103
|
-
if (resolvedPriorRow && this.isreduceType(currentRow)) {
|
|
104
|
-
const subPipe = new Pipe(currentRow['@reduce'], this.jobData);
|
|
105
|
-
const reduced = subPipe.reduce(resolvedPriorRow);
|
|
106
|
-
return reduced;
|
|
107
|
-
}
|
|
108
|
-
else if (this.isPipeType(currentRow)) {
|
|
109
|
-
const subPipe = new Pipe(currentRow['@pipe'], this.jobData, this.context);
|
|
110
|
-
subPipeQueue.push(subPipe.process());
|
|
111
|
-
return resolvedPriorRow;
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
if (subPipeQueue.length > 0) {
|
|
115
|
-
resolvedPriorRow = [...subPipeQueue];
|
|
116
|
-
subPipeQueue.length = 0;
|
|
117
|
-
}
|
|
118
|
-
if (!resolvedPriorRow) {
|
|
119
|
-
return [].concat(this.processCells(Array.isArray(currentRow) ? [...currentRow] : []));
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
const [functionName, ...params] = currentRow;
|
|
123
|
-
let resolvedValue;
|
|
124
|
-
if (this.isContextVariable(functionName)) {
|
|
125
|
-
resolvedValue = this.resolveContextValue(functionName);
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
resolvedValue = Pipe.resolveFunction(functionName)(...resolvedPriorRow);
|
|
129
|
-
}
|
|
130
|
-
return [resolvedValue].concat(this.processCells([...params]));
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
static resolveFunction(functionName) {
|
|
135
|
-
let [prefix, suffix] = functionName.split('.');
|
|
136
|
-
prefix = prefix.substring(2);
|
|
137
|
-
suffix = suffix.substring(0, suffix.length - 1);
|
|
138
|
-
const domain = functions_1.default[prefix];
|
|
139
|
-
if (!domain) {
|
|
140
|
-
throw new Error(`Unknown domain name [${functionName}]: ${prefix}`);
|
|
141
|
-
}
|
|
142
|
-
if (!domain[suffix]) {
|
|
143
|
-
throw new Error(`Unknown domain function [${functionName}]: ${prefix}.${suffix}`);
|
|
144
|
-
}
|
|
145
|
-
return domain[suffix];
|
|
146
|
-
}
|
|
147
|
-
processCells(cells) {
|
|
148
|
-
const resolved = [];
|
|
149
|
-
if (Array.isArray(cells)) {
|
|
150
|
-
for (const currentCell of cells) {
|
|
151
|
-
resolved.push(this.resolveCellValue(currentCell));
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
return resolved;
|
|
155
|
-
}
|
|
156
|
-
isFunction(currentCell) {
|
|
157
|
-
return (typeof currentCell === 'string' &&
|
|
158
|
-
currentCell.startsWith('{@') &&
|
|
159
|
-
currentCell.endsWith('}'));
|
|
160
|
-
}
|
|
161
|
-
isContextVariable(currentCell) {
|
|
162
|
-
if (typeof currentCell === 'string' && currentCell.endsWith('}')) {
|
|
163
|
-
return (currentCell.startsWith('{$item') ||
|
|
164
|
-
currentCell.startsWith('{$key') ||
|
|
165
|
-
currentCell.startsWith('{$index') ||
|
|
166
|
-
currentCell.startsWith('{$input') ||
|
|
167
|
-
currentCell.startsWith('{$output'));
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
isMappable(currentCell) {
|
|
171
|
-
return (typeof currentCell === 'string' &&
|
|
172
|
-
currentCell.startsWith('{') &&
|
|
173
|
-
currentCell.endsWith('}'));
|
|
174
|
-
}
|
|
175
|
-
resolveCellValue(currentCell) {
|
|
176
|
-
if (this.isFunction(currentCell)) {
|
|
177
|
-
const fn = Pipe.resolveFunction(currentCell);
|
|
178
|
-
return fn.call();
|
|
179
|
-
}
|
|
180
|
-
else if (this.isContextVariable(currentCell)) {
|
|
181
|
-
return this.resolveContextValue(currentCell);
|
|
182
|
-
}
|
|
183
|
-
else if (this.isMappable(currentCell)) {
|
|
184
|
-
return this.resolveMappableValue(currentCell);
|
|
185
|
-
}
|
|
186
|
-
else {
|
|
187
|
-
return currentCell;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
getNestedProperty(obj, path) {
|
|
191
|
-
const pathParts = path.split('.');
|
|
192
|
-
let current = obj;
|
|
193
|
-
for (const part of pathParts) {
|
|
194
|
-
if (current === null ||
|
|
195
|
-
typeof current !== 'object' ||
|
|
196
|
-
!current.hasOwnProperty(part)) {
|
|
197
|
-
return undefined;
|
|
198
|
-
}
|
|
199
|
-
current = current[part];
|
|
200
|
-
}
|
|
201
|
-
return current;
|
|
202
|
-
}
|
|
203
|
-
resolveMappableValue(currentCell) {
|
|
204
|
-
const term = this.resolveMapTerm(currentCell);
|
|
205
|
-
return this.getNestedProperty(this.jobData, term);
|
|
206
|
-
}
|
|
207
|
-
resolveContextValue(currentCell) {
|
|
208
|
-
const term = this.resolveContextTerm(currentCell);
|
|
209
|
-
return this.getNestedProperty(this.context, term);
|
|
210
|
-
}
|
|
211
|
-
resolveContextTerm(currentCell) {
|
|
212
|
-
return currentCell.substring(1, currentCell.length - 1);
|
|
213
|
-
}
|
|
214
|
-
resolveFunctionTerm(currentCell) {
|
|
215
|
-
return currentCell.substring(2, currentCell.length - 1);
|
|
216
|
-
}
|
|
217
|
-
resolveMapTerm(currentCell) {
|
|
218
|
-
return currentCell.substring(1, currentCell.length - 1);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
exports.Pipe = Pipe;
|
|
1
|
+
'use strict';function _0x85eb(){const _0x5606d4=['30PiUfCK','4229739jHnBtx','1596KTWZIp','7014225UwYFgD','561gkCwjM','1573780NJgedU','214854VYGMyH','273xZttwy','6487283Qsqonj','1782019hfAWCM','32YfeqMh'];_0x85eb=function(){return _0x5606d4;};return _0x85eb();}(function(_0x2d680e,_0x30b5b7){const _0x43163a=_0x6d74,_0xe9b58a=_0x2d680e();while(!![]){try{const _0x377ee1=parseInt(_0x43163a(0x1c8))/0x1+-parseInt(_0x43163a(0x1c4))/0x2+-parseInt(_0x43163a(0x1c3))/0x3*(-parseInt(_0x43163a(0x1c1))/0x4)+-parseInt(_0x43163a(0x1c2))/0x5+parseInt(_0x43163a(0x1c5))/0x6*(parseInt(_0x43163a(0x1c6))/0x7)+-parseInt(_0x43163a(0x1c9))/0x8*(parseInt(_0x43163a(0x1cb))/0x9)+parseInt(_0x43163a(0x1ca))/0xa*(parseInt(_0x43163a(0x1c7))/0xb);if(_0x377ee1===_0x30b5b7)break;else _0xe9b58a['push'](_0xe9b58a['shift']());}catch(_0x5c5064){_0xe9b58a['push'](_0xe9b58a['shift']());}}}(_0x85eb,0xe89f7));var __importDefault=this&&this['__importDefault']||function(_0x1e471b){return _0x1e471b&&_0x1e471b['__esModule']?_0x1e471b:{'default':_0x1e471b};};Object['defineProperty'](exports,'__esModule',{'value':!![]}),exports['Pipe']=void 0x0;function _0x6d74(_0x3ece5c,_0x1aecce){const _0x85ebca=_0x85eb();return _0x6d74=function(_0x6d7488,_0x1c55e8){_0x6d7488=_0x6d7488-0x1c1;let _0x45964c=_0x85ebca[_0x6d7488];return _0x45964c;},_0x6d74(_0x3ece5c,_0x1aecce);}const functions_1=__importDefault(require('./functions'));class Pipe{constructor(_0x56552d,_0x550fbd,_0x1cc94b){this['rules']=_0x56552d,this['jobData']=_0x550fbd,this['context']=_0x1cc94b;}['isPipeType'](_0x5eefd1){return!Array['isArray'](_0x5eefd1)&&'@pipe'in _0x5eefd1;}['isreduceType'](_0x1973a6){return!Array['isArray'](_0x1973a6)&&'@reduce'in _0x1973a6;}static['isPipeObject'](_0x2007f2){return typeof _0x2007f2==='object'&&_0x2007f2!==null&&!Array['isArray'](_0x2007f2)&&'@pipe'in _0x2007f2;}static['resolve'](_0x6d7336,_0x5cd4a4){let _0x4dc343;return Pipe['isPipeObject'](_0x6d7336)?_0x4dc343=new Pipe(_0x6d7336['@pipe'],_0x5cd4a4):_0x4dc343=new Pipe([[_0x6d7336]],_0x5cd4a4),_0x4dc343['process']();}['process'](_0x156747=null){let _0x17f327=0x0;!(_0x156747||this['isPipeType'](this['rules'][0x0])||this['isreduceType'](this['rules'][0x0]))&&(_0x156747=this['processCells'](this['rules'][0x0]),_0x17f327=0x1);const _0x5a36cb=this['rules']['length'],_0x391568=[];for(let _0x191813=_0x17f327;_0x191813<_0x5a36cb;_0x191813++){_0x156747=this['processRow'](this['rules'][_0x191813],_0x156747,_0x391568);}return _0x156747[0x0];}['cloneUnknown'](_0x3a8f11){if(_0x3a8f11===null||typeof _0x3a8f11!=='object')return _0x3a8f11;if(_0x3a8f11 instanceof Date)return new Date(_0x3a8f11['getTime']());if(_0x3a8f11 instanceof RegExp)return new RegExp(_0x3a8f11);if(Array['isArray'](_0x3a8f11))return _0x3a8f11['map'](_0x1b3f50=>this['cloneUnknown'](_0x1b3f50));const _0x43e124={};for(const _0x5469f6 in _0x3a8f11){Object['prototype']['hasOwnProperty']['call'](_0x3a8f11,_0x5469f6)&&(_0x43e124[_0x5469f6]=this['cloneUnknown'](_0x3a8f11[_0x5469f6]));}return _0x43e124;}['reduce'](_0x1247a0){let _0x48285f=this['cloneUnknown'](_0x1247a0[0x1]??null);if(Array['isArray'](_0x1247a0[0x0]))for(let _0x397406=0x0;_0x397406<_0x1247a0[0x0]['length'];_0x397406++){this['context']={'$input':_0x1247a0[0x0],'$output':_0x48285f,'$item':_0x1247a0[0x0][_0x397406],'$key':_0x397406['toString'](),'$index':_0x397406},_0x48285f=this['process']([_0x48285f]);}else{let _0x24ec1b=-0x1;for(const _0xd1b19f in _0x1247a0[0x0]){_0x24ec1b++,this['context']={'$input':_0x1247a0[0x0],'$output':_0x48285f,'$item':_0x1247a0[0x0][_0xd1b19f],'$key':_0xd1b19f,'$index':_0x24ec1b},_0x48285f=this['process']([_0x48285f]);}}return[_0x48285f];}['processRow'](_0x4844f8,_0x489c68,_0x1c626f){if(_0x489c68&&this['isreduceType'](_0x4844f8)){const _0x59b71e=new Pipe(_0x4844f8['@reduce'],this['jobData']),_0x634c=_0x59b71e['reduce'](_0x489c68);return _0x634c;}else{if(this['isPipeType'](_0x4844f8)){const _0x49af64=new Pipe(_0x4844f8['@pipe'],this['jobData'],this['context']);return _0x1c626f['push'](_0x49af64['process']()),_0x489c68;}else{_0x1c626f['length']>0x0&&(_0x489c68=[..._0x1c626f],_0x1c626f['length']=0x0);if(!_0x489c68)return[]['concat'](this['processCells'](Array['isArray'](_0x4844f8)?[..._0x4844f8]:[]));else{const [_0x5cd848,..._0x11f08d]=_0x4844f8;let _0x1f6c47;return this['isContextVariable'](_0x5cd848)?_0x1f6c47=this['resolveContextValue'](_0x5cd848):_0x1f6c47=Pipe['resolveFunction'](_0x5cd848)(..._0x489c68),[_0x1f6c47]['concat'](this['processCells']([..._0x11f08d]));}}}}static['resolveFunction'](_0x5a7ea8){let [_0x1d5725,_0x1ebcf7]=_0x5a7ea8['split']('.');_0x1d5725=_0x1d5725['substring'](0x2),_0x1ebcf7=_0x1ebcf7['substring'](0x0,_0x1ebcf7['length']-0x1);const _0x51825b=functions_1['default'][_0x1d5725];if(!_0x51825b)throw new Error('Unknown\x20domain\x20name\x20['+_0x5a7ea8+']:\x20'+_0x1d5725);if(!_0x51825b[_0x1ebcf7])throw new Error('Unknown\x20domain\x20function\x20['+_0x5a7ea8+']:\x20'+_0x1d5725+'.'+_0x1ebcf7);return _0x51825b[_0x1ebcf7];}['processCells'](_0x1aa554){const _0x2a9e1e=[];if(Array['isArray'](_0x1aa554))for(const _0x4af12b of _0x1aa554){_0x2a9e1e['push'](this['resolveCellValue'](_0x4af12b));}return _0x2a9e1e;}['isFunction'](_0x12b358){return typeof _0x12b358==='string'&&_0x12b358['startsWith']('{@')&&_0x12b358['endsWith']('}');}['isContextVariable'](_0x45dac2){if(typeof _0x45dac2==='string'&&_0x45dac2['endsWith']('}'))return _0x45dac2['startsWith']('{$item')||_0x45dac2['startsWith']('{$key')||_0x45dac2['startsWith']('{$index')||_0x45dac2['startsWith']('{$input')||_0x45dac2['startsWith']('{$output');}['isMappable'](_0x3f5294){return typeof _0x3f5294==='string'&&_0x3f5294['startsWith']('{')&&_0x3f5294['endsWith']('}');}['resolveCellValue'](_0x4833f3){if(this['isFunction'](_0x4833f3)){const _0x45622d=Pipe['resolveFunction'](_0x4833f3);return _0x45622d['call']();}else{if(this['isContextVariable'](_0x4833f3))return this['resolveContextValue'](_0x4833f3);else return this['isMappable'](_0x4833f3)?this['resolveMappableValue'](_0x4833f3):_0x4833f3;}}['getNestedProperty'](_0x51e91f,_0x1bfae2){const _0x13cb9a=_0x1bfae2['split']('.');let _0x55d11f=_0x51e91f;for(const _0x3371d2 of _0x13cb9a){if(_0x55d11f===null||typeof _0x55d11f!=='object'||!_0x55d11f['hasOwnProperty'](_0x3371d2))return undefined;_0x55d11f=_0x55d11f[_0x3371d2];}return _0x55d11f;}['resolveMappableValue'](_0x1788b9){const _0x3b07b0=this['resolveMapTerm'](_0x1788b9);return this['getNestedProperty'](this['jobData'],_0x3b07b0);}['resolveContextValue'](_0x4bcd6f){const _0x2326d7=this['resolveContextTerm'](_0x4bcd6f);return this['getNestedProperty'](this['context'],_0x2326d7);}['resolveContextTerm'](_0x51d269){return _0x51d269['substring'](0x1,_0x51d269['length']-0x1);}['resolveFunctionTerm'](_0x2b7a80){return _0x2b7a80['substring'](0x2,_0x2b7a80['length']-0x1);}['resolveMapTerm'](_0x3680c1){return _0x3680c1['substring'](0x1,_0x3680c1['length']-0x1);}}exports['Pipe']=Pipe;
|
|
@@ -25,7 +25,7 @@ declare class QuorumService {
|
|
|
25
25
|
static init(namespace: string, appId: string, guid: string, config: HotMeshConfig, engine: EngineService, logger: ILogger): Promise<QuorumService>;
|
|
26
26
|
verifyQuorumFields(config: HotMeshConfig): void;
|
|
27
27
|
initStoreChannel(store: RedisClient): Promise<void>;
|
|
28
|
-
initSubChannel(sub: RedisClient): Promise<void>;
|
|
28
|
+
initSubChannel(sub: RedisClient, store: RedisClient): Promise<void>;
|
|
29
29
|
subscriptionHandler(): SubscriptionCallback;
|
|
30
30
|
sayPong(appId: string, guid: string, originator: string, details?: boolean): Promise<void>;
|
|
31
31
|
requestQuorum(delay?: number, details?: boolean): Promise<number>;
|
|
@@ -1,219 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.QuorumService = void 0;
|
|
4
|
-
const enums_1 = require("../../modules/enums");
|
|
5
|
-
const utils_1 = require("../../modules/utils");
|
|
6
|
-
const compiler_1 = require("../compiler");
|
|
7
|
-
const hotmesh_1 = require("../../types/hotmesh");
|
|
8
|
-
const factory_1 = require("../sub/factory");
|
|
9
|
-
const factory_2 = require("../store/factory");
|
|
10
|
-
class QuorumService {
|
|
11
|
-
constructor() {
|
|
12
|
-
this.profiles = [];
|
|
13
|
-
this.cacheMode = 'cache';
|
|
14
|
-
this.untilVersion = null;
|
|
15
|
-
this.quorum = null;
|
|
16
|
-
this.callbacks = [];
|
|
17
|
-
}
|
|
18
|
-
static async init(namespace, appId, guid, config, engine, logger) {
|
|
19
|
-
if (config.engine) {
|
|
20
|
-
const instance = new QuorumService();
|
|
21
|
-
instance.verifyQuorumFields(config);
|
|
22
|
-
instance.namespace = namespace;
|
|
23
|
-
instance.appId = appId;
|
|
24
|
-
instance.guid = guid;
|
|
25
|
-
instance.logger = logger;
|
|
26
|
-
instance.engine = engine;
|
|
27
|
-
await instance.initStoreChannel(config.engine.store);
|
|
28
|
-
await instance.initSubChannel(config.engine.sub);
|
|
29
|
-
await instance.subscribe.subscribe(hotmesh_1.KeyType.QUORUM, instance.subscriptionHandler(), appId);
|
|
30
|
-
await instance.subscribe.subscribe(hotmesh_1.KeyType.QUORUM, instance.subscriptionHandler(), appId, instance.guid);
|
|
31
|
-
instance.engine.processWebHooks();
|
|
32
|
-
instance.engine.processTimeHooks();
|
|
33
|
-
return instance;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
verifyQuorumFields(config) {
|
|
37
|
-
if (!(0, utils_1.identifyRedisType)(config.engine.store) ||
|
|
38
|
-
!(0, utils_1.identifyRedisType)(config.engine.sub)) {
|
|
39
|
-
throw new Error('quorum config must include `store` and `sub` fields.');
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
async initStoreChannel(store) {
|
|
43
|
-
this.store = await factory_2.StoreServiceFactory.init(store, this.namespace, this.appId, this.logger);
|
|
44
|
-
}
|
|
45
|
-
async initSubChannel(sub) {
|
|
46
|
-
this.subscribe = await factory_1.SubServiceFactory.init(sub, this.namespace, this.appId, this.guid, this.logger);
|
|
47
|
-
}
|
|
48
|
-
subscriptionHandler() {
|
|
49
|
-
const self = this;
|
|
50
|
-
return async (topic, message) => {
|
|
51
|
-
self.logger.debug('quorum-event-received', { topic, type: message.type });
|
|
52
|
-
if (message.type === 'activate') {
|
|
53
|
-
self.engine.setCacheMode(message.cache_mode, message.until_version);
|
|
54
|
-
}
|
|
55
|
-
else if (message.type === 'ping') {
|
|
56
|
-
self.sayPong(self.appId, self.guid, message.originator, message.details);
|
|
57
|
-
}
|
|
58
|
-
else if (message.type === 'pong' && self.guid === message.originator) {
|
|
59
|
-
self.quorum = self.quorum + 1;
|
|
60
|
-
if (message.profile) {
|
|
61
|
-
self.profiles.push(message.profile);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
else if (message.type === 'throttle') {
|
|
65
|
-
self.engine.throttle(message.throttle);
|
|
66
|
-
}
|
|
67
|
-
else if (message.type === 'work') {
|
|
68
|
-
self.engine.processWebHooks();
|
|
69
|
-
}
|
|
70
|
-
else if (message.type === 'job') {
|
|
71
|
-
self.engine.routeToSubscribers(message.topic, message.job);
|
|
72
|
-
}
|
|
73
|
-
else if (message.type === 'cron') {
|
|
74
|
-
self.engine.processTimeHooks();
|
|
75
|
-
}
|
|
76
|
-
else if (message.type === 'rollcall') {
|
|
77
|
-
self.doRollCall(message);
|
|
78
|
-
}
|
|
79
|
-
if (self.callbacks.length > 0) {
|
|
80
|
-
self.callbacks.forEach((cb) => cb(topic, message));
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
async sayPong(appId, guid, originator, details = false) {
|
|
85
|
-
let profile;
|
|
86
|
-
if (details) {
|
|
87
|
-
const stream = this.engine.stream.mintKey(hotmesh_1.KeyType.STREAMS, {
|
|
88
|
-
appId: this.appId,
|
|
89
|
-
});
|
|
90
|
-
profile = {
|
|
91
|
-
engine_id: this.guid,
|
|
92
|
-
namespace: this.namespace,
|
|
93
|
-
app_id: this.appId,
|
|
94
|
-
stream,
|
|
95
|
-
counts: this.engine.router.counts,
|
|
96
|
-
timestamp: (0, utils_1.formatISODate)(new Date()),
|
|
97
|
-
inited: this.engine.inited,
|
|
98
|
-
throttle: this.engine.router.throttle,
|
|
99
|
-
reclaimDelay: this.engine.router.reclaimDelay,
|
|
100
|
-
reclaimCount: this.engine.router.reclaimCount,
|
|
101
|
-
system: await (0, utils_1.getSystemHealth)(),
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
this.store.publish(hotmesh_1.KeyType.QUORUM, {
|
|
105
|
-
type: 'pong',
|
|
106
|
-
guid,
|
|
107
|
-
originator,
|
|
108
|
-
profile,
|
|
109
|
-
}, appId);
|
|
110
|
-
}
|
|
111
|
-
async requestQuorum(delay = enums_1.HMSH_QUORUM_DELAY_MS, details = false) {
|
|
112
|
-
const quorum = this.quorum;
|
|
113
|
-
this.quorum = 0;
|
|
114
|
-
this.profiles.length = 0;
|
|
115
|
-
await this.store.publish(hotmesh_1.KeyType.QUORUM, {
|
|
116
|
-
type: 'ping',
|
|
117
|
-
originator: this.guid,
|
|
118
|
-
details,
|
|
119
|
-
}, this.appId);
|
|
120
|
-
await (0, utils_1.sleepFor)(delay);
|
|
121
|
-
return quorum;
|
|
122
|
-
}
|
|
123
|
-
async doRollCall(message) {
|
|
124
|
-
let iteration = 0;
|
|
125
|
-
const max = !isNaN(message.max) ? message.max : enums_1.HMSH_QUORUM_ROLLCALL_CYCLES;
|
|
126
|
-
if (this.rollCallInterval)
|
|
127
|
-
clearTimeout(this.rollCallInterval);
|
|
128
|
-
const base = message.interval / 2;
|
|
129
|
-
const amount = base + Math.ceil(Math.random() * base);
|
|
130
|
-
do {
|
|
131
|
-
await (0, utils_1.sleepFor)(Math.ceil(Math.random() * 1000));
|
|
132
|
-
await this.sayPong(this.appId, this.guid, null, true);
|
|
133
|
-
if (!message.interval)
|
|
134
|
-
return;
|
|
135
|
-
const { promise, timerId } = (0, utils_1.XSleepFor)(amount * 1000);
|
|
136
|
-
this.rollCallInterval = timerId;
|
|
137
|
-
await promise;
|
|
138
|
-
} while (this.rollCallInterval && iteration++ < max - 1);
|
|
139
|
-
}
|
|
140
|
-
cancelRollCall() {
|
|
141
|
-
if (this.rollCallInterval) {
|
|
142
|
-
clearTimeout(this.rollCallInterval);
|
|
143
|
-
delete this.rollCallInterval;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
stop() {
|
|
147
|
-
this.cancelRollCall();
|
|
148
|
-
}
|
|
149
|
-
async pub(quorumMessage) {
|
|
150
|
-
return await this.store.publish(hotmesh_1.KeyType.QUORUM, quorumMessage, this.appId, quorumMessage.topic || quorumMessage.guid);
|
|
151
|
-
}
|
|
152
|
-
async sub(callback) {
|
|
153
|
-
this.callbacks.push(callback);
|
|
154
|
-
}
|
|
155
|
-
async unsub(callback) {
|
|
156
|
-
this.callbacks = this.callbacks.filter((cb) => cb !== callback);
|
|
157
|
-
}
|
|
158
|
-
async rollCall(delay = enums_1.HMSH_QUORUM_DELAY_MS) {
|
|
159
|
-
await this.requestQuorum(delay, true);
|
|
160
|
-
const targetStreams = [];
|
|
161
|
-
const multi = this.store.getMulti();
|
|
162
|
-
this.profiles.forEach((profile) => {
|
|
163
|
-
if (!targetStreams.includes(profile.stream)) {
|
|
164
|
-
targetStreams.push(profile.stream);
|
|
165
|
-
this.store.xlen(profile.stream, multi);
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
const stream_depths = (await multi.exec());
|
|
169
|
-
this.profiles.forEach(async (profile) => {
|
|
170
|
-
const index = targetStreams.indexOf(profile.stream);
|
|
171
|
-
if (index != -1) {
|
|
172
|
-
profile.stream_depth = Array.isArray(stream_depths[index])
|
|
173
|
-
? stream_depths[index][1]
|
|
174
|
-
: stream_depths[index];
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
return this.profiles;
|
|
178
|
-
}
|
|
179
|
-
async activate(version, delay = enums_1.HMSH_QUORUM_DELAY_MS, count = 0) {
|
|
180
|
-
version = version.toString();
|
|
181
|
-
const canActivate = await this.store.reserveScoutRole('activate', Math.ceil(delay * 6 / 1000) + 1);
|
|
182
|
-
if (!canActivate) {
|
|
183
|
-
this.logger.debug('quorum-activation-awaiting', { version });
|
|
184
|
-
await (0, utils_1.sleepFor)(delay * 6);
|
|
185
|
-
const app = await this.store.getApp(this.appId, true);
|
|
186
|
-
return app?.active == true && app?.version === version;
|
|
187
|
-
}
|
|
188
|
-
const config = await this.engine.getVID();
|
|
189
|
-
await this.requestQuorum(delay);
|
|
190
|
-
const q1 = await this.requestQuorum(delay);
|
|
191
|
-
const q2 = await this.requestQuorum(delay);
|
|
192
|
-
const q3 = await this.requestQuorum(delay);
|
|
193
|
-
if (q1 && q1 === q2 && q2 === q3) {
|
|
194
|
-
this.logger.info('quorum-rollcall-succeeded', { q1, q2, q3 });
|
|
195
|
-
this.store.publish(hotmesh_1.KeyType.QUORUM, { type: 'activate', cache_mode: 'nocache', until_version: version }, this.appId);
|
|
196
|
-
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
197
|
-
await this.store.releaseScoutRole('activate');
|
|
198
|
-
if (this.engine.untilVersion === version) {
|
|
199
|
-
this.logger.info('quorum-activation-succeeded', { version });
|
|
200
|
-
const { id } = config;
|
|
201
|
-
const compiler = new compiler_1.CompilerService(this.store, this.logger);
|
|
202
|
-
return await compiler.activate(id, version);
|
|
203
|
-
}
|
|
204
|
-
else {
|
|
205
|
-
this.logger.error('quorum-activation-error', { version });
|
|
206
|
-
throw new Error(`UntilVersion Not Received. Version ${version} not activated`);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
else {
|
|
210
|
-
this.logger.warn('quorum-rollcall-error', { q1, q2, q3, count });
|
|
211
|
-
this.store.releaseScoutRole('activate');
|
|
212
|
-
if (count < enums_1.HMSH_ACTIVATION_MAX_RETRY) {
|
|
213
|
-
return await this.activate(version, delay * 2, count + 1);
|
|
214
|
-
}
|
|
215
|
-
throw new Error(`Quorum not reached. Version ${version} not activated.`);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
exports.QuorumService = QuorumService;
|
|
1
|
+
'use strict';function _0x2692(_0x2dee21,_0x414ef7){const _0x442f65=_0x442f();return _0x2692=function(_0x2692fc,_0x164223){_0x2692fc=_0x2692fc-0x13e;let _0x1eef29=_0x442f65[_0x2692fc];return _0x1eef29;},_0x2692(_0x2dee21,_0x414ef7);}function _0x442f(){const _0x59f399=['3uUBIwM','56366hkDDfw','913CYLQpi','48BMlcTq','8300eCpWii','4128aENgpY','7173675hfVPoA','10FkAdCn','355911GTFTZK','10596288AChrwZ','1350727vcQPkw','384348vxIXcR'];_0x442f=function(){return _0x59f399;};return _0x442f();}(function(_0x2d7849,_0x26406e){const _0x1b2041=_0x2692,_0x19f044=_0x2d7849();while(!![]){try{const _0x204c11=parseInt(_0x1b2041(0x149))/0x1*(parseInt(_0x1b2041(0x13e))/0x2)+parseInt(_0x1b2041(0x145))/0x3*(-parseInt(_0x1b2041(0x140))/0x4)+parseInt(_0x1b2041(0x141))/0x5*(-parseInt(_0x1b2041(0x142))/0x6)+parseInt(_0x1b2041(0x147))/0x7+parseInt(_0x1b2041(0x146))/0x8+parseInt(_0x1b2041(0x143))/0x9*(-parseInt(_0x1b2041(0x144))/0xa)+parseInt(_0x1b2041(0x13f))/0xb*(parseInt(_0x1b2041(0x148))/0xc);if(_0x204c11===_0x26406e)break;else _0x19f044['push'](_0x19f044['shift']());}catch(_0x1eb1c6){_0x19f044['push'](_0x19f044['shift']());}}}(_0x442f,0xdb276));Object['defineProperty'](exports,'__esModule',{'value':!![]}),exports['QuorumService']=void 0x0;const enums_1=require('../../modules/enums'),utils_1=require('../../modules/utils'),compiler_1=require('../compiler'),hotmesh_1=require('../../types/hotmesh'),factory_1=require('../sub/factory'),factory_2=require('../store/factory');class QuorumService{constructor(){this['profiles']=[],this['cacheMode']='cache',this['untilVersion']=null,this['quorum']=null,this['callbacks']=[];}static async['init'](_0x3f2d42,_0x42ec5a,_0x27adf7,_0x596b2c,_0x4438b5,_0x21a75f){if(_0x596b2c['engine']){const _0x4c56a4=new QuorumService();return _0x4c56a4['verifyQuorumFields'](_0x596b2c),_0x4c56a4['namespace']=_0x3f2d42,_0x4c56a4['appId']=_0x42ec5a,_0x4c56a4['guid']=_0x27adf7,_0x4c56a4['logger']=_0x21a75f,_0x4c56a4['engine']=_0x4438b5,await _0x4c56a4['initStoreChannel'](_0x596b2c['engine']['store']),await _0x4c56a4['initSubChannel'](_0x596b2c['engine']['sub'],_0x596b2c['engine']['store']),await _0x4c56a4['subscribe']['subscribe'](hotmesh_1['KeyType']['QUORUM'],_0x4c56a4['subscriptionHandler'](),_0x42ec5a),await _0x4c56a4['subscribe']['subscribe'](hotmesh_1['KeyType']['QUORUM'],_0x4c56a4['subscriptionHandler'](),_0x42ec5a,_0x4c56a4['guid']),_0x4c56a4['engine']['processWebHooks'](),_0x4c56a4['engine']['processTimeHooks'](),_0x4c56a4;}}['verifyQuorumFields'](_0x4c8629){if(!(0x0,utils_1['identifyRedisType'])(_0x4c8629['engine']['store'])||!(0x0,utils_1['identifyRedisType'])(_0x4c8629['engine']['sub']))throw new Error('quorum\x20config\x20must\x20include\x20`store`\x20and\x20`sub`\x20fields.');}async['initStoreChannel'](_0x1ce3ac){this['store']=await factory_2['StoreServiceFactory']['init'](_0x1ce3ac,this['namespace'],this['appId'],this['logger']);}async['initSubChannel'](_0x1e22cd,_0x5923d0){this['subscribe']=await factory_1['SubServiceFactory']['init'](_0x1e22cd,_0x5923d0,this['namespace'],this['appId'],this['guid'],this['logger']);}['subscriptionHandler'](){const _0x1300be=this;return async(_0x2f464e,_0xfb96d6)=>{_0x1300be['logger']['debug']('quorum-event-received',{'topic':_0x2f464e,'type':_0xfb96d6['type']});if(_0xfb96d6['type']==='activate')_0x1300be['engine']['setCacheMode'](_0xfb96d6['cache_mode'],_0xfb96d6['until_version']);else{if(_0xfb96d6['type']==='ping')_0x1300be['sayPong'](_0x1300be['appId'],_0x1300be['guid'],_0xfb96d6['originator'],_0xfb96d6['details']);else{if(_0xfb96d6['type']==='pong'&&_0x1300be['guid']===_0xfb96d6['originator'])_0x1300be['quorum']=_0x1300be['quorum']+0x1,_0xfb96d6['profile']&&_0x1300be['profiles']['push'](_0xfb96d6['profile']);else{if(_0xfb96d6['type']==='throttle')_0x1300be['engine']['throttle'](_0xfb96d6['throttle']);else{if(_0xfb96d6['type']==='work')_0x1300be['engine']['processWebHooks']();else{if(_0xfb96d6['type']==='job')_0x1300be['engine']['routeToSubscribers'](_0xfb96d6['topic'],_0xfb96d6['job']);else{if(_0xfb96d6['type']==='cron')_0x1300be['engine']['processTimeHooks']();else _0xfb96d6['type']==='rollcall'&&_0x1300be['doRollCall'](_0xfb96d6);}}}}}}_0x1300be['callbacks']['length']>0x0&&_0x1300be['callbacks']['forEach'](_0x2f8a8e=>_0x2f8a8e(_0x2f464e,_0xfb96d6));};}async['sayPong'](_0x1294ea,_0x144199,_0x1e1e45,_0xcd84cb=![]){let _0x5452e4;if(_0xcd84cb){const _0x9a3a1b=this['engine']['store']['mintKey'](hotmesh_1['KeyType']['STREAMS'],{'appId':this['appId']});_0x5452e4={'engine_id':this['guid'],'namespace':this['namespace'],'app_id':this['appId'],'stream':_0x9a3a1b,'counts':this['engine']['router']['counts'],'timestamp':(0x0,utils_1['formatISODate'])(new Date()),'inited':this['engine']['inited'],'throttle':this['engine']['router']['throttle'],'reclaimDelay':this['engine']['router']['reclaimDelay'],'reclaimCount':this['engine']['router']['reclaimCount'],'system':await(0x0,utils_1['getSystemHealth'])()};}this['subscribe']['publish'](hotmesh_1['KeyType']['QUORUM'],{'type':'pong','guid':_0x144199,'originator':_0x1e1e45,'profile':_0x5452e4},_0x1294ea);}async['requestQuorum'](_0x467762=enums_1['HMSH_QUORUM_DELAY_MS'],_0x354d78=![]){const _0xb4a898=this['quorum'];return this['quorum']=0x0,this['profiles']['length']=0x0,await this['subscribe']['publish'](hotmesh_1['KeyType']['QUORUM'],{'type':'ping','originator':this['guid'],'details':_0x354d78},this['appId']),await(0x0,utils_1['sleepFor'])(_0x467762),_0xb4a898;}async['doRollCall'](_0x1445e3){let _0x573230=0x0;const _0x179df0=!isNaN(_0x1445e3['max'])?_0x1445e3['max']:enums_1['HMSH_QUORUM_ROLLCALL_CYCLES'];if(this['rollCallInterval'])clearTimeout(this['rollCallInterval']);const _0x2a2705=_0x1445e3['interval']/0x2,_0x190dd9=_0x2a2705+Math['ceil'](Math['random']()*_0x2a2705);do{await(0x0,utils_1['sleepFor'])(Math['ceil'](Math['random']()*0x3e8)),await this['sayPong'](this['appId'],this['guid'],null,!![]);if(!_0x1445e3['interval'])return;const {promise:_0xbb2684,timerId:_0x57887a}=(0x0,utils_1['XSleepFor'])(_0x190dd9*0x3e8);this['rollCallInterval']=_0x57887a,await _0xbb2684;}while(this['rollCallInterval']&&_0x573230++<_0x179df0-0x1);}['cancelRollCall'](){this['rollCallInterval']&&(clearTimeout(this['rollCallInterval']),delete this['rollCallInterval']);}['stop'](){this['cancelRollCall']();}async['pub'](_0xd44d42){return await this['subscribe']['publish'](hotmesh_1['KeyType']['QUORUM'],_0xd44d42,this['appId'],_0xd44d42['topic']||_0xd44d42['guid']);}async['sub'](_0x2dffc3){this['callbacks']['push'](_0x2dffc3);}async['unsub'](_0x33d7c1){this['callbacks']=this['callbacks']['filter'](_0x44ae9e=>_0x44ae9e!==_0x33d7c1);}async['rollCall'](_0xfa05df=enums_1['HMSH_QUORUM_DELAY_MS']){await this['requestQuorum'](_0xfa05df,!![]);const _0x4f26b1=[],_0x15c834=this['store']['getMulti']();this['profiles']['forEach'](_0x98cb33=>{!_0x4f26b1['includes'](_0x98cb33['stream'])&&(_0x4f26b1['push'](_0x98cb33['stream']),this['engine']['stream']['getMessageDepth'](_0x98cb33['stream'],_0x15c834));});const _0x1981ad=await _0x15c834['exec']();return this['profiles']['forEach'](async _0x40ccf5=>{const _0x4db301=_0x4f26b1['indexOf'](_0x40ccf5['stream']);_0x4db301!=-0x1&&(_0x40ccf5['stream_depth']=Array['isArray'](_0x1981ad[_0x4db301])?_0x1981ad[_0x4db301][0x1]:_0x1981ad[_0x4db301]);}),this['profiles'];}async['activate'](_0x2094ba,_0x58344f=enums_1['HMSH_QUORUM_DELAY_MS'],_0x402dd4=0x0){_0x2094ba=_0x2094ba['toString']();const _0x3fa73f=await this['store']['reserveScoutRole']('activate',Math['ceil'](_0x58344f*0x6/0x3e8)+0x1);if(!_0x3fa73f){this['logger']['debug']('quorum-activation-awaiting',{'version':_0x2094ba}),await(0x0,utils_1['sleepFor'])(_0x58344f*0x6);const _0x20005c=await this['store']['getApp'](this['appId'],!![]);return _0x20005c?.['active']==!![]&&_0x20005c?.['version']===_0x2094ba;}const _0x4a64cf=await this['engine']['getVID']();await this['requestQuorum'](_0x58344f);const _0x2769ac=await this['requestQuorum'](_0x58344f),_0x27a950=await this['requestQuorum'](_0x58344f),_0x9b3c68=await this['requestQuorum'](_0x58344f);if(_0x2769ac&&_0x2769ac===_0x27a950&&_0x27a950===_0x9b3c68){this['logger']['info']('quorum-rollcall-succeeded',{'q1':_0x2769ac,'q2':_0x27a950,'q3':_0x9b3c68}),this['subscribe']['publish'](hotmesh_1['KeyType']['QUORUM'],{'type':'activate','cache_mode':'nocache','until_version':_0x2094ba},this['appId']),await new Promise(_0x45c2f7=>setTimeout(_0x45c2f7,_0x58344f)),await this['store']['releaseScoutRole']('activate');if(this['engine']['untilVersion']===_0x2094ba){this['logger']['info']('quorum-activation-succeeded',{'version':_0x2094ba});const {id:_0x595bad}=_0x4a64cf,_0x10e07f=new compiler_1['CompilerService'](this['store'],this['engine']['stream'],this['logger']);return await _0x10e07f['activate'](_0x595bad,_0x2094ba);}else{this['logger']['error']('quorum-activation-error',{'version':_0x2094ba});throw new Error('UntilVersion\x20Not\x20Received.\x20Version\x20'+_0x2094ba+'\x20not\x20activated');}}else{this['logger']['warn']('quorum-rollcall-error',{'q1':_0x2769ac,'q2':_0x27a950,'q3':_0x9b3c68,'count':_0x402dd4}),this['store']['releaseScoutRole']('activate');if(_0x402dd4<enums_1['HMSH_ACTIVATION_MAX_RETRY'])return await this['activate'](_0x2094ba,_0x58344f*0x2,_0x402dd4+0x1);throw new Error('Quorum\x20not\x20reached.\x20Version\x20'+_0x2094ba+'\x20not\x20activated.');}}}exports['QuorumService']=QuorumService;
|