@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,28 @@
|
|
|
1
|
+
import { JobState } from '../../types/job';
|
|
2
|
+
import { TransitionRule } from '../../types/transition';
|
|
3
|
+
import { StreamCode } from '../../types';
|
|
4
|
+
declare class MapperService {
|
|
5
|
+
private rules;
|
|
6
|
+
private data;
|
|
7
|
+
constructor(rules: Record<string, unknown>, data: JobState);
|
|
8
|
+
mapRules(): Record<string, unknown>;
|
|
9
|
+
private traverseRules;
|
|
10
|
+
/**
|
|
11
|
+
* resolves a pipe expression of the form: { @pipe: [["{data.foo.bar}", 2, false, "hello world"]] }
|
|
12
|
+
* @param value
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
private pipe;
|
|
16
|
+
/**
|
|
17
|
+
* resolves a mapping expression in the form: "{data.foo.bar}" or 2 or false or "hello world"
|
|
18
|
+
* @param value
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
private resolve;
|
|
22
|
+
/**
|
|
23
|
+
* Evaluates a transition rule against the current job state and incoming Stream message
|
|
24
|
+
* to determine which (if any) transition should be taken.
|
|
25
|
+
*/
|
|
26
|
+
static evaluate(transitionRule: TransitionRule | boolean, context: JobState, code: StreamCode): boolean;
|
|
27
|
+
}
|
|
28
|
+
export { MapperService };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MapperService = void 0;
|
|
4
|
+
const pipe_1 = require("../pipe");
|
|
5
|
+
class MapperService {
|
|
6
|
+
constructor(rules, data) {
|
|
7
|
+
this.rules = rules;
|
|
8
|
+
this.data = data;
|
|
9
|
+
}
|
|
10
|
+
mapRules() {
|
|
11
|
+
return this.traverseRules(this.rules);
|
|
12
|
+
}
|
|
13
|
+
traverseRules(rules) {
|
|
14
|
+
if (typeof rules === 'object' && '@pipe' in rules) {
|
|
15
|
+
return this.pipe(rules['@pipe']);
|
|
16
|
+
}
|
|
17
|
+
if (typeof rules === 'object' && rules !== null) {
|
|
18
|
+
const mappedRules = {};
|
|
19
|
+
for (const key in rules) {
|
|
20
|
+
if (Object.prototype.hasOwnProperty.call(rules, key)) {
|
|
21
|
+
mappedRules[key] = this.traverseRules(rules[key]);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return mappedRules;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
return this.resolve(rules);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* resolves a pipe expression of the form: { @pipe: [["{data.foo.bar}", 2, false, "hello world"]] }
|
|
32
|
+
* @param value
|
|
33
|
+
* @returns
|
|
34
|
+
*/
|
|
35
|
+
pipe(value) {
|
|
36
|
+
const pipe = new pipe_1.Pipe(value, this.data);
|
|
37
|
+
return pipe.process();
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* resolves a mapping expression in the form: "{data.foo.bar}" or 2 or false or "hello world"
|
|
41
|
+
* @param value
|
|
42
|
+
* @returns
|
|
43
|
+
*/
|
|
44
|
+
resolve(value) {
|
|
45
|
+
const pipe = new pipe_1.Pipe([[value]], this.data);
|
|
46
|
+
return pipe.process();
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Evaluates a transition rule against the current job state and incoming Stream message
|
|
50
|
+
* to determine which (if any) transition should be taken.
|
|
51
|
+
*/
|
|
52
|
+
static evaluate(transitionRule, context, code) {
|
|
53
|
+
if (typeof transitionRule === 'boolean') {
|
|
54
|
+
return transitionRule;
|
|
55
|
+
}
|
|
56
|
+
if ((Array.isArray(transitionRule.code) &&
|
|
57
|
+
transitionRule.code.includes(code || 200)) ||
|
|
58
|
+
code.toString() === (transitionRule.code || 200).toString()) {
|
|
59
|
+
if (!transitionRule.match) {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
const orGate = transitionRule.gate === 'or';
|
|
63
|
+
let allAreTrue = true;
|
|
64
|
+
let someAreTrue = false;
|
|
65
|
+
transitionRule.match.forEach(({ expected, actual }) => {
|
|
66
|
+
if ((orGate && !someAreTrue) || (!orGate && allAreTrue)) {
|
|
67
|
+
const result = pipe_1.Pipe.resolve(actual, context) === expected;
|
|
68
|
+
if (orGate && result) {
|
|
69
|
+
someAreTrue = true;
|
|
70
|
+
}
|
|
71
|
+
else if (!orGate && !result) {
|
|
72
|
+
allAreTrue = false;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
return orGate ? someAreTrue : allAreTrue;
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.MapperService = MapperService;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { HotMesh } from '../hotmesh';
|
|
2
|
+
import { ClientConfig, ClientWorkflow, Connection, WorkflowOptions } from '../../types/memflow';
|
|
3
|
+
/**
|
|
4
|
+
* The MemFlow `Client` service is functionally
|
|
5
|
+
* equivalent to the Temporal `Client` service.
|
|
6
|
+
* Start a new workflow execution by calling
|
|
7
|
+
* `workflow.start`. Note the direct connection to
|
|
8
|
+
* Postgres.
|
|
9
|
+
*
|
|
10
|
+
* NATS can be used as the message broker if advanced
|
|
11
|
+
* messaging is required (i.e, patterned subscriptions).
|
|
12
|
+
* @example
|
|
13
|
+
|
|
14
|
+
* ```typescript
|
|
15
|
+
* //client.ts
|
|
16
|
+
* import { Client, HotMesh } from '@hotmeshio/hotmesh';
|
|
17
|
+
* import { Client as Postgres } from 'pg';
|
|
18
|
+
|
|
19
|
+
* async function run(): Promise<string> {
|
|
20
|
+
* const client = new Client({
|
|
21
|
+
* connection: {
|
|
22
|
+
* class: Postgres,
|
|
23
|
+
* options: { connectionString: 'postgresql://usr:pwd@localhost:5432/db' }
|
|
24
|
+
* }
|
|
25
|
+
* });
|
|
26
|
+
|
|
27
|
+
* const handle = await client.workflow.start({
|
|
28
|
+
* args: ['HotMesh'],
|
|
29
|
+
* taskQueue: 'default',
|
|
30
|
+
* workflowName: 'example',
|
|
31
|
+
* workflowId: HotMesh.guid()
|
|
32
|
+
* });
|
|
33
|
+
|
|
34
|
+
* return await handle.result();
|
|
35
|
+
* //returns ['Hello HotMesh', '¡Hola, HotMesh!']
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare class ClientService {
|
|
40
|
+
/**
|
|
41
|
+
* @private
|
|
42
|
+
*/
|
|
43
|
+
connection: Connection;
|
|
44
|
+
/**
|
|
45
|
+
* @private
|
|
46
|
+
*/
|
|
47
|
+
options: WorkflowOptions;
|
|
48
|
+
/**
|
|
49
|
+
* @private
|
|
50
|
+
*/
|
|
51
|
+
static topics: string[];
|
|
52
|
+
/**
|
|
53
|
+
* @private
|
|
54
|
+
*/
|
|
55
|
+
static instances: Map<string, HotMesh | Promise<HotMesh>>;
|
|
56
|
+
/**
|
|
57
|
+
* @private
|
|
58
|
+
*/
|
|
59
|
+
constructor(config: ClientConfig);
|
|
60
|
+
/**
|
|
61
|
+
* @private
|
|
62
|
+
*/
|
|
63
|
+
getHotMeshClient: (workflowTopic: string | null, namespace?: string) => Promise<HotMesh>;
|
|
64
|
+
/**
|
|
65
|
+
* Creates a stream where messages can be published to ensure there is a
|
|
66
|
+
* channel in place when the message arrives (a race condition for those
|
|
67
|
+
* platforms without implicit topic setup).
|
|
68
|
+
* @private
|
|
69
|
+
*/
|
|
70
|
+
static createStream: (hotMeshClient: HotMesh, workflowTopic: string, namespace?: string) => Promise<void>;
|
|
71
|
+
hashOptions(): string;
|
|
72
|
+
/**
|
|
73
|
+
* It is possible for a client to invoke a workflow without first
|
|
74
|
+
* creating the stream. This method will verify that the stream
|
|
75
|
+
* exists and if not, create it.
|
|
76
|
+
* @private
|
|
77
|
+
*/
|
|
78
|
+
verifyStream: (hotMeshClient: HotMesh, workflowTopic: string, namespace?: string) => Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* @private
|
|
81
|
+
*/
|
|
82
|
+
search: (hotMeshClient: HotMesh, index: string, query: string[]) => Promise<string[]>;
|
|
83
|
+
/**
|
|
84
|
+
* The MemFlow `Client` service is functionally
|
|
85
|
+
* equivalent to the Temporal `Client` service.
|
|
86
|
+
* Starting a workflow is the primary use case and
|
|
87
|
+
* is accessed by calling workflow.start().
|
|
88
|
+
*/
|
|
89
|
+
workflow: ClientWorkflow;
|
|
90
|
+
/**
|
|
91
|
+
* Any router can be used to deploy and activate the HotMesh
|
|
92
|
+
* distributed executable to the active quorum EXCEPT for
|
|
93
|
+
* those routers in `readonly` mode.
|
|
94
|
+
*/
|
|
95
|
+
deployAndActivate(namespace?: string, version?: string): Promise<void>;
|
|
96
|
+
/**
|
|
97
|
+
* @private
|
|
98
|
+
*/
|
|
99
|
+
verifyWorkflowActive(hotMesh: HotMesh, appId?: string, count?: number): Promise<boolean>;
|
|
100
|
+
/**
|
|
101
|
+
* @private
|
|
102
|
+
*/
|
|
103
|
+
activateWorkflow(hotMesh: HotMesh, appId?: string, version?: string): Promise<void>;
|
|
104
|
+
/**
|
|
105
|
+
* @private
|
|
106
|
+
*/
|
|
107
|
+
static shutdown(): Promise<void>;
|
|
108
|
+
}
|
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.ClientService = void 0;
|
|
5
|
+
const enums_1 = require("../../modules/enums");
|
|
6
|
+
const utils_1 = require("../../modules/utils");
|
|
7
|
+
const hotmesh_1 = require("../hotmesh");
|
|
8
|
+
const key_1 = require("../../modules/key");
|
|
9
|
+
const types_1 = require("../../types");
|
|
10
|
+
const search_1 = require("./search");
|
|
11
|
+
const handle_1 = require("./handle");
|
|
12
|
+
const factory_1 = require("./schemas/factory");
|
|
13
|
+
/**
|
|
14
|
+
* The MemFlow `Client` service is functionally
|
|
15
|
+
* equivalent to the Temporal `Client` service.
|
|
16
|
+
* Start a new workflow execution by calling
|
|
17
|
+
* `workflow.start`. Note the direct connection to
|
|
18
|
+
* Postgres.
|
|
19
|
+
*
|
|
20
|
+
* NATS can be used as the message broker if advanced
|
|
21
|
+
* messaging is required (i.e, patterned subscriptions).
|
|
22
|
+
* @example
|
|
23
|
+
|
|
24
|
+
* ```typescript
|
|
25
|
+
* //client.ts
|
|
26
|
+
* import { Client, HotMesh } from '@hotmeshio/hotmesh';
|
|
27
|
+
* import { Client as Postgres } from 'pg';
|
|
28
|
+
|
|
29
|
+
* async function run(): Promise<string> {
|
|
30
|
+
* const client = new Client({
|
|
31
|
+
* connection: {
|
|
32
|
+
* class: Postgres,
|
|
33
|
+
* options: { connectionString: 'postgresql://usr:pwd@localhost:5432/db' }
|
|
34
|
+
* }
|
|
35
|
+
* });
|
|
36
|
+
|
|
37
|
+
* const handle = await client.workflow.start({
|
|
38
|
+
* args: ['HotMesh'],
|
|
39
|
+
* taskQueue: 'default',
|
|
40
|
+
* workflowName: 'example',
|
|
41
|
+
* workflowId: HotMesh.guid()
|
|
42
|
+
* });
|
|
43
|
+
|
|
44
|
+
* return await handle.result();
|
|
45
|
+
* //returns ['Hello HotMesh', '¡Hola, HotMesh!']
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
class ClientService {
|
|
50
|
+
/**
|
|
51
|
+
* @private
|
|
52
|
+
*/
|
|
53
|
+
constructor(config) {
|
|
54
|
+
/**
|
|
55
|
+
* @private
|
|
56
|
+
*/
|
|
57
|
+
this.getHotMeshClient = async (workflowTopic, namespace) => {
|
|
58
|
+
//namespace isolation requires the connection options to be hashed
|
|
59
|
+
//as multiple intersecting databases can be used by the same service
|
|
60
|
+
//hashing options allows for reuse of the same connection without risk of
|
|
61
|
+
//overwriting data in another namespace.
|
|
62
|
+
const optionsHash = this.hashOptions();
|
|
63
|
+
const targetNS = namespace ?? factory_1.APP_ID;
|
|
64
|
+
const connectionNS = `${optionsHash}.${targetNS}`;
|
|
65
|
+
if (ClientService.instances.has(connectionNS)) {
|
|
66
|
+
const hotMeshClient = await ClientService.instances.get(connectionNS);
|
|
67
|
+
await this.verifyWorkflowActive(hotMeshClient, targetNS);
|
|
68
|
+
return hotMeshClient;
|
|
69
|
+
}
|
|
70
|
+
//init, but don't await
|
|
71
|
+
const readonly = this.connection.readonly ?? undefined;
|
|
72
|
+
let hotMeshClient = hotmesh_1.HotMesh.init({
|
|
73
|
+
appId: targetNS,
|
|
74
|
+
logLevel: enums_1.HMSH_LOGLEVEL,
|
|
75
|
+
engine: {
|
|
76
|
+
readonly,
|
|
77
|
+
connection: this.connection,
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
//synchronously cache the promise (before awaiting)
|
|
81
|
+
ClientService.instances.set(connectionNS, hotMeshClient);
|
|
82
|
+
//resolve, activate, and return the client
|
|
83
|
+
const resolvedClient = await hotMeshClient;
|
|
84
|
+
if (!readonly) {
|
|
85
|
+
resolvedClient.engine.logger.info('memflow-readonly-client', {
|
|
86
|
+
guid: resolvedClient.engine.guid,
|
|
87
|
+
appId: targetNS,
|
|
88
|
+
});
|
|
89
|
+
await this.activateWorkflow(resolvedClient, targetNS);
|
|
90
|
+
}
|
|
91
|
+
return resolvedClient;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* It is possible for a client to invoke a workflow without first
|
|
95
|
+
* creating the stream. This method will verify that the stream
|
|
96
|
+
* exists and if not, create it.
|
|
97
|
+
* @private
|
|
98
|
+
*/
|
|
99
|
+
this.verifyStream = async (hotMeshClient, workflowTopic, namespace) => {
|
|
100
|
+
const optionsHash = this.hashOptions();
|
|
101
|
+
const targetNS = namespace ?? factory_1.APP_ID;
|
|
102
|
+
const targetTopic = `${optionsHash}.${targetNS}.${workflowTopic}`;
|
|
103
|
+
if (!ClientService.topics.includes(targetTopic)) {
|
|
104
|
+
ClientService.topics.push(targetTopic);
|
|
105
|
+
await ClientService.createStream(hotMeshClient, workflowTopic, namespace);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* @private
|
|
110
|
+
*/
|
|
111
|
+
this.search = async (hotMeshClient, index, query) => {
|
|
112
|
+
const searchClient = hotMeshClient.engine.search;
|
|
113
|
+
return await searchClient.sendIndexedQuery(index, query);
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* The MemFlow `Client` service is functionally
|
|
117
|
+
* equivalent to the Temporal `Client` service.
|
|
118
|
+
* Starting a workflow is the primary use case and
|
|
119
|
+
* is accessed by calling workflow.start().
|
|
120
|
+
*/
|
|
121
|
+
this.workflow = {
|
|
122
|
+
/**
|
|
123
|
+
* Starts a workflow, verifies the idempotent id, and
|
|
124
|
+
* adds searchable data to the record.
|
|
125
|
+
*/
|
|
126
|
+
start: async (options) => {
|
|
127
|
+
const taskQueueName = options.taskQueue ?? options.entity;
|
|
128
|
+
const workflowName = options.entity ?? options.workflowName;
|
|
129
|
+
const trc = options.workflowTrace;
|
|
130
|
+
const spn = options.workflowSpan;
|
|
131
|
+
//hotmesh `topic` is equivalent to `queue+workflowname` pattern in other systems
|
|
132
|
+
const workflowTopic = `${taskQueueName}-${workflowName}`;
|
|
133
|
+
const hotMeshClient = await this.getHotMeshClient(workflowTopic, options.namespace);
|
|
134
|
+
//verify that the stream channel exists before enqueueing
|
|
135
|
+
await this.verifyStream(hotMeshClient, workflowTopic, options.namespace);
|
|
136
|
+
const payload = {
|
|
137
|
+
arguments: [...options.args],
|
|
138
|
+
originJobId: options.originJobId,
|
|
139
|
+
expire: options.expire ?? enums_1.HMSH_EXPIRE_JOB_SECONDS,
|
|
140
|
+
persistent: options.persistent,
|
|
141
|
+
signalIn: options.signalIn,
|
|
142
|
+
parentWorkflowId: options.parentWorkflowId,
|
|
143
|
+
workflowId: options.workflowId || hotmesh_1.HotMesh.guid(),
|
|
144
|
+
workflowTopic: workflowTopic,
|
|
145
|
+
backoffCoefficient: options.config?.backoffCoefficient || enums_1.HMSH_MEMFLOW_EXP_BACKOFF,
|
|
146
|
+
maximumAttempts: options.config?.maximumAttempts || enums_1.HMSH_MEMFLOW_MAX_ATTEMPTS,
|
|
147
|
+
maximumInterval: (0, utils_1.s)(options.config?.maximumInterval || enums_1.HMSH_MEMFLOW_MAX_INTERVAL),
|
|
148
|
+
};
|
|
149
|
+
const context = { metadata: { trc, spn }, data: {} };
|
|
150
|
+
const jobId = await hotMeshClient.pub(`${options.namespace ?? factory_1.APP_ID}.execute`, payload, context, {
|
|
151
|
+
search: options?.search?.data,
|
|
152
|
+
marker: options?.marker,
|
|
153
|
+
pending: options?.pending,
|
|
154
|
+
});
|
|
155
|
+
return new handle_1.WorkflowHandleService(hotMeshClient, workflowTopic, jobId);
|
|
156
|
+
},
|
|
157
|
+
/**
|
|
158
|
+
* Sends a message payload to a running workflow that is paused and awaiting the signal
|
|
159
|
+
*/
|
|
160
|
+
signal: async (signalId, data, namespace) => {
|
|
161
|
+
const topic = `${namespace ?? factory_1.APP_ID}.wfs.signal`;
|
|
162
|
+
return await (await this.getHotMeshClient(topic, namespace)).hook(topic, { id: signalId, data });
|
|
163
|
+
},
|
|
164
|
+
/**
|
|
165
|
+
* Spawns an a new, isolated execution cycle within the same job.
|
|
166
|
+
* Similar to `worker` functions, `hook` functions have a linked
|
|
167
|
+
* function. But hooks do not start a new job and instead read/write
|
|
168
|
+
* their isolated activity data to an existing Job record (HASH).
|
|
169
|
+
*
|
|
170
|
+
* This example spawns a hook that will update workflow `guid123`.
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```typescript
|
|
174
|
+
* await client.workflow.hook({
|
|
175
|
+
* namespace: 'demo',
|
|
176
|
+
* taskQueue: 'default',
|
|
177
|
+
* workflowName: 'myDemoFunction',
|
|
178
|
+
* workflowId: 'guid123',
|
|
179
|
+
* args: ['Hello'],
|
|
180
|
+
* });
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
hook: async (options) => {
|
|
184
|
+
const workflowTopic = `${options.taskQueue ?? options.entity}-${options.entity ?? options.workflowName}`;
|
|
185
|
+
const payload = {
|
|
186
|
+
arguments: [...options.args],
|
|
187
|
+
id: options.workflowId,
|
|
188
|
+
workflowTopic,
|
|
189
|
+
backoffCoefficient: options.config?.backoffCoefficient || enums_1.HMSH_MEMFLOW_EXP_BACKOFF,
|
|
190
|
+
maximumAttempts: options.config?.maximumAttempts || enums_1.HMSH_MEMFLOW_MAX_ATTEMPTS,
|
|
191
|
+
maximumInterval: (0, utils_1.s)(options.config?.maximumInterval || enums_1.HMSH_MEMFLOW_MAX_INTERVAL),
|
|
192
|
+
};
|
|
193
|
+
//seed search data before entering
|
|
194
|
+
const hotMeshClient = await this.getHotMeshClient(workflowTopic, options.namespace);
|
|
195
|
+
const msgId = await hotMeshClient.hook(`${hotMeshClient.appId}.flow.signal`, payload, types_1.StreamStatus.PENDING, 202);
|
|
196
|
+
//todo: commit search data BEFORE enqueuing hook
|
|
197
|
+
if (options.search?.data) {
|
|
198
|
+
const searchSessionId = `-search-${hotmesh_1.HotMesh.guid()}-0`;
|
|
199
|
+
const search = new search_1.Search(options.workflowId, hotMeshClient, searchSessionId);
|
|
200
|
+
const entries = Object.entries(options.search.data).flat();
|
|
201
|
+
await search.set(...entries);
|
|
202
|
+
}
|
|
203
|
+
//todo: support context as well as search (-context-)
|
|
204
|
+
return msgId;
|
|
205
|
+
},
|
|
206
|
+
/**
|
|
207
|
+
* Returns a reference to a running workflow,
|
|
208
|
+
* allowing callers to check the status of the workflow,
|
|
209
|
+
* interrupt it, and even await its eventual response
|
|
210
|
+
* if still in a pending state.
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* ```typescript
|
|
214
|
+
* const handle = await client.workflow.getHandle(
|
|
215
|
+
* 'default',
|
|
216
|
+
* 'myFunction',
|
|
217
|
+
* 'someGuid123',
|
|
218
|
+
* 'demo',
|
|
219
|
+
* );
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
222
|
+
getHandle: async (taskQueue, workflowName, workflowId, namespace) => {
|
|
223
|
+
const workflowTopic = `${taskQueue}-${workflowName}`;
|
|
224
|
+
const hotMeshClient = await this.getHotMeshClient(workflowTopic, namespace);
|
|
225
|
+
return new handle_1.WorkflowHandleService(hotMeshClient, workflowTopic, workflowId);
|
|
226
|
+
},
|
|
227
|
+
/**
|
|
228
|
+
* Provides direct access to the SEARCH backend when making
|
|
229
|
+
* queries. Taskqueues and workflow names are
|
|
230
|
+
* used to identify the point of presence to use. `...args` is
|
|
231
|
+
* the tokenized query. When querying Redis/FTSEARCH, the trailing
|
|
232
|
+
* ...args might be `'@_custom1:memflow'`. For postgres,
|
|
233
|
+
* the trailing ...args would be: `'_custom', 'memflow'`. In each case,
|
|
234
|
+
* the query looks for all job data where the field `_custom` is
|
|
235
|
+
* equal to `memflow`.
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* ```typescript
|
|
239
|
+
* await client.workflow.search(
|
|
240
|
+
* 'someTaskQueue'
|
|
241
|
+
* 'someWorkflowName',
|
|
242
|
+
* 'memflow',
|
|
243
|
+
* 'user',
|
|
244
|
+
* ...args,
|
|
245
|
+
* );
|
|
246
|
+
* //returns [count, [id, fields[]], [id, fields[]], [id, fields[]], ...]]
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
search: async (taskQueue, workflowName, namespace, index, ...query) => {
|
|
250
|
+
const workflowTopic = `${taskQueue}-${workflowName}`;
|
|
251
|
+
const hotMeshClient = await this.getHotMeshClient(workflowTopic, namespace);
|
|
252
|
+
try {
|
|
253
|
+
return await this.search(hotMeshClient, index, query);
|
|
254
|
+
}
|
|
255
|
+
catch (error) {
|
|
256
|
+
hotMeshClient.engine.logger.error('memflow-client-search-err', {
|
|
257
|
+
error,
|
|
258
|
+
});
|
|
259
|
+
throw error;
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
};
|
|
263
|
+
this.connection = config.connection;
|
|
264
|
+
}
|
|
265
|
+
hashOptions() {
|
|
266
|
+
if ('options' in this.connection) {
|
|
267
|
+
//shorthand format
|
|
268
|
+
return (0, utils_1.hashOptions)(this.connection.options);
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
//longhand format (sub, store, stream, pub, search)
|
|
272
|
+
const response = [];
|
|
273
|
+
for (const p in this.connection) {
|
|
274
|
+
if (this.connection[p].options) {
|
|
275
|
+
response.push((0, utils_1.hashOptions)(this.connection[p].options));
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return response.join('');
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Any router can be used to deploy and activate the HotMesh
|
|
283
|
+
* distributed executable to the active quorum EXCEPT for
|
|
284
|
+
* those routers in `readonly` mode.
|
|
285
|
+
*/
|
|
286
|
+
async deployAndActivate(namespace = factory_1.APP_ID, version = factory_1.APP_VERSION) {
|
|
287
|
+
if (isNaN(Number(version))) {
|
|
288
|
+
throw new Error('Invalid version number');
|
|
289
|
+
}
|
|
290
|
+
const hotMesh = await this.getHotMeshClient('', namespace);
|
|
291
|
+
await this.activateWorkflow(hotMesh, namespace, version);
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* @private
|
|
295
|
+
*/
|
|
296
|
+
async verifyWorkflowActive(hotMesh, appId = factory_1.APP_ID, count = 0) {
|
|
297
|
+
const app = await hotMesh.engine.store.getApp(appId);
|
|
298
|
+
const appVersion = app?.version;
|
|
299
|
+
if (isNaN(appVersion)) {
|
|
300
|
+
if (count > 10) {
|
|
301
|
+
throw new Error('Workflow failed to activate');
|
|
302
|
+
}
|
|
303
|
+
await (0, utils_1.sleepFor)(enums_1.HMSH_QUORUM_DELAY_MS * 2);
|
|
304
|
+
return await this.verifyWorkflowActive(hotMesh, appId, count + 1);
|
|
305
|
+
}
|
|
306
|
+
return true;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* @private
|
|
310
|
+
*/
|
|
311
|
+
async activateWorkflow(hotMesh, appId = factory_1.APP_ID, version = factory_1.APP_VERSION) {
|
|
312
|
+
const app = await hotMesh.engine.store.getApp(appId);
|
|
313
|
+
const appVersion = app?.version;
|
|
314
|
+
if (appVersion === version && !app.active) {
|
|
315
|
+
try {
|
|
316
|
+
await hotMesh.activate(version);
|
|
317
|
+
}
|
|
318
|
+
catch (error) {
|
|
319
|
+
hotMesh.engine.logger.error('memflow-client-activate-err', {
|
|
320
|
+
error,
|
|
321
|
+
});
|
|
322
|
+
throw error;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
else if (isNaN(Number(appVersion)) || appVersion < version) {
|
|
326
|
+
try {
|
|
327
|
+
await hotMesh.deploy((0, factory_1.getWorkflowYAML)(appId, version));
|
|
328
|
+
await hotMesh.activate(version);
|
|
329
|
+
}
|
|
330
|
+
catch (error) {
|
|
331
|
+
hotMesh.engine.logger.error('memflow-client-deploy-activate-err', {
|
|
332
|
+
error,
|
|
333
|
+
});
|
|
334
|
+
throw error;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* @private
|
|
340
|
+
*/
|
|
341
|
+
static async shutdown() {
|
|
342
|
+
for (const [_, hotMeshInstance] of ClientService.instances) {
|
|
343
|
+
(await hotMeshInstance).stop();
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
_a = ClientService;
|
|
348
|
+
/**
|
|
349
|
+
* @private
|
|
350
|
+
*/
|
|
351
|
+
ClientService.topics = [];
|
|
352
|
+
/**
|
|
353
|
+
* @private
|
|
354
|
+
*/
|
|
355
|
+
ClientService.instances = new Map();
|
|
356
|
+
/**
|
|
357
|
+
* Creates a stream where messages can be published to ensure there is a
|
|
358
|
+
* channel in place when the message arrives (a race condition for those
|
|
359
|
+
* platforms without implicit topic setup).
|
|
360
|
+
* @private
|
|
361
|
+
*/
|
|
362
|
+
ClientService.createStream = async (hotMeshClient, workflowTopic, namespace) => {
|
|
363
|
+
const params = { appId: namespace ?? factory_1.APP_ID, topic: workflowTopic };
|
|
364
|
+
const streamKey = hotMeshClient.engine.store.mintKey(key_1.KeyType.STREAMS, params);
|
|
365
|
+
try {
|
|
366
|
+
await hotMeshClient.engine.stream.createConsumerGroup(streamKey, 'WORKER');
|
|
367
|
+
}
|
|
368
|
+
catch (err) {
|
|
369
|
+
//ignore if already exists
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
exports.ClientService = ClientService;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Connection } from '../../types/memflow';
|
|
2
|
+
import { ProviderConfig, ProvidersConfig } from '../../types/provider';
|
|
3
|
+
/**
|
|
4
|
+
* The Connection service is used to declare the class
|
|
5
|
+
* and connection options but does not connect quite yet. Connection
|
|
6
|
+
* happens at a later lifecycle stage when a workflow
|
|
7
|
+
* is started by the MemFlow Client module (`(new MemFlow.Client())).start()`).
|
|
8
|
+
*
|
|
9
|
+
* The config options optionall support a multi-connection setup
|
|
10
|
+
* where the `store` connection explicitly defined along with `stream`, `sub`, etc.
|
|
11
|
+
* For example, Postgres can be used for stream and store while
|
|
12
|
+
* Redis is used for sub.
|
|
13
|
+
*/
|
|
14
|
+
export declare class ConnectionService {
|
|
15
|
+
/**
|
|
16
|
+
* @private
|
|
17
|
+
*/
|
|
18
|
+
constructor();
|
|
19
|
+
/**
|
|
20
|
+
* Instance initializer
|
|
21
|
+
*/
|
|
22
|
+
static connect(config: ProviderConfig | ProvidersConfig): Promise<Connection>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConnectionService = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* The Connection service is used to declare the class
|
|
6
|
+
* and connection options but does not connect quite yet. Connection
|
|
7
|
+
* happens at a later lifecycle stage when a workflow
|
|
8
|
+
* is started by the MemFlow Client module (`(new MemFlow.Client())).start()`).
|
|
9
|
+
*
|
|
10
|
+
* The config options optionall support a multi-connection setup
|
|
11
|
+
* where the `store` connection explicitly defined along with `stream`, `sub`, etc.
|
|
12
|
+
* For example, Postgres can be used for stream and store while
|
|
13
|
+
* Redis is used for sub.
|
|
14
|
+
*/
|
|
15
|
+
class ConnectionService {
|
|
16
|
+
/**
|
|
17
|
+
* @private
|
|
18
|
+
*/
|
|
19
|
+
constructor() { }
|
|
20
|
+
/**
|
|
21
|
+
* Instance initializer
|
|
22
|
+
*/
|
|
23
|
+
static async connect(config) {
|
|
24
|
+
return 'store' in config
|
|
25
|
+
? config
|
|
26
|
+
: {
|
|
27
|
+
class: config.class,
|
|
28
|
+
options: { ...config.options },
|
|
29
|
+
provider: config.provider,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.ConnectionService = ConnectionService;
|