@hotmeshio/hotmesh 0.4.0 → 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/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 +7 -0
- package/build/services/memflow/workflow/signal.js +28 -0
- package/build/services/memflow/workflow/sleepFor.d.ts +8 -0
- package/build/services/memflow/workflow/sleepFor.js +35 -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 +8 -0
- package/build/services/memflow/workflow/waitFor.js +35 -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 +145 -0
- package/build/services/store/providers/postgres/postgres.js +1036 -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 +36 -0
- package/build/services/task/index.js +206 -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,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Validator = void 0;
|
|
4
|
+
const pipe_1 = require("../pipe");
|
|
5
|
+
class Validator {
|
|
6
|
+
constructor(manifest) {
|
|
7
|
+
this.manifest = null;
|
|
8
|
+
this.activityIds = [];
|
|
9
|
+
this.mappingStatements = {};
|
|
10
|
+
this.store = null;
|
|
11
|
+
this.manifest = manifest;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* validate the manifest file
|
|
15
|
+
*/
|
|
16
|
+
async validate(store) {
|
|
17
|
+
this.store = store;
|
|
18
|
+
this.getMappingStatements();
|
|
19
|
+
this.validateActivityIds();
|
|
20
|
+
this.validateReferencedActivityIds();
|
|
21
|
+
this.validateMappingStatements();
|
|
22
|
+
this.validateTransitions();
|
|
23
|
+
this.validateTransitionConditions();
|
|
24
|
+
this.validateStats();
|
|
25
|
+
this.validateSchemas();
|
|
26
|
+
this.validateUniqueHandledTopics();
|
|
27
|
+
this.validateGraphPublishSubscribe();
|
|
28
|
+
this.validateHooks();
|
|
29
|
+
this.validateConditionalStatements();
|
|
30
|
+
}
|
|
31
|
+
// 1.1) Validate the manifest file activity ids are unique (no duplicates)
|
|
32
|
+
validateActivityIds() {
|
|
33
|
+
const activityIdsSet = new Set();
|
|
34
|
+
this.manifest.app.graphs.forEach((graph) => {
|
|
35
|
+
const ids = Object.keys(graph.activities);
|
|
36
|
+
// Check for duplicates and add ids to the set
|
|
37
|
+
ids.forEach((id) => {
|
|
38
|
+
if (activityIdsSet.has(id)) {
|
|
39
|
+
throw new Error(`Duplicate activity id found: ${id}`);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
activityIdsSet.add(id);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
this.activityIds = Array.from(activityIdsSet);
|
|
47
|
+
}
|
|
48
|
+
isMappingStatement(value) {
|
|
49
|
+
return (typeof value === 'string' && value.startsWith('{') && value.endsWith('}'));
|
|
50
|
+
}
|
|
51
|
+
extractMappingStatements(obj, result, currentActivityId) {
|
|
52
|
+
for (const key in obj) {
|
|
53
|
+
if (typeof obj[key] === 'object' && obj[key] !== null) {
|
|
54
|
+
this.extractMappingStatements(obj[key], result, currentActivityId);
|
|
55
|
+
}
|
|
56
|
+
else if (this.isMappingStatement(obj[key])) {
|
|
57
|
+
if (!result[currentActivityId]) {
|
|
58
|
+
result[currentActivityId] = [];
|
|
59
|
+
}
|
|
60
|
+
result[currentActivityId].push(obj[key]);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
getMappingStatements() {
|
|
65
|
+
const mappingStatements = {};
|
|
66
|
+
this.manifest.app.graphs.forEach((graph) => {
|
|
67
|
+
const activities = graph.activities;
|
|
68
|
+
for (const activityId in activities) {
|
|
69
|
+
const activity = activities[activityId];
|
|
70
|
+
this.extractMappingStatements(activity, mappingStatements, activityId);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
this.mappingStatements = mappingStatements;
|
|
74
|
+
}
|
|
75
|
+
// 1.2) Validate no activity ids are referenced that don't exist
|
|
76
|
+
validateReferencedActivityIds() {
|
|
77
|
+
// get list of all mapping statements and validate
|
|
78
|
+
const mappingStatements = this.mappingStatements;
|
|
79
|
+
const activityIds = this.activityIds;
|
|
80
|
+
for (const activity in mappingStatements) {
|
|
81
|
+
const statements = mappingStatements[activity];
|
|
82
|
+
statements.forEach((statement) => {
|
|
83
|
+
if (statement.startsWith('{') && statement.endsWith('}')) {
|
|
84
|
+
const statementParts = statement.slice(1, -1).split('.');
|
|
85
|
+
const referencedActivityId = statementParts[0];
|
|
86
|
+
if (!(Validator.SYS_VARS.includes(referencedActivityId) ||
|
|
87
|
+
activityIds.includes(referencedActivityId) ||
|
|
88
|
+
this.isFunction(statement) ||
|
|
89
|
+
this.isContextVariable(statement))) {
|
|
90
|
+
throw new Error(`Mapping statement references non-existent activity: ${statement}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
isFunction(value) {
|
|
97
|
+
return value.startsWith('{@') && pipe_1.Pipe.resolveFunction(value);
|
|
98
|
+
}
|
|
99
|
+
isContextVariable(value) {
|
|
100
|
+
return ['{$input}', '{$output}', '{$item}', '{$key}', '{$index}'].includes(value);
|
|
101
|
+
}
|
|
102
|
+
// 1.3) Validate the mapping/@pipe statements are valid
|
|
103
|
+
validateMappingStatements() {
|
|
104
|
+
// Implement the method content
|
|
105
|
+
}
|
|
106
|
+
// 1.4) Validate the transitions are valid
|
|
107
|
+
validateTransitions() {
|
|
108
|
+
// Implement the method content
|
|
109
|
+
}
|
|
110
|
+
// 1.5) Validate the transition conditions are valid
|
|
111
|
+
validateTransitionConditions() {
|
|
112
|
+
// Implement the method content
|
|
113
|
+
}
|
|
114
|
+
// 1.6) Validate the stats
|
|
115
|
+
validateStats() {
|
|
116
|
+
// Implement the method content
|
|
117
|
+
}
|
|
118
|
+
// 1.7) Validate the schemas
|
|
119
|
+
validateSchemas() {
|
|
120
|
+
// Implement the method content
|
|
121
|
+
}
|
|
122
|
+
// 1.8) Validate the topics are unique and handled
|
|
123
|
+
validateUniqueHandledTopics() {
|
|
124
|
+
// Implement the method content
|
|
125
|
+
}
|
|
126
|
+
// 1.9) Validate that every graph has publishes and subscribes
|
|
127
|
+
validateGraphPublishSubscribe() {
|
|
128
|
+
// Implement the method content
|
|
129
|
+
}
|
|
130
|
+
// 1.10) Validate hooks, including mapping statements
|
|
131
|
+
validateHooks() {
|
|
132
|
+
// Implement the method content
|
|
133
|
+
}
|
|
134
|
+
// 1.11) Validate conditional statements
|
|
135
|
+
validateConditionalStatements() {
|
|
136
|
+
// Implement the method content
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
exports.Validator = Validator;
|
|
140
|
+
Validator.SYS_VARS = ['$app', '$self', '$graph', '$job'];
|
|
141
|
+
Validator.CONTEXT_VARS = [
|
|
142
|
+
'{$input}',
|
|
143
|
+
'{$output}',
|
|
144
|
+
'{$item}',
|
|
145
|
+
'{$key}',
|
|
146
|
+
'{$index}',
|
|
147
|
+
];
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { HotMeshEngine, HotMeshWorker } from '../../types/hotmesh';
|
|
2
|
+
import { ProviderConfig, ProviderNativeClient } from '../../types/provider';
|
|
3
|
+
export declare class ConnectorService {
|
|
4
|
+
static disconnectAll(): Promise<void>;
|
|
5
|
+
/**
|
|
6
|
+
* Connect to a provider (redis, nats, postgres) and return the native
|
|
7
|
+
* client. Connections are handled by the engine and worker routers at
|
|
8
|
+
* initialization, but the factory method provided here is useful
|
|
9
|
+
* for testing provider configurations.
|
|
10
|
+
*/
|
|
11
|
+
static connectClient(ProviderConfig: ProviderConfig): Promise<ProviderNativeClient>;
|
|
12
|
+
/**
|
|
13
|
+
* Initialize `store`, `stream`, and `subscription` clients for any provider.
|
|
14
|
+
* @private
|
|
15
|
+
*/
|
|
16
|
+
static initClients(target: HotMeshEngine | HotMeshWorker): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Binds a provider client native instance to the target object.
|
|
19
|
+
* @private
|
|
20
|
+
*/
|
|
21
|
+
static initClient(ProviderConfig: ProviderConfig, target: HotMeshEngine | HotMeshWorker, field: string): Promise<void>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConnectorService = void 0;
|
|
4
|
+
const utils_1 = require("../../modules/utils");
|
|
5
|
+
const ioredis_1 = require("./providers/ioredis");
|
|
6
|
+
const nats_1 = require("./providers/nats");
|
|
7
|
+
const postgres_1 = require("./providers/postgres");
|
|
8
|
+
const redis_1 = require("./providers/redis");
|
|
9
|
+
class ConnectorService {
|
|
10
|
+
static async disconnectAll() {
|
|
11
|
+
await redis_1.RedisConnection.disconnectAll();
|
|
12
|
+
await ioredis_1.RedisConnection.disconnectAll();
|
|
13
|
+
await postgres_1.PostgresConnection.disconnectAll();
|
|
14
|
+
await nats_1.NatsConnection.disconnectAll();
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Connect to a provider (redis, nats, postgres) and return the native
|
|
18
|
+
* client. Connections are handled by the engine and worker routers at
|
|
19
|
+
* initialization, but the factory method provided here is useful
|
|
20
|
+
* for testing provider configurations.
|
|
21
|
+
*/
|
|
22
|
+
static async connectClient(ProviderConfig) {
|
|
23
|
+
const target = {};
|
|
24
|
+
await ConnectorService.initClient(ProviderConfig, target, 'client');
|
|
25
|
+
return target.client;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Initialize `store`, `stream`, and `subscription` clients for any provider.
|
|
29
|
+
* @private
|
|
30
|
+
*/
|
|
31
|
+
static async initClients(target) {
|
|
32
|
+
let connection = utils_1.polyfill.providerConfig(target);
|
|
33
|
+
if (!('store' in connection)) {
|
|
34
|
+
connection = target.connection = {
|
|
35
|
+
...connection,
|
|
36
|
+
store: { ...connection },
|
|
37
|
+
stream: { ...connection },
|
|
38
|
+
sub: { ...connection },
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
// Expanded form
|
|
42
|
+
if (connection.store) {
|
|
43
|
+
await ConnectorService.initClient(connection.store, target, 'store');
|
|
44
|
+
}
|
|
45
|
+
if (connection.stream) {
|
|
46
|
+
await ConnectorService.initClient(connection.stream, target, 'stream');
|
|
47
|
+
}
|
|
48
|
+
if (connection.sub) {
|
|
49
|
+
await ConnectorService.initClient(connection.sub, target, 'sub');
|
|
50
|
+
// use store for publishing events if same as subscription
|
|
51
|
+
if (connection.sub.class !== connection.store.class) {
|
|
52
|
+
//initialize a separate client for publishing events, using
|
|
53
|
+
//the same provider as the subscription client
|
|
54
|
+
connection.pub = {
|
|
55
|
+
class: connection.sub.class,
|
|
56
|
+
options: { ...connection.sub.options },
|
|
57
|
+
provider: connection.sub.provider,
|
|
58
|
+
};
|
|
59
|
+
await ConnectorService.initClient(connection.pub, target, 'pub');
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Binds a provider client native instance to the target object.
|
|
65
|
+
* @private
|
|
66
|
+
*/
|
|
67
|
+
static async initClient(ProviderConfig, target, field) {
|
|
68
|
+
if (target[field]) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const providerClass = ProviderConfig.class;
|
|
72
|
+
const options = ProviderConfig.options;
|
|
73
|
+
const providerName = ProviderConfig.provider || (0, utils_1.identifyProvider)(providerClass); //e.g. 'postgres.poolclient'
|
|
74
|
+
const providerType = providerName.split('.')[0]; //e.g. 'postgres'
|
|
75
|
+
let clientInstance;
|
|
76
|
+
const id = (0, utils_1.guid)();
|
|
77
|
+
switch (providerType) {
|
|
78
|
+
case 'redis':
|
|
79
|
+
clientInstance = await redis_1.RedisConnection.connect(id, providerClass, options, { provider: providerName });
|
|
80
|
+
break;
|
|
81
|
+
case 'ioredis':
|
|
82
|
+
clientInstance = await ioredis_1.RedisConnection.connect(id, providerClass, options, { provider: providerName });
|
|
83
|
+
break;
|
|
84
|
+
case 'nats':
|
|
85
|
+
clientInstance = await nats_1.NatsConnection.connect(id, providerClass, options, { provider: providerName });
|
|
86
|
+
break;
|
|
87
|
+
case 'postgres':
|
|
88
|
+
//if connecting as a poolClient for subscription, auto connect the client
|
|
89
|
+
const bAutoConnect = field === 'sub';
|
|
90
|
+
clientInstance = await postgres_1.PostgresConnection.connect(id, providerClass, options, { connect: bAutoConnect, provider: providerName });
|
|
91
|
+
break;
|
|
92
|
+
default:
|
|
93
|
+
throw new Error(`Unknown provider type: ${providerType}`);
|
|
94
|
+
}
|
|
95
|
+
// Bind the resolved client instance to the target object
|
|
96
|
+
target[field] = clientInstance.getClient();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exports.ConnectorService = ConnectorService;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { StringAnyType } from '../../types';
|
|
2
|
+
import { ProviderClass, ProviderNativeClient, ProviderOptions } from '../../types/provider';
|
|
3
|
+
import { ILogger } from '../logger';
|
|
4
|
+
/**
|
|
5
|
+
* Abstract class for creating connections to different backend providers.
|
|
6
|
+
* All implementations should extend this class and implement
|
|
7
|
+
* the following steps:
|
|
8
|
+
*
|
|
9
|
+
* 1) Add the provider to ./providers/<name>.ts
|
|
10
|
+
* 2) Update ./factory.ts to reference the provider
|
|
11
|
+
* 3) Register the tag with the `Provider` type in ./types/provider.ts.
|
|
12
|
+
* 4) Create the specific provider type file at ./types/<name>.ts
|
|
13
|
+
* 5) Update ./modules/utils.ts (identifyProvider) with logic to resolve the provider by inspecting the class/import
|
|
14
|
+
*/
|
|
15
|
+
declare abstract class AbstractConnection<PClass, POptions> {
|
|
16
|
+
static logger: ILogger;
|
|
17
|
+
static disconnecting: boolean;
|
|
18
|
+
protected connection: any | null;
|
|
19
|
+
protected static instances: Map<string, AbstractConnection<ProviderClass, ProviderOptions>>;
|
|
20
|
+
protected id: string | null;
|
|
21
|
+
protected abstract defaultOptions: any;
|
|
22
|
+
protected abstract createConnection(client: PClass, options: POptions, config?: StringAnyType): Promise<any>;
|
|
23
|
+
abstract getClient(): ProviderNativeClient;
|
|
24
|
+
disconnect(): Promise<void>;
|
|
25
|
+
protected abstract closeConnection(connection: any): Promise<void>;
|
|
26
|
+
static connect<T extends AbstractConnection<ProviderClass, ProviderOptions>>(this: new () => T, id: string, client: ProviderClass, options?: ProviderOptions, //user
|
|
27
|
+
config?: StringAnyType): Promise<T>;
|
|
28
|
+
static disconnectAll(): Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
export { AbstractConnection };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AbstractConnection = void 0;
|
|
4
|
+
const logger_1 = require("../logger");
|
|
5
|
+
/**
|
|
6
|
+
* Abstract class for creating connections to different backend providers.
|
|
7
|
+
* All implementations should extend this class and implement
|
|
8
|
+
* the following steps:
|
|
9
|
+
*
|
|
10
|
+
* 1) Add the provider to ./providers/<name>.ts
|
|
11
|
+
* 2) Update ./factory.ts to reference the provider
|
|
12
|
+
* 3) Register the tag with the `Provider` type in ./types/provider.ts.
|
|
13
|
+
* 4) Create the specific provider type file at ./types/<name>.ts
|
|
14
|
+
* 5) Update ./modules/utils.ts (identifyProvider) with logic to resolve the provider by inspecting the class/import
|
|
15
|
+
*/
|
|
16
|
+
class AbstractConnection {
|
|
17
|
+
constructor() {
|
|
18
|
+
this.connection = null;
|
|
19
|
+
this.id = null;
|
|
20
|
+
}
|
|
21
|
+
async disconnect() {
|
|
22
|
+
if (this.connection) {
|
|
23
|
+
await this.closeConnection(this.connection);
|
|
24
|
+
this.connection = null;
|
|
25
|
+
}
|
|
26
|
+
if (this.id) {
|
|
27
|
+
AbstractConnection.instances.delete(this.id);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
static async connect(id, client, options, //user
|
|
31
|
+
config) {
|
|
32
|
+
if (AbstractConnection.instances.has(id)) {
|
|
33
|
+
return AbstractConnection.instances.get(id);
|
|
34
|
+
}
|
|
35
|
+
const instance = new this();
|
|
36
|
+
const opts = options ? { ...options } : { ...instance.defaultOptions };
|
|
37
|
+
instance.connection = await instance.createConnection(client, opts, config);
|
|
38
|
+
instance.id = id;
|
|
39
|
+
AbstractConnection.instances.set(id, instance);
|
|
40
|
+
return instance;
|
|
41
|
+
}
|
|
42
|
+
static async disconnectAll() {
|
|
43
|
+
if (!this.disconnecting) {
|
|
44
|
+
this.disconnecting = true;
|
|
45
|
+
await Promise.all(Array.from(this.instances.values()).map((instance) => instance.disconnect()));
|
|
46
|
+
this.instances.clear();
|
|
47
|
+
this.disconnecting = false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.AbstractConnection = AbstractConnection;
|
|
52
|
+
AbstractConnection.logger = new logger_1.LoggerService('hotmesh', 'system');
|
|
53
|
+
AbstractConnection.disconnecting = false;
|
|
54
|
+
AbstractConnection.instances = new Map();
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AbstractConnection } from '..';
|
|
2
|
+
import { IORedisClientOptions as RedisClientOptions, IORedisClassType as RedisClassType, IORedisClientType as RedisClientType } from '../../../types/redis';
|
|
3
|
+
declare class RedisConnection extends AbstractConnection<RedisClassType, RedisClientOptions> {
|
|
4
|
+
defaultOptions: RedisClientOptions;
|
|
5
|
+
createConnection(Redis: RedisClassType, options: RedisClientOptions): Promise<RedisClientType>;
|
|
6
|
+
getClient(): RedisClientType;
|
|
7
|
+
closeConnection(connection: RedisClientType): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
export { RedisConnection };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RedisConnection = void 0;
|
|
4
|
+
const __1 = require("..");
|
|
5
|
+
class RedisConnection extends __1.AbstractConnection {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this.defaultOptions = {
|
|
9
|
+
host: 'localhost',
|
|
10
|
+
port: 6379,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
async createConnection(Redis, options) {
|
|
14
|
+
return new Redis(options);
|
|
15
|
+
}
|
|
16
|
+
getClient() {
|
|
17
|
+
if (!this.connection) {
|
|
18
|
+
throw new Error('Redis client is not connected');
|
|
19
|
+
}
|
|
20
|
+
return this.connection;
|
|
21
|
+
}
|
|
22
|
+
async closeConnection(connection) {
|
|
23
|
+
await connection.quit();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.RedisConnection = RedisConnection;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AbstractConnection } from '..';
|
|
2
|
+
import { NatsClientOptions, NatsClientType, NatsClassType } from '../../../types/nats';
|
|
3
|
+
declare class NatsConnection extends AbstractConnection<NatsClassType, NatsClientOptions> {
|
|
4
|
+
defaultOptions: NatsClientOptions;
|
|
5
|
+
createConnection(Connect: NatsClassType, options: NatsClientOptions): Promise<NatsClientType>;
|
|
6
|
+
getClient(): NatsClientType;
|
|
7
|
+
closeConnection(connection: NatsClientType): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
export { NatsConnection, NatsClientOptions };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NatsConnection = void 0;
|
|
4
|
+
const __1 = require("..");
|
|
5
|
+
class NatsConnection extends __1.AbstractConnection {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this.defaultOptions = {
|
|
9
|
+
servers: ['nats:4222'],
|
|
10
|
+
timeout: 5000,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
async createConnection(Connect, options) {
|
|
14
|
+
try {
|
|
15
|
+
return (await Connect(options));
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
NatsConnection.logger.error(`nats-provider-connection-failed`, {
|
|
19
|
+
error,
|
|
20
|
+
});
|
|
21
|
+
throw new Error(`nats-provider-connection-failed: ${error.message}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
getClient() {
|
|
25
|
+
if (!this.connection) {
|
|
26
|
+
throw new Error('nats-provider-connection-failed');
|
|
27
|
+
}
|
|
28
|
+
return this.connection;
|
|
29
|
+
}
|
|
30
|
+
async closeConnection(connection) {
|
|
31
|
+
await connection.close();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.NatsConnection = NatsConnection;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AbstractConnection } from '..';
|
|
2
|
+
import { PostgresClientOptions, PostgresClientType, PostgresClassType, PostgresPoolClientType } from '../../../types/postgres';
|
|
3
|
+
declare class PostgresConnection extends AbstractConnection<PostgresClassType, PostgresClientOptions> {
|
|
4
|
+
defaultOptions: PostgresClientOptions;
|
|
5
|
+
protected static poolClientInstances: Set<PostgresPoolClientType>;
|
|
6
|
+
protected static connectionInstances: Set<PostgresClientType>;
|
|
7
|
+
poolClientInstance: PostgresPoolClientType;
|
|
8
|
+
createConnection(clientConstructor: any, options: PostgresClientOptions, config?: {
|
|
9
|
+
connect?: boolean;
|
|
10
|
+
provider?: string;
|
|
11
|
+
}): Promise<PostgresClientType>;
|
|
12
|
+
getClient(): PostgresClientType;
|
|
13
|
+
static disconnectAll(): Promise<void>;
|
|
14
|
+
static disconnectPoolClients(): Promise<void>;
|
|
15
|
+
static disconnectConnections(): Promise<void>;
|
|
16
|
+
closeConnection(connection: PostgresClientType): Promise<void>;
|
|
17
|
+
static isPoolClient(client: any): client is PostgresPoolClientType;
|
|
18
|
+
static getTransactionClient(transactionClient: any): Promise<['client' | 'poolclient', PostgresClientType]>;
|
|
19
|
+
}
|
|
20
|
+
export { PostgresConnection };
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PostgresConnection = void 0;
|
|
4
|
+
const __1 = require("..");
|
|
5
|
+
class PostgresConnection extends __1.AbstractConnection {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this.defaultOptions = {
|
|
9
|
+
host: 'postgres',
|
|
10
|
+
port: 5432,
|
|
11
|
+
user: 'postgres',
|
|
12
|
+
password: 'password',
|
|
13
|
+
database: 'hotmesh',
|
|
14
|
+
max: 20,
|
|
15
|
+
idleTimeoutMillis: 30000,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
async createConnection(clientConstructor, options, config = {}) {
|
|
19
|
+
try {
|
|
20
|
+
let connection;
|
|
21
|
+
if (config.provider === 'postgres.poolclient' ||
|
|
22
|
+
PostgresConnection.isPoolClient(clientConstructor)) {
|
|
23
|
+
// It's a PoolClient
|
|
24
|
+
connection = clientConstructor;
|
|
25
|
+
if (config.connect) {
|
|
26
|
+
const client = await clientConstructor.connect();
|
|
27
|
+
//register the connection singularly to be 'released' later
|
|
28
|
+
PostgresConnection.poolClientInstances.add(client);
|
|
29
|
+
this.poolClientInstance = client;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
// It's a Client
|
|
34
|
+
connection = new clientConstructor(options);
|
|
35
|
+
await connection.connect();
|
|
36
|
+
await connection.query('SELECT 1');
|
|
37
|
+
}
|
|
38
|
+
//register the connection statically to be 'ended' later
|
|
39
|
+
PostgresConnection.connectionInstances.add(connection);
|
|
40
|
+
return connection;
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
PostgresConnection.logger.error(`postgres-provider-connection-failed`, {
|
|
44
|
+
host: options.host ?? 'unknown',
|
|
45
|
+
database: options.database ?? 'unknown',
|
|
46
|
+
port: options.port ?? 'unknown',
|
|
47
|
+
error,
|
|
48
|
+
});
|
|
49
|
+
throw new Error(`postgres-provider-connection-failed: ${error.message}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
getClient() {
|
|
53
|
+
if (!this.connection) {
|
|
54
|
+
throw new Error('Postgres client is not connected');
|
|
55
|
+
}
|
|
56
|
+
return this.poolClientInstance || this.connection;
|
|
57
|
+
}
|
|
58
|
+
static async disconnectAll() {
|
|
59
|
+
if (!this.disconnecting) {
|
|
60
|
+
this.disconnecting = true;
|
|
61
|
+
await this.disconnectPoolClients();
|
|
62
|
+
await this.disconnectConnections();
|
|
63
|
+
this.disconnecting = false;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
static async disconnectPoolClients() {
|
|
67
|
+
Array.from(this.poolClientInstances.values()).map((instance) => {
|
|
68
|
+
instance.release();
|
|
69
|
+
});
|
|
70
|
+
this.poolClientInstances.clear();
|
|
71
|
+
}
|
|
72
|
+
static async disconnectConnections() {
|
|
73
|
+
Array.from(this.connectionInstances.values()).map((instance) => {
|
|
74
|
+
instance.end();
|
|
75
|
+
});
|
|
76
|
+
this.connectionInstances.clear();
|
|
77
|
+
}
|
|
78
|
+
async closeConnection(connection) {
|
|
79
|
+
//no-op (handled by disconnectAll)
|
|
80
|
+
}
|
|
81
|
+
static isPoolClient(client) {
|
|
82
|
+
return !(isNaN(client?.totalCount) && isNaN(client?.idleCount));
|
|
83
|
+
}
|
|
84
|
+
static async getTransactionClient(transactionClient) {
|
|
85
|
+
let client;
|
|
86
|
+
let type;
|
|
87
|
+
if (PostgresConnection.isPoolClient(transactionClient)) {
|
|
88
|
+
type = 'poolclient';
|
|
89
|
+
client = await transactionClient.connect();
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
type = 'client';
|
|
93
|
+
client = transactionClient;
|
|
94
|
+
}
|
|
95
|
+
return [type, client];
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.PostgresConnection = PostgresConnection;
|
|
99
|
+
//statically track all clients (//call 'release')
|
|
100
|
+
PostgresConnection.poolClientInstances = new Set();
|
|
101
|
+
//statically track all connections (//call 'end')
|
|
102
|
+
PostgresConnection.connectionInstances = new Set();
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AbstractConnection } from '..';
|
|
2
|
+
import { RedisRedisClassType as RedisClassType, RedisRedisClientType as RedisClientType, RedisRedisClientOptions as RedisClientOptions } from '../../../types/redis';
|
|
3
|
+
declare class RedisConnection extends AbstractConnection<RedisClassType, RedisClientOptions> {
|
|
4
|
+
defaultOptions: RedisClientOptions;
|
|
5
|
+
createConnection(Redis: Partial<RedisClassType>, options: RedisClientOptions): Promise<Partial<RedisClientType>>;
|
|
6
|
+
getClient(): RedisClientType;
|
|
7
|
+
closeConnection(connection: any): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
export { RedisConnection, RedisClientType };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RedisConnection = void 0;
|
|
4
|
+
const __1 = require("..");
|
|
5
|
+
class RedisConnection extends __1.AbstractConnection {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this.defaultOptions = {
|
|
9
|
+
socket: {
|
|
10
|
+
host: 'localhost',
|
|
11
|
+
port: 6379,
|
|
12
|
+
tls: false,
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
async createConnection(Redis, options) {
|
|
17
|
+
return new Promise((resolve, reject) => {
|
|
18
|
+
const client = Redis.createClient(options);
|
|
19
|
+
client.on('error', (error) => {
|
|
20
|
+
reject(error);
|
|
21
|
+
});
|
|
22
|
+
client.on('ready', () => {
|
|
23
|
+
resolve(client);
|
|
24
|
+
});
|
|
25
|
+
client.connect();
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
getClient() {
|
|
29
|
+
if (!this.connection) {
|
|
30
|
+
throw new Error('Redis client is not connected');
|
|
31
|
+
}
|
|
32
|
+
return this.connection;
|
|
33
|
+
}
|
|
34
|
+
async closeConnection(connection) {
|
|
35
|
+
await connection.quit();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.RedisConnection = RedisConnection;
|