@hotmeshio/hotmesh 0.4.0 → 0.4.2
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 +39 -14
- package/build/modules/enums.d.ts +110 -0
- package/build/modules/enums.js +134 -0
- package/build/modules/errors.d.ts +124 -0
- package/build/modules/errors.js +191 -0
- package/build/modules/key.d.ts +66 -0
- package/build/modules/key.js +190 -0
- package/build/modules/storage.d.ts +3 -0
- package/build/modules/storage.js +5 -0
- package/build/modules/utils.d.ts +119 -0
- package/build/modules/utils.js +374 -0
- package/build/package.json +1 -1
- package/build/services/activities/activity.d.ts +104 -0
- package/build/services/activities/activity.js +549 -0
- package/build/services/activities/await.d.ts +12 -0
- package/build/services/activities/await.js +114 -0
- package/build/services/activities/cycle.d.ts +19 -0
- package/build/services/activities/cycle.js +112 -0
- package/build/services/activities/hook.d.ts +27 -0
- package/build/services/activities/hook.js +168 -0
- package/build/services/activities/index.d.ts +19 -0
- package/build/services/activities/index.js +20 -0
- package/build/services/activities/interrupt.d.ts +16 -0
- package/build/services/activities/interrupt.js +158 -0
- package/build/services/activities/signal.d.ts +20 -0
- package/build/services/activities/signal.js +134 -0
- package/build/services/activities/trigger.d.ts +37 -0
- package/build/services/activities/trigger.js +246 -0
- package/build/services/activities/worker.d.ts +12 -0
- package/build/services/activities/worker.js +106 -0
- package/build/services/collator/index.d.ts +111 -0
- package/build/services/collator/index.js +293 -0
- package/build/services/compiler/deployer.d.ts +40 -0
- package/build/services/compiler/deployer.js +488 -0
- package/build/services/compiler/index.d.ts +32 -0
- package/build/services/compiler/index.js +112 -0
- package/build/services/compiler/validator.d.ts +34 -0
- package/build/services/compiler/validator.js +147 -0
- package/build/services/connector/factory.d.ts +22 -0
- package/build/services/connector/factory.js +99 -0
- package/build/services/connector/index.d.ts +30 -0
- package/build/services/connector/index.js +54 -0
- package/build/services/connector/providers/ioredis.d.ts +9 -0
- package/build/services/connector/providers/ioredis.js +26 -0
- package/build/services/connector/providers/nats.d.ts +9 -0
- package/build/services/connector/providers/nats.js +34 -0
- package/build/services/connector/providers/postgres.d.ts +20 -0
- package/build/services/connector/providers/postgres.js +102 -0
- package/build/services/connector/providers/redis.d.ts +9 -0
- package/build/services/connector/providers/redis.js +38 -0
- package/build/services/engine/index.d.ts +264 -0
- package/build/services/engine/index.js +761 -0
- package/build/services/exporter/index.d.ts +44 -0
- package/build/services/exporter/index.js +126 -0
- package/build/services/hotmesh/index.d.ts +483 -0
- package/build/services/hotmesh/index.js +622 -0
- package/build/services/logger/index.d.ts +16 -0
- package/build/services/logger/index.js +54 -0
- package/build/services/mapper/index.d.ts +28 -0
- package/build/services/mapper/index.js +81 -0
- package/build/services/memflow/client.d.ts +108 -0
- package/build/services/memflow/client.js +372 -0
- package/build/services/memflow/connection.d.ts +23 -0
- package/build/services/memflow/connection.js +33 -0
- package/build/services/memflow/context.d.ts +143 -0
- package/build/services/memflow/context.js +299 -0
- package/build/services/memflow/exporter.d.ts +51 -0
- package/build/services/memflow/exporter.js +215 -0
- package/build/services/memflow/handle.d.ts +90 -0
- package/build/services/memflow/handle.js +176 -0
- package/build/services/memflow/index.d.ts +116 -0
- package/build/services/memflow/index.js +122 -0
- package/build/services/memflow/schemas/factory.d.ts +29 -0
- package/build/services/memflow/schemas/factory.js +2492 -0
- package/build/services/memflow/search.d.ts +142 -0
- package/build/services/memflow/search.js +320 -0
- package/build/services/memflow/worker.d.ts +124 -0
- package/build/services/memflow/worker.js +514 -0
- package/build/services/memflow/workflow/all.d.ts +7 -0
- package/build/services/memflow/workflow/all.js +15 -0
- package/build/services/memflow/workflow/common.d.ts +20 -0
- package/build/services/memflow/workflow/common.js +47 -0
- package/build/services/memflow/workflow/context.d.ts +6 -0
- package/build/services/memflow/workflow/context.js +45 -0
- package/build/services/memflow/workflow/contextMethods.d.ts +14 -0
- package/build/services/memflow/workflow/contextMethods.js +33 -0
- package/build/services/memflow/workflow/didRun.d.ts +7 -0
- package/build/services/memflow/workflow/didRun.js +22 -0
- package/build/services/memflow/workflow/emit.d.ts +11 -0
- package/build/services/memflow/workflow/emit.js +29 -0
- package/build/services/memflow/workflow/enrich.d.ts +9 -0
- package/build/services/memflow/workflow/enrich.js +17 -0
- package/build/services/memflow/workflow/execChild.d.ts +18 -0
- package/build/services/memflow/workflow/execChild.js +102 -0
- package/build/services/memflow/workflow/execHook.d.ts +65 -0
- package/build/services/memflow/workflow/execHook.js +73 -0
- package/build/services/memflow/workflow/hook.d.ts +9 -0
- package/build/services/memflow/workflow/hook.js +56 -0
- package/build/services/memflow/workflow/index.d.ts +74 -0
- package/build/services/memflow/workflow/index.js +87 -0
- package/build/services/memflow/workflow/interrupt.d.ts +9 -0
- package/build/services/memflow/workflow/interrupt.js +24 -0
- package/build/services/memflow/workflow/isSideEffectAllowed.d.ts +10 -0
- package/build/services/memflow/workflow/isSideEffectAllowed.js +33 -0
- package/build/services/memflow/workflow/proxyActivities.d.ts +20 -0
- package/build/services/memflow/workflow/proxyActivities.js +97 -0
- package/build/services/memflow/workflow/random.d.ts +6 -0
- package/build/services/memflow/workflow/random.js +16 -0
- package/build/services/memflow/workflow/searchMethods.d.ts +6 -0
- package/build/services/memflow/workflow/searchMethods.js +25 -0
- package/build/services/memflow/workflow/signal.d.ts +29 -0
- package/build/services/memflow/workflow/signal.js +50 -0
- package/build/services/memflow/workflow/sleepFor.d.ts +24 -0
- package/build/services/memflow/workflow/sleepFor.js +51 -0
- package/build/services/memflow/workflow/trace.d.ts +14 -0
- package/build/services/memflow/workflow/trace.js +33 -0
- package/build/services/memflow/workflow/waitFor.d.ts +29 -0
- package/build/services/memflow/workflow/waitFor.js +56 -0
- package/build/services/meshcall/index.d.ts +194 -0
- package/build/services/meshcall/index.js +452 -0
- package/build/services/meshcall/schemas/factory.d.ts +9 -0
- package/build/services/meshcall/schemas/factory.js +189 -0
- package/build/services/meshdata/index.d.ts +795 -0
- package/build/services/meshdata/index.js +1235 -0
- package/build/services/meshos/index.d.ts +293 -0
- package/build/services/meshos/index.js +547 -0
- package/build/services/pipe/functions/array.d.ts +17 -0
- package/build/services/pipe/functions/array.js +74 -0
- package/build/services/pipe/functions/bitwise.d.ts +9 -0
- package/build/services/pipe/functions/bitwise.js +24 -0
- package/build/services/pipe/functions/conditional.d.ts +13 -0
- package/build/services/pipe/functions/conditional.js +36 -0
- package/build/services/pipe/functions/cron.d.ts +12 -0
- package/build/services/pipe/functions/cron.js +40 -0
- package/build/services/pipe/functions/date.d.ts +58 -0
- package/build/services/pipe/functions/date.js +171 -0
- package/build/services/pipe/functions/index.d.ts +29 -0
- package/build/services/pipe/functions/index.js +30 -0
- package/build/services/pipe/functions/json.d.ts +5 -0
- package/build/services/pipe/functions/json.js +12 -0
- package/build/services/pipe/functions/logical.d.ts +5 -0
- package/build/services/pipe/functions/logical.js +12 -0
- package/build/services/pipe/functions/math.d.ts +42 -0
- package/build/services/pipe/functions/math.js +184 -0
- package/build/services/pipe/functions/number.d.ts +21 -0
- package/build/services/pipe/functions/number.js +60 -0
- package/build/services/pipe/functions/object.d.ts +25 -0
- package/build/services/pipe/functions/object.js +81 -0
- package/build/services/pipe/functions/string.d.ts +23 -0
- package/build/services/pipe/functions/string.js +69 -0
- package/build/services/pipe/functions/symbol.d.ts +12 -0
- package/build/services/pipe/functions/symbol.js +33 -0
- package/build/services/pipe/functions/unary.d.ts +7 -0
- package/build/services/pipe/functions/unary.js +18 -0
- package/build/services/pipe/index.d.ts +48 -0
- package/build/services/pipe/index.js +242 -0
- package/build/services/quorum/index.d.ts +90 -0
- package/build/services/quorum/index.js +263 -0
- package/build/services/reporter/index.d.ts +50 -0
- package/build/services/reporter/index.js +348 -0
- 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 +57 -0
- package/build/services/router/index.js +121 -0
- 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/factory.d.ts +7 -0
- package/build/services/search/factory.js +24 -0
- package/build/services/search/index.d.ts +23 -0
- package/build/services/search/index.js +10 -0
- package/build/services/search/providers/postgres/postgres.d.ts +25 -0
- package/build/services/search/providers/postgres/postgres.js +149 -0
- package/build/services/search/providers/redis/ioredis.d.ts +19 -0
- package/build/services/search/providers/redis/ioredis.js +121 -0
- package/build/services/search/providers/redis/redis.d.ts +19 -0
- package/build/services/search/providers/redis/redis.js +134 -0
- package/build/services/serializer/index.d.ts +42 -0
- package/build/services/serializer/index.js +282 -0
- package/build/services/store/cache.d.ts +67 -0
- package/build/services/store/cache.js +128 -0
- package/build/services/store/factory.d.ts +8 -0
- package/build/services/store/factory.js +24 -0
- package/build/services/store/index.d.ts +89 -0
- package/build/services/store/index.js +9 -0
- package/build/services/store/providers/postgres/kvsql.d.ts +168 -0
- package/build/services/store/providers/postgres/kvsql.js +198 -0
- package/build/services/store/providers/postgres/kvtables.d.ts +20 -0
- package/build/services/store/providers/postgres/kvtables.js +441 -0
- package/build/services/store/providers/postgres/kvtransaction.d.ts +36 -0
- package/build/services/store/providers/postgres/kvtransaction.js +248 -0
- package/build/services/store/providers/postgres/kvtypes/hash.d.ts +60 -0
- package/build/services/store/providers/postgres/kvtypes/hash.js +1287 -0
- package/build/services/store/providers/postgres/kvtypes/list.d.ts +33 -0
- package/build/services/store/providers/postgres/kvtypes/list.js +194 -0
- package/build/services/store/providers/postgres/kvtypes/string.d.ts +20 -0
- package/build/services/store/providers/postgres/kvtypes/string.js +115 -0
- package/build/services/store/providers/postgres/kvtypes/zset.d.ts +41 -0
- package/build/services/store/providers/postgres/kvtypes/zset.js +214 -0
- package/build/services/store/providers/postgres/postgres.d.ts +178 -0
- package/build/services/store/providers/postgres/postgres.js +1244 -0
- package/build/services/store/providers/redis/_base.d.ts +137 -0
- package/build/services/store/providers/redis/_base.js +980 -0
- package/build/services/store/providers/redis/ioredis.d.ts +20 -0
- package/build/services/store/providers/redis/ioredis.js +180 -0
- package/build/services/store/providers/redis/redis.d.ts +18 -0
- package/build/services/store/providers/redis/redis.js +199 -0
- package/build/services/store/providers/store-initializable.d.ts +5 -0
- package/build/services/store/providers/store-initializable.js +2 -0
- package/build/services/stream/factory.d.ts +8 -0
- package/build/services/stream/factory.js +37 -0
- package/build/services/stream/index.d.ts +69 -0
- package/build/services/stream/index.js +11 -0
- package/build/services/stream/providers/nats/nats.d.ts +60 -0
- package/build/services/stream/providers/nats/nats.js +225 -0
- package/build/services/stream/providers/postgres/kvtables.d.ts +3 -0
- package/build/services/stream/providers/postgres/kvtables.js +146 -0
- package/build/services/stream/providers/postgres/postgres.d.ts +107 -0
- package/build/services/stream/providers/postgres/postgres.js +519 -0
- package/build/services/stream/providers/redis/ioredis.d.ts +61 -0
- package/build/services/stream/providers/redis/ioredis.js +272 -0
- package/build/services/stream/providers/redis/redis.d.ts +61 -0
- package/build/services/stream/providers/redis/redis.js +305 -0
- package/build/services/stream/providers/stream-initializable.d.ts +4 -0
- package/build/services/stream/providers/stream-initializable.js +2 -0
- package/build/services/sub/factory.d.ts +7 -0
- package/build/services/sub/factory.js +29 -0
- package/build/services/sub/index.d.ts +22 -0
- package/build/services/sub/index.js +10 -0
- package/build/services/sub/providers/nats/nats.d.ts +19 -0
- package/build/services/sub/providers/nats/nats.js +105 -0
- package/build/services/sub/providers/postgres/postgres.d.ts +19 -0
- package/build/services/sub/providers/postgres/postgres.js +92 -0
- package/build/services/sub/providers/redis/ioredis.d.ts +17 -0
- package/build/services/sub/providers/redis/ioredis.js +81 -0
- package/build/services/sub/providers/redis/redis.d.ts +17 -0
- package/build/services/sub/providers/redis/redis.js +72 -0
- package/build/services/task/index.d.ts +48 -0
- package/build/services/task/index.js +253 -0
- package/build/services/telemetry/index.d.ts +52 -0
- package/build/services/telemetry/index.js +306 -0
- package/build/services/worker/index.d.ts +77 -0
- package/build/services/worker/index.js +197 -0
- package/package.json +1 -1
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- package/typedoc.json +0 -47
- 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/memflow.ts +0 -645
- package/types/meshcall.ts +0 -235
- package/types/meshdata.ts +0 -278
- package/types/ms.d.ts +0 -7
- package/types/nats.ts +0 -270
- package/types/pipe.ts +0 -90
- package/types/postgres.ts +0 -114
- 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 -231
- package/types/task.ts +0 -7
- package/types/telemetry.ts +0 -16
- package/types/transition.ts +0 -20
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExporterService = void 0;
|
|
4
|
+
const utils_1 = require("../../modules/utils");
|
|
5
|
+
const serializer_1 = require("../serializer");
|
|
6
|
+
class ExporterService {
|
|
7
|
+
constructor(appId, store, logger) {
|
|
8
|
+
this.appId = appId;
|
|
9
|
+
this.logger = logger;
|
|
10
|
+
this.store = store;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Convert the job hash from its compiles format into a MemFlowJobExport object with
|
|
14
|
+
* facets that describe the workflow in terms relevant to narrative storytelling.
|
|
15
|
+
*/
|
|
16
|
+
async export(jobId, options = {}) {
|
|
17
|
+
if (!ExporterService.symbols.has(this.appId)) {
|
|
18
|
+
const symbols = this.store.getAllSymbols();
|
|
19
|
+
ExporterService.symbols.set(this.appId, await symbols);
|
|
20
|
+
}
|
|
21
|
+
const jobData = await this.store.getRaw(jobId);
|
|
22
|
+
const jobExport = this.inflate(jobData, options);
|
|
23
|
+
return jobExport;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Inflates the job data from Redis into a MemFlowJobExport object
|
|
27
|
+
* @param jobHash - the job data from Redis
|
|
28
|
+
* @param dependencyList - the list of dependencies for the job
|
|
29
|
+
* @returns - the inflated job data
|
|
30
|
+
*/
|
|
31
|
+
inflate(jobHash, options) {
|
|
32
|
+
const timeline = [];
|
|
33
|
+
const state = {};
|
|
34
|
+
const data = {};
|
|
35
|
+
const transitionsObject = {};
|
|
36
|
+
const regex = /^([a-zA-Z]{3}),(\d+(?:,\d+)*)/;
|
|
37
|
+
Object.entries(jobHash).forEach(([key, value]) => {
|
|
38
|
+
const match = key.match(regex);
|
|
39
|
+
if (match) {
|
|
40
|
+
//transitions
|
|
41
|
+
this.inflateTransition(match, value, transitionsObject);
|
|
42
|
+
}
|
|
43
|
+
else if (key.startsWith('_')) {
|
|
44
|
+
//data
|
|
45
|
+
data[key.substring(1)] = value;
|
|
46
|
+
}
|
|
47
|
+
else if (key.startsWith('-')) {
|
|
48
|
+
//timeline
|
|
49
|
+
const keyParts = this.keyToObject(key);
|
|
50
|
+
timeline.push({
|
|
51
|
+
...keyParts,
|
|
52
|
+
key,
|
|
53
|
+
value: this.resolveValue(value, options.values),
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
else if (key.length === 3) {
|
|
57
|
+
//state
|
|
58
|
+
state[this.inflateKey(key)] = serializer_1.SerializerService.fromString(value);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
return this.filterFields({
|
|
62
|
+
data: (0, utils_1.restoreHierarchy)(data),
|
|
63
|
+
state: Object.entries((0, utils_1.restoreHierarchy)(state))[0][1],
|
|
64
|
+
status: parseInt(jobHash[':'], 10),
|
|
65
|
+
timeline: this.sortParts(timeline),
|
|
66
|
+
transitions: this.sortEntriesByCreated(transitionsObject),
|
|
67
|
+
}, options.block, options.allow);
|
|
68
|
+
}
|
|
69
|
+
resolveValue(raw, withValues) {
|
|
70
|
+
const resolved = serializer_1.SerializerService.fromString(raw);
|
|
71
|
+
if (withValues !== false) {
|
|
72
|
+
return resolved;
|
|
73
|
+
}
|
|
74
|
+
if (resolved && typeof resolved === 'object') {
|
|
75
|
+
if ('data' in resolved) {
|
|
76
|
+
resolved.data = {};
|
|
77
|
+
}
|
|
78
|
+
if ('$error' in resolved) {
|
|
79
|
+
resolved.$error = {};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return resolved;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Inflates the key from Redis, 3-character symbol
|
|
86
|
+
* into a human-readable JSON path, reflecting the
|
|
87
|
+
* tree-like structure of the unidimensional Hash
|
|
88
|
+
* @private
|
|
89
|
+
*/
|
|
90
|
+
inflateKey(key) {
|
|
91
|
+
const symbols = ExporterService.symbols.get(this.appId);
|
|
92
|
+
if (key in symbols) {
|
|
93
|
+
const path = symbols[key];
|
|
94
|
+
const parts = path.split('/');
|
|
95
|
+
return parts.join('/');
|
|
96
|
+
}
|
|
97
|
+
return key;
|
|
98
|
+
}
|
|
99
|
+
filterFields(fullObject, block = [], allow = []) {
|
|
100
|
+
let result = {};
|
|
101
|
+
if (allow && allow.length > 0) {
|
|
102
|
+
allow.forEach((field) => {
|
|
103
|
+
if (field in fullObject) {
|
|
104
|
+
result[field] = fullObject[field];
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
result = { ...fullObject };
|
|
110
|
+
}
|
|
111
|
+
if (block && block.length > 0) {
|
|
112
|
+
block.forEach((field) => {
|
|
113
|
+
if (field in result) {
|
|
114
|
+
delete result[field];
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
return result;
|
|
119
|
+
}
|
|
120
|
+
inflateTransition(match, value, transitionsObject) {
|
|
121
|
+
const [_, letters, dimensions] = match;
|
|
122
|
+
const path = this.inflateKey(letters);
|
|
123
|
+
const parts = path.split('/');
|
|
124
|
+
const activity = parts[0];
|
|
125
|
+
const isCreate = path.endsWith('/output/metadata/ac');
|
|
126
|
+
const isUpdate = path.endsWith('/output/metadata/au');
|
|
127
|
+
//for now only export activity start/stop; activity data would also be interesting
|
|
128
|
+
if (isCreate || isUpdate) {
|
|
129
|
+
const targetName = `${activity},${dimensions}`;
|
|
130
|
+
const target = transitionsObject[targetName];
|
|
131
|
+
if (!target) {
|
|
132
|
+
transitionsObject[targetName] = {
|
|
133
|
+
activity,
|
|
134
|
+
dimensions,
|
|
135
|
+
created: isCreate ? value : null,
|
|
136
|
+
updated: isUpdate ? value : null,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
target[isCreate ? 'created' : 'updated'] = value;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
sortEntriesByCreated(obj) {
|
|
145
|
+
const entriesArray = Object.values(obj);
|
|
146
|
+
entriesArray.sort((a, b) => {
|
|
147
|
+
return (a.created || a.updated).localeCompare(b.created || b.updated);
|
|
148
|
+
});
|
|
149
|
+
return entriesArray;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* marker names are overloaded with details like sequence, type, etc
|
|
153
|
+
*/
|
|
154
|
+
keyToObject(key) {
|
|
155
|
+
function extractDimension(label) {
|
|
156
|
+
const parts = label.split(',');
|
|
157
|
+
if (parts.length > 1) {
|
|
158
|
+
parts.shift();
|
|
159
|
+
return parts.join(',');
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
const parts = key.split('-');
|
|
163
|
+
if (parts.length === 4) {
|
|
164
|
+
//-proxy-5- -search-1-1-
|
|
165
|
+
return {
|
|
166
|
+
index: parseInt(parts[2], 10),
|
|
167
|
+
dimension: extractDimension(parts[1]),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
//-search,0,0-1-1- -proxy,0,0-1-
|
|
172
|
+
return {
|
|
173
|
+
index: parseInt(parts[2], 10),
|
|
174
|
+
secondary: parseInt(parts[3], 10),
|
|
175
|
+
dimension: extractDimension(parts[1]),
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* idem list has a complicated sort order based on indexes and dimensions
|
|
181
|
+
*/
|
|
182
|
+
sortParts(parts) {
|
|
183
|
+
return parts.sort((a, b) => {
|
|
184
|
+
const { dimension: aDim, index: aIdx, secondary: aSec } = a;
|
|
185
|
+
const { dimension: bDim, index: bIdx, secondary: bSec } = b;
|
|
186
|
+
if (aDim === undefined && bDim !== undefined)
|
|
187
|
+
return -1;
|
|
188
|
+
if (aDim !== undefined && bDim === undefined)
|
|
189
|
+
return 1;
|
|
190
|
+
if (aDim !== undefined && bDim !== undefined) {
|
|
191
|
+
if (aDim < bDim)
|
|
192
|
+
return -1;
|
|
193
|
+
if (aDim > bDim)
|
|
194
|
+
return 1;
|
|
195
|
+
}
|
|
196
|
+
if (aIdx < bIdx)
|
|
197
|
+
return -1;
|
|
198
|
+
if (aIdx > bIdx)
|
|
199
|
+
return 1;
|
|
200
|
+
if (aSec === undefined && bSec !== undefined)
|
|
201
|
+
return -1;
|
|
202
|
+
if (aSec !== undefined && bSec === undefined)
|
|
203
|
+
return 1;
|
|
204
|
+
if (aSec !== undefined && bSec !== undefined) {
|
|
205
|
+
if (aSec < bSec)
|
|
206
|
+
return -1;
|
|
207
|
+
if (aSec > bSec)
|
|
208
|
+
return 1;
|
|
209
|
+
}
|
|
210
|
+
return 0;
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
exports.ExporterService = ExporterService;
|
|
215
|
+
ExporterService.symbols = new Map();
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { HotMesh } from '../hotmesh';
|
|
2
|
+
import { MemFlowJobExport, ExportOptions } from '../../types/exporter';
|
|
3
|
+
import { JobInterruptOptions } from '../../types/job';
|
|
4
|
+
import { StreamError } from '../../types/stream';
|
|
5
|
+
import { ExporterService } from './exporter';
|
|
6
|
+
/**
|
|
7
|
+
* The WorkflowHandleService provides methods to interact with a running
|
|
8
|
+
* workflow. This includes exporting the workflow, sending signals, and
|
|
9
|
+
* querying the state of the workflow. It is instanced/accessed via the
|
|
10
|
+
* MemFlow.Client class.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { Client } from '@hotmeshio/hotmesh';
|
|
15
|
+
* import { Client as Postgres } from 'pg';
|
|
16
|
+
*
|
|
17
|
+
* const client = new Client({ connection: {
|
|
18
|
+
* class: Postgres,
|
|
19
|
+
* options: { connectionString: 'postgres://user:pass@localhost:5432/db' }
|
|
20
|
+
* }});
|
|
21
|
+
*
|
|
22
|
+
* const handle = await client.workflow.start({
|
|
23
|
+
* args: ['HotMesh'],
|
|
24
|
+
* taskQueue: 'hello-world',
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* //perform actions like send a signal
|
|
28
|
+
* await handle.signal('my-signal', { data: 'Hello' });
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare class WorkflowHandleService {
|
|
32
|
+
/**
|
|
33
|
+
* @private
|
|
34
|
+
*/
|
|
35
|
+
exporter: ExporterService;
|
|
36
|
+
hotMesh: HotMesh;
|
|
37
|
+
workflowTopic: string;
|
|
38
|
+
workflowId: string;
|
|
39
|
+
/**
|
|
40
|
+
* @private
|
|
41
|
+
*/
|
|
42
|
+
constructor(hotMesh: HotMesh, workflowTopic: string, workflowId: string);
|
|
43
|
+
/**
|
|
44
|
+
* Exports the workflow state to a JSON object.
|
|
45
|
+
*/
|
|
46
|
+
export(options?: ExportOptions): Promise<MemFlowJobExport>;
|
|
47
|
+
/**
|
|
48
|
+
* Sends a signal to the workflow. This is a way to send
|
|
49
|
+
* a message to a workflow that is paused due to having
|
|
50
|
+
* executed `MemFlow.workflow.waitFor`. The workflow
|
|
51
|
+
* will awaken if no other signals are pending.
|
|
52
|
+
*/
|
|
53
|
+
signal(signalId: string, data: Record<any, any>): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Returns the job state of the workflow. If the workflow has completed
|
|
56
|
+
* this is also the job output. If the workflow is still running, this
|
|
57
|
+
* is the current state of the job, but it may change depending upon
|
|
58
|
+
* the activities that remain.
|
|
59
|
+
*/
|
|
60
|
+
state(metadata?: boolean): Promise<Record<string, any>>;
|
|
61
|
+
/**
|
|
62
|
+
* Returns the current search state of the workflow. This is
|
|
63
|
+
* different than the job state or individual activity state.
|
|
64
|
+
* Search state represents name/value pairs that were added
|
|
65
|
+
* to the workflow.
|
|
66
|
+
*/
|
|
67
|
+
queryState(fields: string[]): Promise<Record<string, any>>;
|
|
68
|
+
/**
|
|
69
|
+
* Returns the current status of the workflow. This is a semaphore
|
|
70
|
+
* value that represents the current state of the workflow, where
|
|
71
|
+
* 0 is complete and a negative value represents that the flow was
|
|
72
|
+
* interrupted.
|
|
73
|
+
*/
|
|
74
|
+
status(): Promise<number>;
|
|
75
|
+
/**
|
|
76
|
+
* Interrupts a running workflow. Standard Job Completion tasks will
|
|
77
|
+
* run. Subscribers will be notified and the job hash will be expired.
|
|
78
|
+
*/
|
|
79
|
+
interrupt(options?: JobInterruptOptions): Promise<string>;
|
|
80
|
+
/**
|
|
81
|
+
* Waits for the workflow to complete and returns the result. If
|
|
82
|
+
* the workflow response includes an error, this method will rethrow
|
|
83
|
+
* the error, including the stack trace if available.
|
|
84
|
+
* Wrap calls in a try/catch as necessary to avoid unhandled exceptions.
|
|
85
|
+
*/
|
|
86
|
+
result<T>(config?: {
|
|
87
|
+
state?: boolean;
|
|
88
|
+
throwOnError?: boolean;
|
|
89
|
+
}): Promise<T | StreamError>;
|
|
90
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WorkflowHandleService = void 0;
|
|
4
|
+
const exporter_1 = require("./exporter");
|
|
5
|
+
/**
|
|
6
|
+
* The WorkflowHandleService provides methods to interact with a running
|
|
7
|
+
* workflow. This includes exporting the workflow, sending signals, and
|
|
8
|
+
* querying the state of the workflow. It is instanced/accessed via the
|
|
9
|
+
* MemFlow.Client class.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { Client } from '@hotmeshio/hotmesh';
|
|
14
|
+
* import { Client as Postgres } from 'pg';
|
|
15
|
+
*
|
|
16
|
+
* const client = new Client({ connection: {
|
|
17
|
+
* class: Postgres,
|
|
18
|
+
* options: { connectionString: 'postgres://user:pass@localhost:5432/db' }
|
|
19
|
+
* }});
|
|
20
|
+
*
|
|
21
|
+
* const handle = await client.workflow.start({
|
|
22
|
+
* args: ['HotMesh'],
|
|
23
|
+
* taskQueue: 'hello-world',
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* //perform actions like send a signal
|
|
27
|
+
* await handle.signal('my-signal', { data: 'Hello' });
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
class WorkflowHandleService {
|
|
31
|
+
/**
|
|
32
|
+
* @private
|
|
33
|
+
*/
|
|
34
|
+
constructor(hotMesh, workflowTopic, workflowId) {
|
|
35
|
+
this.workflowTopic = workflowTopic;
|
|
36
|
+
this.workflowId = workflowId;
|
|
37
|
+
this.hotMesh = hotMesh;
|
|
38
|
+
this.exporter = new exporter_1.ExporterService(this.hotMesh.appId, this.hotMesh.engine.store, this.hotMesh.engine.logger);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Exports the workflow state to a JSON object.
|
|
42
|
+
*/
|
|
43
|
+
async export(options) {
|
|
44
|
+
return this.exporter.export(this.workflowId, options);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Sends a signal to the workflow. This is a way to send
|
|
48
|
+
* a message to a workflow that is paused due to having
|
|
49
|
+
* executed `MemFlow.workflow.waitFor`. The workflow
|
|
50
|
+
* will awaken if no other signals are pending.
|
|
51
|
+
*/
|
|
52
|
+
async signal(signalId, data) {
|
|
53
|
+
await this.hotMesh.hook(`${this.hotMesh.appId}.wfs.signal`, {
|
|
54
|
+
id: signalId,
|
|
55
|
+
data,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Returns the job state of the workflow. If the workflow has completed
|
|
60
|
+
* this is also the job output. If the workflow is still running, this
|
|
61
|
+
* is the current state of the job, but it may change depending upon
|
|
62
|
+
* the activities that remain.
|
|
63
|
+
*/
|
|
64
|
+
async state(metadata = false) {
|
|
65
|
+
const state = await this.hotMesh.getState(`${this.hotMesh.appId}.execute`, this.workflowId);
|
|
66
|
+
if (!state.data && state.metadata.err) {
|
|
67
|
+
throw new Error(JSON.parse(state.metadata.err));
|
|
68
|
+
}
|
|
69
|
+
return metadata ? state : state.data;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Returns the current search state of the workflow. This is
|
|
73
|
+
* different than the job state or individual activity state.
|
|
74
|
+
* Search state represents name/value pairs that were added
|
|
75
|
+
* to the workflow.
|
|
76
|
+
*/
|
|
77
|
+
async queryState(fields) {
|
|
78
|
+
return await this.hotMesh.getQueryState(this.workflowId, fields);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Returns the current status of the workflow. This is a semaphore
|
|
82
|
+
* value that represents the current state of the workflow, where
|
|
83
|
+
* 0 is complete and a negative value represents that the flow was
|
|
84
|
+
* interrupted.
|
|
85
|
+
*/
|
|
86
|
+
async status() {
|
|
87
|
+
return await this.hotMesh.getStatus(this.workflowId);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Interrupts a running workflow. Standard Job Completion tasks will
|
|
91
|
+
* run. Subscribers will be notified and the job hash will be expired.
|
|
92
|
+
*/
|
|
93
|
+
async interrupt(options) {
|
|
94
|
+
return await this.hotMesh.interrupt(`${this.hotMesh.appId}.execute`, this.workflowId, options);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Waits for the workflow to complete and returns the result. If
|
|
98
|
+
* the workflow response includes an error, this method will rethrow
|
|
99
|
+
* the error, including the stack trace if available.
|
|
100
|
+
* Wrap calls in a try/catch as necessary to avoid unhandled exceptions.
|
|
101
|
+
*/
|
|
102
|
+
async result(config) {
|
|
103
|
+
const topic = `${this.hotMesh.appId}.executed.${this.workflowId}`;
|
|
104
|
+
let isResolved = false;
|
|
105
|
+
return new Promise(async (resolve, reject) => {
|
|
106
|
+
/**
|
|
107
|
+
* rejects/resolves the promise based on the `throwOnError`
|
|
108
|
+
* default behavior is to throw if error
|
|
109
|
+
*/
|
|
110
|
+
const safeReject = (err) => {
|
|
111
|
+
if (config?.throwOnError === false) {
|
|
112
|
+
return resolve(err);
|
|
113
|
+
}
|
|
114
|
+
reject(err);
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Common completion function that unsubscribes from the topic/returns
|
|
118
|
+
*/
|
|
119
|
+
const complete = async (response, err) => {
|
|
120
|
+
if (isResolved)
|
|
121
|
+
return;
|
|
122
|
+
isResolved = true;
|
|
123
|
+
if (err) {
|
|
124
|
+
return safeReject(err);
|
|
125
|
+
}
|
|
126
|
+
else if (!response) {
|
|
127
|
+
const state = await this.hotMesh.getState(`${this.hotMesh.appId}.execute`, this.workflowId);
|
|
128
|
+
if (state.data?.done && !state.data?.$error) {
|
|
129
|
+
return resolve(state.data.response);
|
|
130
|
+
}
|
|
131
|
+
else if (state.data?.$error) {
|
|
132
|
+
return safeReject(state.data.$error);
|
|
133
|
+
}
|
|
134
|
+
else if (state.metadata.err) {
|
|
135
|
+
return safeReject(JSON.parse(state.metadata.err));
|
|
136
|
+
}
|
|
137
|
+
response = state.data?.response;
|
|
138
|
+
}
|
|
139
|
+
resolve(response);
|
|
140
|
+
};
|
|
141
|
+
//more expensive; fetches the entire job, not just the `status`
|
|
142
|
+
if (config?.state) {
|
|
143
|
+
const state = await this.hotMesh.getState(`${this.hotMesh.appId}.execute`, this.workflowId);
|
|
144
|
+
if (state?.data?.done && !state.data?.$error) {
|
|
145
|
+
return complete(state.data.response);
|
|
146
|
+
}
|
|
147
|
+
else if (state.data?.$error) {
|
|
148
|
+
return complete(null, state.data.$error);
|
|
149
|
+
}
|
|
150
|
+
else if (state.metadata.err) {
|
|
151
|
+
return complete(null, JSON.parse(state.metadata.err));
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
//subscribe to 'done' topic
|
|
155
|
+
this.hotMesh.sub(topic, async (_topic, state) => {
|
|
156
|
+
this.hotMesh.unsub(topic);
|
|
157
|
+
if (state.data.done && !state.data?.$error) {
|
|
158
|
+
await complete(state.data?.response);
|
|
159
|
+
}
|
|
160
|
+
else if (state.data?.$error) {
|
|
161
|
+
return complete(null, state.data.$error);
|
|
162
|
+
}
|
|
163
|
+
else if (state.metadata.err) {
|
|
164
|
+
const error = JSON.parse(state.metadata.err);
|
|
165
|
+
return await complete(null, error);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
//check state in case completed during wiring
|
|
169
|
+
const status = await this.hotMesh.getStatus(this.workflowId);
|
|
170
|
+
if (status <= 0) {
|
|
171
|
+
await complete();
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
exports.WorkflowHandleService = WorkflowHandleService;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { ContextType } from '../../types/memflow';
|
|
2
|
+
import { ClientService } from './client';
|
|
3
|
+
import { ConnectionService } from './connection';
|
|
4
|
+
import { Search } from './search';
|
|
5
|
+
import { Context } from './context';
|
|
6
|
+
import { WorkerService } from './worker';
|
|
7
|
+
import { WorkflowService } from './workflow';
|
|
8
|
+
import { WorkflowHandleService } from './handle';
|
|
9
|
+
/**
|
|
10
|
+
* The MemFlow service is a collection of services that
|
|
11
|
+
* emulate Temporal's capabilities, but instead are
|
|
12
|
+
* backed by Postgres or Redis/ValKey. The following lifecycle example
|
|
13
|
+
* demonstrates how to start a new workflow, subscribe
|
|
14
|
+
* to the result, and shutdown the system.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { Client, Worker, MemFlow, HotMesh } from '@hotmeshio/hotmesh';
|
|
19
|
+
* import { Client as Postgres} from 'pg';
|
|
20
|
+
* import * as workflows from './workflows';
|
|
21
|
+
*
|
|
22
|
+
* //1) Initialize the worker
|
|
23
|
+
* await Worker.create({
|
|
24
|
+
* connection: {
|
|
25
|
+
* class: Postgres,
|
|
26
|
+
* options: {
|
|
27
|
+
* connectionString: 'postgresql://usr:pwd@localhost:5432/db',
|
|
28
|
+
* }
|
|
29
|
+
* }
|
|
30
|
+
* taskQueue: 'default',
|
|
31
|
+
* namespace: 'memflow',
|
|
32
|
+
* workflow: workflows.example,
|
|
33
|
+
* options: {
|
|
34
|
+
* backoffCoefficient: 2,
|
|
35
|
+
* maximumAttempts: 1_000,
|
|
36
|
+
* maximumInterval: '5 seconds'
|
|
37
|
+
* }
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* //2) initialize the client
|
|
41
|
+
* const client = new Client({
|
|
42
|
+
* connection: {
|
|
43
|
+
* class: Postgres,
|
|
44
|
+
* options: {
|
|
45
|
+
* connectionString: 'postgresql://usr:pwd@localhost:5432/db',
|
|
46
|
+
* }
|
|
47
|
+
* }
|
|
48
|
+
* });
|
|
49
|
+
*
|
|
50
|
+
* //3) start a new workflow
|
|
51
|
+
* const handle = await client.workflow.start({
|
|
52
|
+
* args: ['HotMesh', 'es'],
|
|
53
|
+
* taskQueue: 'default',
|
|
54
|
+
* workflowName: 'example',
|
|
55
|
+
* workflowId: HotMesh.guid(),
|
|
56
|
+
* namespace: 'memflow',
|
|
57
|
+
* });
|
|
58
|
+
*
|
|
59
|
+
* //4) subscribe to the eventual result
|
|
60
|
+
* console.log('\nRESPONSE', await handle.result(), '\n');
|
|
61
|
+
* //logs '¡Hola, HotMesh!'
|
|
62
|
+
*
|
|
63
|
+
* //5) Shutdown (typically on sigint)
|
|
64
|
+
* await MemFlow.shutdown();
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
declare class MemFlowClass {
|
|
68
|
+
/**
|
|
69
|
+
* @private
|
|
70
|
+
*/
|
|
71
|
+
constructor();
|
|
72
|
+
/**
|
|
73
|
+
* The MemFlow `Client` service is functionally
|
|
74
|
+
* equivalent to the Temporal `Client` service.
|
|
75
|
+
*/
|
|
76
|
+
static Client: typeof ClientService;
|
|
77
|
+
/**
|
|
78
|
+
* The MemFlow `Connection` service is functionally
|
|
79
|
+
* equivalent to the Temporal `Connection` service.
|
|
80
|
+
*/
|
|
81
|
+
static Connection: typeof ConnectionService;
|
|
82
|
+
/**
|
|
83
|
+
* @private
|
|
84
|
+
*/
|
|
85
|
+
static Search: typeof Search;
|
|
86
|
+
/**
|
|
87
|
+
* @private
|
|
88
|
+
*/
|
|
89
|
+
static Context: typeof Context;
|
|
90
|
+
/**
|
|
91
|
+
* The Handle provides methods to interact with a running
|
|
92
|
+
* workflow. This includes exporting the workflow, sending signals, and
|
|
93
|
+
* querying the state of the workflow. An instance of the Handle service
|
|
94
|
+
* is typically accessed via the MemFlow.Client class (workflow.getHandle).
|
|
95
|
+
*/
|
|
96
|
+
static Handle: typeof WorkflowHandleService;
|
|
97
|
+
/**
|
|
98
|
+
* The MemFlow `Worker` service is functionally
|
|
99
|
+
* equivalent to the Temporal `Worker` service.
|
|
100
|
+
*/
|
|
101
|
+
static Worker: typeof WorkerService;
|
|
102
|
+
/**
|
|
103
|
+
* The MemFlow `workflow` service is functionally
|
|
104
|
+
* equivalent to the Temporal `Workflow` service
|
|
105
|
+
* with additional methods for managing workflows,
|
|
106
|
+
* including: `execChild`, `waitFor`, `sleep`, etc
|
|
107
|
+
*/
|
|
108
|
+
static workflow: typeof WorkflowService;
|
|
109
|
+
/**
|
|
110
|
+
* Shutdown everything. All connections, workers, and clients will be closed.
|
|
111
|
+
* Include in your signal handlers to ensure a clean shutdown.
|
|
112
|
+
*/
|
|
113
|
+
static shutdown(): Promise<void>;
|
|
114
|
+
}
|
|
115
|
+
export { MemFlowClass as MemFlow };
|
|
116
|
+
export type { ContextType };
|