@hotmeshio/hotmesh 0.3.32 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +128 -823
- package/build/index.d.ts +9 -9
- package/build/index.js +10 -10
- package/build/modules/enums.d.ts +23 -23
- package/build/modules/enums.js +26 -26
- package/build/modules/errors.d.ts +16 -16
- package/build/modules/errors.js +28 -28
- package/build/modules/key.js +190 -1
- package/build/modules/utils.js +374 -1
- package/build/package.json +22 -21
- package/build/services/activities/activity.js +549 -1
- package/build/services/activities/await.js +114 -1
- package/build/services/activities/cycle.js +112 -1
- package/build/services/activities/hook.js +168 -1
- package/build/services/activities/index.js +20 -1
- package/build/services/activities/interrupt.js +158 -1
- package/build/services/activities/signal.js +134 -1
- package/build/services/activities/trigger.js +246 -1
- package/build/services/activities/worker.js +106 -1
- package/build/services/collator/index.js +293 -1
- package/build/services/compiler/deployer.js +488 -1
- package/build/services/compiler/index.js +112 -1
- package/build/services/compiler/validator.js +147 -1
- package/build/services/engine/index.js +761 -1
- package/build/services/exporter/index.js +126 -1
- package/build/services/hotmesh/index.d.ts +160 -17
- package/build/services/hotmesh/index.js +160 -17
- package/build/services/mapper/index.js +81 -1
- package/build/services/{meshflow → memflow}/client.d.ts +3 -3
- package/build/services/{meshflow → memflow}/client.js +17 -16
- package/build/services/{meshflow → memflow}/connection.d.ts +2 -2
- package/build/services/{meshflow → memflow}/connection.js +1 -1
- package/build/services/memflow/context.d.ts +143 -0
- package/build/services/memflow/context.js +299 -0
- package/build/services/{meshflow → memflow}/exporter.d.ts +6 -6
- package/build/services/memflow/exporter.js +215 -0
- package/build/services/{meshflow → memflow}/handle.d.ts +4 -4
- package/build/services/{meshflow → memflow}/handle.js +2 -2
- package/build/services/{meshflow → memflow}/index.d.ts +18 -13
- package/build/services/{meshflow → memflow}/index.js +26 -21
- package/build/services/{meshflow → memflow}/schemas/factory.d.ts +4 -4
- package/build/services/{meshflow → memflow}/schemas/factory.js +5 -5
- package/build/services/{meshflow → memflow}/search.d.ts +1 -1
- package/build/services/{meshflow → memflow}/search.js +4 -4
- package/build/services/{meshflow → memflow}/worker.d.ts +5 -5
- package/build/services/{meshflow → memflow}/worker.js +24 -24
- package/build/services/memflow/workflow/common.d.ts +20 -0
- package/build/services/memflow/workflow/common.js +47 -0
- package/build/services/memflow/workflow/contextMethods.d.ts +14 -0
- package/build/services/memflow/workflow/contextMethods.js +33 -0
- package/build/services/{meshflow → memflow}/workflow/execChild.js +12 -12
- package/build/services/memflow/workflow/execHook.d.ts +65 -0
- package/build/services/memflow/workflow/execHook.js +73 -0
- package/build/services/{meshflow → memflow}/workflow/hook.js +19 -3
- package/build/services/{meshflow → memflow}/workflow/index.d.ts +7 -3
- package/build/services/{meshflow → memflow}/workflow/index.js +7 -3
- package/build/services/{meshflow → memflow}/workflow/proxyActivities.d.ts +2 -2
- package/build/services/{meshflow → memflow}/workflow/proxyActivities.js +8 -8
- package/build/services/{meshflow → memflow}/workflow/sleepFor.js +2 -2
- package/build/services/{meshflow → memflow}/workflow/waitFor.js +2 -2
- package/build/services/meshdata/index.d.ts +24 -24
- package/build/services/meshdata/index.js +40 -40
- package/build/services/pipe/functions/array.js +74 -1
- package/build/services/pipe/functions/bitwise.js +24 -1
- package/build/services/pipe/functions/conditional.js +36 -1
- package/build/services/pipe/functions/cron.js +40 -1
- package/build/services/pipe/functions/date.js +171 -1
- package/build/services/pipe/functions/index.js +30 -1
- package/build/services/pipe/functions/json.js +12 -1
- package/build/services/pipe/functions/logical.js +12 -1
- package/build/services/pipe/functions/math.js +184 -1
- package/build/services/pipe/functions/number.js +60 -1
- package/build/services/pipe/functions/object.js +81 -1
- package/build/services/pipe/functions/string.js +69 -1
- package/build/services/pipe/functions/symbol.js +33 -1
- package/build/services/pipe/functions/unary.js +18 -1
- package/build/services/pipe/index.js +242 -1
- package/build/services/quorum/index.js +263 -1
- package/build/services/reporter/index.js +348 -1
- package/build/services/router/config/index.d.ts +11 -0
- package/build/services/router/config/index.js +36 -0
- package/build/services/router/consumption/index.d.ts +34 -0
- package/build/services/router/consumption/index.js +395 -0
- package/build/services/router/error-handling/index.d.ts +8 -0
- package/build/services/router/error-handling/index.js +98 -0
- package/build/services/router/index.d.ts +13 -16
- package/build/services/router/index.js +121 -1
- package/build/services/router/lifecycle/index.d.ts +27 -0
- package/build/services/router/lifecycle/index.js +80 -0
- package/build/services/router/telemetry/index.d.ts +11 -0
- package/build/services/router/telemetry/index.js +32 -0
- package/build/services/router/throttling/index.d.ts +23 -0
- package/build/services/router/throttling/index.js +76 -0
- package/build/services/search/index.d.ts +2 -1
- package/build/services/search/providers/postgres/postgres.d.ts +2 -1
- package/build/services/search/providers/postgres/postgres.js +149 -1
- package/build/services/search/providers/redis/ioredis.d.ts +1 -0
- package/build/services/search/providers/redis/ioredis.js +121 -1
- package/build/services/search/providers/redis/redis.d.ts +1 -0
- package/build/services/search/providers/redis/redis.js +134 -1
- package/build/services/serializer/index.js +282 -1
- package/build/services/store/providers/postgres/kvsql.d.ts +1 -1
- package/build/services/store/providers/postgres/kvsql.js +198 -1
- package/build/services/store/providers/postgres/kvtables.js +441 -1
- package/build/services/store/providers/postgres/kvtransaction.js +248 -1
- package/build/services/store/providers/postgres/kvtypes/hash.d.ts +1 -1
- package/build/services/store/providers/postgres/kvtypes/hash.js +1287 -1
- package/build/services/store/providers/postgres/kvtypes/list.js +194 -1
- package/build/services/store/providers/postgres/kvtypes/string.js +115 -1
- package/build/services/store/providers/postgres/kvtypes/zset.js +214 -1
- package/build/services/store/providers/postgres/postgres.js +1036 -1
- package/build/services/store/providers/redis/_base.js +980 -1
- package/build/services/store/providers/redis/ioredis.js +180 -1
- package/build/services/store/providers/redis/redis.js +199 -1
- package/build/services/store/providers/store-initializable.js +2 -1
- package/build/services/stream/index.d.ts +5 -0
- package/build/services/stream/providers/nats/nats.d.ts +1 -0
- package/build/services/stream/providers/nats/nats.js +225 -1
- package/build/services/stream/providers/postgres/kvtables.d.ts +1 -0
- package/build/services/stream/providers/postgres/kvtables.js +146 -1
- package/build/services/stream/providers/postgres/postgres.d.ts +19 -0
- package/build/services/stream/providers/postgres/postgres.js +519 -1
- package/build/services/stream/providers/redis/ioredis.d.ts +1 -0
- package/build/services/stream/providers/redis/ioredis.js +272 -1
- package/build/services/stream/providers/redis/redis.d.ts +1 -0
- package/build/services/stream/providers/redis/redis.js +305 -1
- package/build/services/stream/providers/stream-initializable.js +2 -1
- package/build/services/sub/providers/nats/nats.js +105 -1
- package/build/services/sub/providers/postgres/postgres.js +92 -1
- package/build/services/sub/providers/redis/ioredis.js +81 -1
- package/build/services/sub/providers/redis/redis.js +72 -1
- package/build/services/task/index.js +206 -1
- package/build/services/telemetry/index.js +306 -1
- package/build/services/worker/index.js +197 -1
- package/build/types/error.d.ts +5 -5
- package/build/types/exporter.d.ts +1 -1
- package/build/types/index.d.ts +3 -3
- package/build/types/manifest.d.ts +2 -2
- package/build/types/{meshflow.d.ts → memflow.d.ts} +15 -15
- package/build/types/meshdata.d.ts +3 -3
- package/build/types/postgres.d.ts +7 -0
- package/build/types/stream.d.ts +3 -0
- package/index.ts +11 -11
- package/package.json +22 -21
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- package/build/services/meshflow/exporter.js +0 -1
- package/build/services/meshflow/workflow/common.d.ts +0 -18
- package/build/services/meshflow/workflow/common.js +0 -45
- package/typedoc.json +0 -46
- package/types/activity.ts +0 -268
- package/types/app.ts +0 -20
- package/types/async.ts +0 -6
- package/types/cache.ts +0 -1
- package/types/collator.ts +0 -9
- package/types/error.ts +0 -56
- package/types/exporter.ts +0 -102
- package/types/hook.ts +0 -44
- package/types/hotmesh.ts +0 -314
- package/types/index.ts +0 -306
- package/types/job.ts +0 -233
- package/types/logger.ts +0 -8
- package/types/manifest.ts +0 -70
- package/types/map.ts +0 -5
- package/types/meshcall.ts +0 -235
- package/types/meshdata.ts +0 -278
- package/types/meshflow.ts +0 -645
- package/types/ms.d.ts +0 -7
- package/types/nats.ts +0 -270
- package/types/pipe.ts +0 -90
- package/types/postgres.ts +0 -105
- package/types/provider.ts +0 -161
- package/types/quorum.ts +0 -167
- package/types/redis.ts +0 -404
- package/types/serializer.ts +0 -40
- package/types/stats.ts +0 -117
- package/types/stream.ts +0 -227
- package/types/task.ts +0 -7
- package/types/telemetry.ts +0 -16
- package/types/transition.ts +0 -20
- /package/build/services/{meshflow → memflow}/workflow/all.d.ts +0 -0
- /package/build/services/{meshflow → memflow}/workflow/all.js +0 -0
- /package/build/services/{meshflow → memflow}/workflow/context.d.ts +0 -0
- /package/build/services/{meshflow → memflow}/workflow/context.js +0 -0
- /package/build/services/{meshflow → memflow}/workflow/didRun.d.ts +0 -0
- /package/build/services/{meshflow → memflow}/workflow/didRun.js +0 -0
- /package/build/services/{meshflow → memflow}/workflow/emit.d.ts +0 -0
- /package/build/services/{meshflow → memflow}/workflow/emit.js +0 -0
- /package/build/services/{meshflow → memflow}/workflow/enrich.d.ts +0 -0
- /package/build/services/{meshflow → memflow}/workflow/enrich.js +0 -0
- /package/build/services/{meshflow → memflow}/workflow/execChild.d.ts +0 -0
- /package/build/services/{meshflow → memflow}/workflow/hook.d.ts +0 -0
- /package/build/services/{meshflow → memflow}/workflow/interrupt.d.ts +0 -0
- /package/build/services/{meshflow → memflow}/workflow/interrupt.js +0 -0
- /package/build/services/{meshflow → memflow}/workflow/isSideEffectAllowed.d.ts +0 -0
- /package/build/services/{meshflow → memflow}/workflow/isSideEffectAllowed.js +0 -0
- /package/build/services/{meshflow → memflow}/workflow/random.d.ts +0 -0
- /package/build/services/{meshflow → memflow}/workflow/random.js +0 -0
- /package/build/services/{meshflow → memflow}/workflow/searchMethods.d.ts +0 -0
- /package/build/services/{meshflow → memflow}/workflow/searchMethods.js +0 -0
- /package/build/services/{meshflow → memflow}/workflow/signal.d.ts +0 -0
- /package/build/services/{meshflow → memflow}/workflow/signal.js +0 -0
- /package/build/services/{meshflow → memflow}/workflow/sleepFor.d.ts +0 -0
- /package/build/services/{meshflow → memflow}/workflow/trace.d.ts +0 -0
- /package/build/services/{meshflow → memflow}/workflow/trace.js +0 -0
- /package/build/services/{meshflow → memflow}/workflow/waitFor.d.ts +0 -0
- /package/build/types/{meshflow.js → memflow.js} +0 -0
|
@@ -1 +1,33 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SymbolHandler = void 0;
|
|
4
|
+
class SymbolHandler {
|
|
5
|
+
null() {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
undefined() {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
whitespace() {
|
|
12
|
+
return ' ';
|
|
13
|
+
}
|
|
14
|
+
object() {
|
|
15
|
+
return {};
|
|
16
|
+
}
|
|
17
|
+
array() {
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
posInfinity() {
|
|
21
|
+
return Infinity;
|
|
22
|
+
}
|
|
23
|
+
negInfinity() {
|
|
24
|
+
return -Infinity;
|
|
25
|
+
}
|
|
26
|
+
NaN() {
|
|
27
|
+
return NaN;
|
|
28
|
+
}
|
|
29
|
+
date() {
|
|
30
|
+
return new Date();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.SymbolHandler = SymbolHandler;
|
|
@@ -1 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UnaryHandler = void 0;
|
|
4
|
+
class UnaryHandler {
|
|
5
|
+
not(value) {
|
|
6
|
+
return !value;
|
|
7
|
+
}
|
|
8
|
+
positive(value) {
|
|
9
|
+
return +value;
|
|
10
|
+
}
|
|
11
|
+
negative(value) {
|
|
12
|
+
return -value;
|
|
13
|
+
}
|
|
14
|
+
bitwise_not(value) {
|
|
15
|
+
return ~value;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.UnaryHandler = UnaryHandler;
|
|
@@ -1 +1,242 @@
|
|
|
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.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
|
+
/**
|
|
37
|
+
* loop through each PipeItem row in this Pipe, resolving and transforming line by line
|
|
38
|
+
* @returns {any} the result of the pipe
|
|
39
|
+
*/
|
|
40
|
+
process(resolved = null) {
|
|
41
|
+
let index = 0;
|
|
42
|
+
if (!(resolved ||
|
|
43
|
+
this.isPipeType(this.rules[0]) ||
|
|
44
|
+
this.isreduceType(this.rules[0]))) {
|
|
45
|
+
resolved = this.processCells(this.rules[0]); // Add type assertion
|
|
46
|
+
index = 1;
|
|
47
|
+
}
|
|
48
|
+
const len = this.rules.length;
|
|
49
|
+
const subPipeQueue = [];
|
|
50
|
+
for (let i = index; i < len; i++) {
|
|
51
|
+
resolved = this.processRow(this.rules[i], resolved, subPipeQueue);
|
|
52
|
+
}
|
|
53
|
+
return resolved[0];
|
|
54
|
+
}
|
|
55
|
+
cloneUnknown(value) {
|
|
56
|
+
if (value === null || typeof value !== 'object') {
|
|
57
|
+
return value;
|
|
58
|
+
}
|
|
59
|
+
if (value instanceof Date) {
|
|
60
|
+
return new Date(value.getTime());
|
|
61
|
+
}
|
|
62
|
+
if (value instanceof RegExp) {
|
|
63
|
+
return new RegExp(value);
|
|
64
|
+
}
|
|
65
|
+
if (Array.isArray(value)) {
|
|
66
|
+
return value.map((item) => this.cloneUnknown(item));
|
|
67
|
+
}
|
|
68
|
+
const clonedObj = {};
|
|
69
|
+
for (const key in value) {
|
|
70
|
+
if (Object.prototype.hasOwnProperty.call(value, key)) {
|
|
71
|
+
clonedObj[key] = this.cloneUnknown(value[key]);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return clonedObj;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Transforms iterable `input` into a single value. Vars $output, $item, $key
|
|
78
|
+
* and $input are available. The final statement in the iterator (the reduction)
|
|
79
|
+
* is assumed to be the return value. A default $output object may be provided
|
|
80
|
+
* to the iterator by placing the the second cell of the preceding row. Otherwise,
|
|
81
|
+
* construct the object during first run and ensure it is the first cell of the
|
|
82
|
+
* last row of the iterator, so it is returned as the $output for the next cycle
|
|
83
|
+
* @param {unknown[]} input
|
|
84
|
+
* @returns {unknown}
|
|
85
|
+
* @private
|
|
86
|
+
*/
|
|
87
|
+
reduce(input) {
|
|
88
|
+
let resolved = this.cloneUnknown(input[1] ?? null);
|
|
89
|
+
if (Array.isArray(input[0])) {
|
|
90
|
+
for (let index = 0; index < input[0].length; index++) {
|
|
91
|
+
this.context = {
|
|
92
|
+
$input: input[0],
|
|
93
|
+
$output: resolved,
|
|
94
|
+
$item: input[0][index],
|
|
95
|
+
$key: index.toString(),
|
|
96
|
+
$index: index,
|
|
97
|
+
};
|
|
98
|
+
resolved = this.process([resolved]);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
let index = -1;
|
|
103
|
+
for (const $key in input[0]) {
|
|
104
|
+
index++;
|
|
105
|
+
this.context = {
|
|
106
|
+
$input: input[0],
|
|
107
|
+
$output: resolved,
|
|
108
|
+
$item: input[0][$key],
|
|
109
|
+
$key,
|
|
110
|
+
$index: index,
|
|
111
|
+
};
|
|
112
|
+
resolved = this.process([resolved]);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return [resolved];
|
|
116
|
+
}
|
|
117
|
+
processRow(currentRow, resolvedPriorRow, subPipeQueue) {
|
|
118
|
+
if (resolvedPriorRow && this.isreduceType(currentRow)) {
|
|
119
|
+
//reduce the resolvedPriorRow and return the output from the reducer
|
|
120
|
+
const subPipe = new Pipe(currentRow['@reduce'], this.jobData);
|
|
121
|
+
const reduced = subPipe.reduce(resolvedPriorRow);
|
|
122
|
+
return reduced;
|
|
123
|
+
}
|
|
124
|
+
else if (this.isPipeType(currentRow)) {
|
|
125
|
+
//process subPipe and push to subPipeQueue; echo resolvedPriorRow
|
|
126
|
+
const subPipe = new Pipe(currentRow['@pipe'], this.jobData, this.context);
|
|
127
|
+
subPipeQueue.push(subPipe.process());
|
|
128
|
+
return resolvedPriorRow;
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
//pivot the subPipeQueue into the arguments array (resolvedPriorRow)
|
|
132
|
+
if (subPipeQueue.length > 0) {
|
|
133
|
+
resolvedPriorRow = [...subPipeQueue];
|
|
134
|
+
subPipeQueue.length = 0;
|
|
135
|
+
}
|
|
136
|
+
if (!resolvedPriorRow) {
|
|
137
|
+
//if no prior row, use current row as prior row
|
|
138
|
+
return [].concat(this.processCells(Array.isArray(currentRow) ? [...currentRow] : []));
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
const [functionName, ...params] = currentRow; // Add type assertion
|
|
142
|
+
//use resolved values from prior row (n - 1) as input params to cell 1 function
|
|
143
|
+
let resolvedValue;
|
|
144
|
+
if (this.isContextVariable(functionName)) {
|
|
145
|
+
resolvedValue = this.resolveContextValue(functionName);
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
resolvedValue = Pipe.resolveFunction(functionName)(...resolvedPriorRow);
|
|
149
|
+
}
|
|
150
|
+
//resolve remaining cells in row and return concatenated with resolvedValue
|
|
151
|
+
return [resolvedValue].concat(this.processCells([...params]));
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
static resolveFunction(functionName) {
|
|
156
|
+
let [prefix, suffix] = functionName.split('.');
|
|
157
|
+
prefix = prefix.substring(2);
|
|
158
|
+
suffix = suffix.substring(0, suffix.length - 1);
|
|
159
|
+
const domain = functions_1.default[prefix];
|
|
160
|
+
if (!domain) {
|
|
161
|
+
throw new Error(`Unknown domain name [${functionName}]: ${prefix}`);
|
|
162
|
+
}
|
|
163
|
+
if (!domain[suffix]) {
|
|
164
|
+
throw new Error(`Unknown domain function [${functionName}]: ${prefix}.${suffix}`);
|
|
165
|
+
}
|
|
166
|
+
return domain[suffix];
|
|
167
|
+
}
|
|
168
|
+
processCells(cells) {
|
|
169
|
+
const resolved = [];
|
|
170
|
+
if (Array.isArray(cells)) {
|
|
171
|
+
for (const currentCell of cells) {
|
|
172
|
+
resolved.push(this.resolveCellValue(currentCell));
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return resolved;
|
|
176
|
+
}
|
|
177
|
+
isFunction(currentCell) {
|
|
178
|
+
return (typeof currentCell === 'string' &&
|
|
179
|
+
currentCell.startsWith('{@') &&
|
|
180
|
+
currentCell.endsWith('}'));
|
|
181
|
+
}
|
|
182
|
+
isContextVariable(currentCell) {
|
|
183
|
+
if (typeof currentCell === 'string' && currentCell.endsWith('}')) {
|
|
184
|
+
return (currentCell.startsWith('{$item') ||
|
|
185
|
+
currentCell.startsWith('{$key') ||
|
|
186
|
+
currentCell.startsWith('{$index') ||
|
|
187
|
+
currentCell.startsWith('{$input') ||
|
|
188
|
+
currentCell.startsWith('{$output'));
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
isMappable(currentCell) {
|
|
192
|
+
return (typeof currentCell === 'string' &&
|
|
193
|
+
currentCell.startsWith('{') &&
|
|
194
|
+
currentCell.endsWith('}'));
|
|
195
|
+
}
|
|
196
|
+
resolveCellValue(currentCell) {
|
|
197
|
+
if (this.isFunction(currentCell)) {
|
|
198
|
+
const fn = Pipe.resolveFunction(currentCell);
|
|
199
|
+
return fn.call();
|
|
200
|
+
}
|
|
201
|
+
else if (this.isContextVariable(currentCell)) {
|
|
202
|
+
return this.resolveContextValue(currentCell);
|
|
203
|
+
}
|
|
204
|
+
else if (this.isMappable(currentCell)) {
|
|
205
|
+
return this.resolveMappableValue(currentCell);
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
return currentCell;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
getNestedProperty(obj, path) {
|
|
212
|
+
const pathParts = path.split('.');
|
|
213
|
+
let current = obj;
|
|
214
|
+
for (const part of pathParts) {
|
|
215
|
+
if (current === null ||
|
|
216
|
+
typeof current !== 'object' ||
|
|
217
|
+
!current.hasOwnProperty(part)) {
|
|
218
|
+
return undefined;
|
|
219
|
+
}
|
|
220
|
+
current = current[part];
|
|
221
|
+
}
|
|
222
|
+
return current;
|
|
223
|
+
}
|
|
224
|
+
resolveMappableValue(currentCell) {
|
|
225
|
+
const term = this.resolveMapTerm(currentCell);
|
|
226
|
+
return this.getNestedProperty(this.jobData, term);
|
|
227
|
+
}
|
|
228
|
+
resolveContextValue(currentCell) {
|
|
229
|
+
const term = this.resolveContextTerm(currentCell);
|
|
230
|
+
return this.getNestedProperty(this.context, term);
|
|
231
|
+
}
|
|
232
|
+
resolveContextTerm(currentCell) {
|
|
233
|
+
return currentCell.substring(1, currentCell.length - 1);
|
|
234
|
+
}
|
|
235
|
+
resolveFunctionTerm(currentCell) {
|
|
236
|
+
return currentCell.substring(2, currentCell.length - 1);
|
|
237
|
+
}
|
|
238
|
+
resolveMapTerm(currentCell) {
|
|
239
|
+
return currentCell.substring(1, currentCell.length - 1);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
exports.Pipe = Pipe;
|
|
@@ -1 +1,263 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
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
|
+
/**
|
|
12
|
+
* @private
|
|
13
|
+
*/
|
|
14
|
+
constructor() {
|
|
15
|
+
this.profiles = [];
|
|
16
|
+
this.cacheMode = 'cache';
|
|
17
|
+
this.untilVersion = null;
|
|
18
|
+
this.quorum = null;
|
|
19
|
+
this.callbacks = [];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @private
|
|
23
|
+
*/
|
|
24
|
+
static async init(namespace, appId, guid, config, engine, logger) {
|
|
25
|
+
if (config.engine) {
|
|
26
|
+
const instance = new QuorumService();
|
|
27
|
+
instance.verifyQuorumFields(config);
|
|
28
|
+
instance.namespace = namespace;
|
|
29
|
+
instance.appId = appId;
|
|
30
|
+
instance.guid = guid;
|
|
31
|
+
instance.logger = logger;
|
|
32
|
+
instance.engine = engine;
|
|
33
|
+
await instance.initStoreChannel(config.engine.store);
|
|
34
|
+
await instance.initSubChannel(config.engine.sub, config.engine.pub ?? config.engine.store);
|
|
35
|
+
//general quorum subscription
|
|
36
|
+
await instance.subscribe.subscribe(hotmesh_1.KeyType.QUORUM, instance.subscriptionHandler(), appId);
|
|
37
|
+
//app-specific quorum subscription (used for pubsub one-time request/response)
|
|
38
|
+
await instance.subscribe.subscribe(hotmesh_1.KeyType.QUORUM, instance.subscriptionHandler(), appId, instance.guid);
|
|
39
|
+
instance.engine.processWebHooks();
|
|
40
|
+
instance.engine.processTimeHooks();
|
|
41
|
+
return instance;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* @private
|
|
46
|
+
*/
|
|
47
|
+
verifyQuorumFields(config) {
|
|
48
|
+
if (!(0, utils_1.identifyProvider)(config.engine.store) ||
|
|
49
|
+
!(0, utils_1.identifyProvider)(config.engine.sub)) {
|
|
50
|
+
throw new Error('quorum config must include `store` and `sub` fields.');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* @private
|
|
55
|
+
*/
|
|
56
|
+
async initStoreChannel(store) {
|
|
57
|
+
this.store = await factory_2.StoreServiceFactory.init(store, this.namespace, this.appId, this.logger);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* @private
|
|
61
|
+
*/
|
|
62
|
+
async initSubChannel(sub, store) {
|
|
63
|
+
this.subscribe = await factory_1.SubServiceFactory.init(sub, store, this.namespace, this.appId, this.guid, this.logger);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* @private
|
|
67
|
+
*/
|
|
68
|
+
subscriptionHandler() {
|
|
69
|
+
const self = this;
|
|
70
|
+
return async (topic, message) => {
|
|
71
|
+
self.logger.debug('quorum-event-received', { topic, type: message.type });
|
|
72
|
+
if (message.type === 'activate') {
|
|
73
|
+
self.engine.setCacheMode(message.cache_mode, message.until_version);
|
|
74
|
+
}
|
|
75
|
+
else if (message.type === 'ping') {
|
|
76
|
+
self.sayPong(self.appId, self.guid, message.originator, message.details);
|
|
77
|
+
}
|
|
78
|
+
else if (message.type === 'pong' && self.guid === message.originator) {
|
|
79
|
+
self.quorum = self.quorum + 1;
|
|
80
|
+
if (message.profile) {
|
|
81
|
+
self.profiles.push(message.profile);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
else if (message.type === 'throttle') {
|
|
85
|
+
self.engine.throttle(message.throttle);
|
|
86
|
+
}
|
|
87
|
+
else if (message.type === 'work') {
|
|
88
|
+
self.engine.processWebHooks();
|
|
89
|
+
}
|
|
90
|
+
else if (message.type === 'job') {
|
|
91
|
+
self.engine.routeToSubscribers(message.topic, message.job);
|
|
92
|
+
}
|
|
93
|
+
else if (message.type === 'cron') {
|
|
94
|
+
self.engine.processTimeHooks();
|
|
95
|
+
}
|
|
96
|
+
else if (message.type === 'rollcall') {
|
|
97
|
+
self.doRollCall(message);
|
|
98
|
+
}
|
|
99
|
+
//if there are any callbacks, call them
|
|
100
|
+
if (self.callbacks.length > 0) {
|
|
101
|
+
self.callbacks.forEach((cb) => cb(topic, message));
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* @private
|
|
107
|
+
*/
|
|
108
|
+
async sayPong(appId, guid, originator, details = false) {
|
|
109
|
+
let profile;
|
|
110
|
+
if (details) {
|
|
111
|
+
const stream = this.engine.store.mintKey(hotmesh_1.KeyType.STREAMS, {
|
|
112
|
+
appId: this.appId,
|
|
113
|
+
});
|
|
114
|
+
profile = {
|
|
115
|
+
engine_id: this.guid,
|
|
116
|
+
namespace: this.namespace,
|
|
117
|
+
app_id: this.appId,
|
|
118
|
+
stream,
|
|
119
|
+
counts: this.engine.router.counts,
|
|
120
|
+
timestamp: (0, utils_1.formatISODate)(new Date()),
|
|
121
|
+
inited: this.engine.inited,
|
|
122
|
+
throttle: this.engine.router.throttle,
|
|
123
|
+
reclaimDelay: this.engine.router.reclaimDelay,
|
|
124
|
+
reclaimCount: this.engine.router.reclaimCount,
|
|
125
|
+
system: await (0, utils_1.getSystemHealth)(),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
this.subscribe.publish(hotmesh_1.KeyType.QUORUM, {
|
|
129
|
+
type: 'pong',
|
|
130
|
+
guid,
|
|
131
|
+
originator,
|
|
132
|
+
profile,
|
|
133
|
+
}, appId);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* A quorum-wide command to request a quorum count.
|
|
137
|
+
* @private
|
|
138
|
+
*/
|
|
139
|
+
async requestQuorum(delay = enums_1.HMSH_QUORUM_DELAY_MS, details = false) {
|
|
140
|
+
const quorum = this.quorum;
|
|
141
|
+
this.quorum = 0;
|
|
142
|
+
this.profiles.length = 0;
|
|
143
|
+
await this.subscribe.publish(hotmesh_1.KeyType.QUORUM, {
|
|
144
|
+
type: 'ping',
|
|
145
|
+
originator: this.guid,
|
|
146
|
+
details,
|
|
147
|
+
}, this.appId);
|
|
148
|
+
await (0, utils_1.sleepFor)(delay);
|
|
149
|
+
return quorum;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* @private
|
|
153
|
+
*/
|
|
154
|
+
async doRollCall(message) {
|
|
155
|
+
let iteration = 0;
|
|
156
|
+
const max = !isNaN(message.max) ? message.max : enums_1.HMSH_QUORUM_ROLLCALL_CYCLES;
|
|
157
|
+
if (this.rollCallInterval)
|
|
158
|
+
clearTimeout(this.rollCallInterval);
|
|
159
|
+
const base = message.interval / 2;
|
|
160
|
+
const amount = base + Math.ceil(Math.random() * base);
|
|
161
|
+
do {
|
|
162
|
+
await (0, utils_1.sleepFor)(Math.ceil(Math.random() * 1000));
|
|
163
|
+
await this.sayPong(this.appId, this.guid, null, true);
|
|
164
|
+
if (!message.interval)
|
|
165
|
+
return;
|
|
166
|
+
const { promise, timerId } = (0, utils_1.XSleepFor)(amount * 1000);
|
|
167
|
+
this.rollCallInterval = timerId;
|
|
168
|
+
await promise;
|
|
169
|
+
} while (this.rollCallInterval && iteration++ < max - 1);
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* @private
|
|
173
|
+
*/
|
|
174
|
+
cancelRollCall() {
|
|
175
|
+
if (this.rollCallInterval) {
|
|
176
|
+
clearTimeout(this.rollCallInterval);
|
|
177
|
+
delete this.rollCallInterval;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* @private
|
|
182
|
+
*/
|
|
183
|
+
stop() {
|
|
184
|
+
this.cancelRollCall();
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* @private
|
|
188
|
+
*/
|
|
189
|
+
async pub(quorumMessage) {
|
|
190
|
+
return await this.subscribe.publish(hotmesh_1.KeyType.QUORUM, quorumMessage, this.appId, quorumMessage.topic || quorumMessage.guid);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* @private
|
|
194
|
+
*/
|
|
195
|
+
async sub(callback) {
|
|
196
|
+
this.callbacks.push(callback);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* @private
|
|
200
|
+
*/
|
|
201
|
+
async unsub(callback) {
|
|
202
|
+
this.callbacks = this.callbacks.filter((cb) => cb !== callback);
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* @private
|
|
206
|
+
*/
|
|
207
|
+
async rollCall(delay = enums_1.HMSH_QUORUM_DELAY_MS) {
|
|
208
|
+
await this.requestQuorum(delay, true);
|
|
209
|
+
const stream_depths = await this.engine.stream.getStreamDepths(this.profiles);
|
|
210
|
+
this.profiles.forEach(async (profile, index) => {
|
|
211
|
+
//if nothing in the table, the depth will be 0
|
|
212
|
+
//todo: separate table for every worker stream?
|
|
213
|
+
profile.stream_depth = stream_depths?.[index]?.depth ?? 0;
|
|
214
|
+
});
|
|
215
|
+
return this.profiles;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* @private
|
|
219
|
+
*/
|
|
220
|
+
async activate(version, delay = enums_1.HMSH_QUORUM_DELAY_MS, count = 0) {
|
|
221
|
+
version = version.toString();
|
|
222
|
+
const canActivate = await this.store.reserveScoutRole('activate', Math.ceil(delay * 6 / 1000) + 1);
|
|
223
|
+
if (!canActivate) {
|
|
224
|
+
//another engine is already activating the app version
|
|
225
|
+
this.logger.debug('quorum-activation-awaiting', { version });
|
|
226
|
+
await (0, utils_1.sleepFor)(delay * 6);
|
|
227
|
+
const app = await this.store.getApp(this.appId, true);
|
|
228
|
+
return app?.active == true && app?.version === version;
|
|
229
|
+
}
|
|
230
|
+
const config = await this.engine.getVID();
|
|
231
|
+
await this.requestQuorum(delay);
|
|
232
|
+
const q1 = await this.requestQuorum(delay);
|
|
233
|
+
const q2 = await this.requestQuorum(delay);
|
|
234
|
+
const q3 = await this.requestQuorum(delay);
|
|
235
|
+
if (q1 && q1 === q2 && q2 === q3) {
|
|
236
|
+
this.logger.info('quorum-rollcall-succeeded', { q1, q2, q3 });
|
|
237
|
+
this.subscribe.publish(hotmesh_1.KeyType.QUORUM, { type: 'activate', cache_mode: 'nocache', until_version: version }, this.appId);
|
|
238
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
239
|
+
await this.store.releaseScoutRole('activate');
|
|
240
|
+
//confirm we received the activation message
|
|
241
|
+
if (this.engine.untilVersion === version) {
|
|
242
|
+
this.logger.info('quorum-activation-succeeded', { version });
|
|
243
|
+
const { id } = config;
|
|
244
|
+
const compiler = new compiler_1.CompilerService(this.store, this.engine.stream, this.logger);
|
|
245
|
+
return await compiler.activate(id, version);
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
this.logger.error('quorum-activation-error', { version });
|
|
249
|
+
throw new Error(`UntilVersion Not Received. Version ${version} not activated`);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
this.logger.warn('quorum-rollcall-error', { q1, q2, q3, count });
|
|
254
|
+
this.store.releaseScoutRole('activate');
|
|
255
|
+
if (count < enums_1.HMSH_ACTIVATION_MAX_RETRY) {
|
|
256
|
+
//increase the delay (give the quorum time to respond) and try again
|
|
257
|
+
return await this.activate(version, delay * 2, count + 1);
|
|
258
|
+
}
|
|
259
|
+
throw new Error(`Quorum not reached. Version ${version} not activated.`);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
exports.QuorumService = QuorumService;
|