@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,374 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.arrayToHash = exports.isStreamMessage = exports.parseStreamMessage = exports.s = exports.isValidCron = exports.restoreHierarchy = exports.getValueByPath = exports.getIndexedHash = exports.getSymVal = exports.getSymKey = exports.formatISODate = exports.getTimeSeries = exports.getSubscriptionTopic = exports.findSubscriptionForTrigger = exports.findTopKey = exports.matchesStatus = exports.matchesStatusCode = exports.polyfill = exports.identifyProvider = exports.XSleepFor = exports.sleepImmediate = exports.sleepFor = exports.guid = exports.deterministicRandom = exports.deepCopy = exports.getSystemHealth = exports.hashOptions = void 0;
|
|
7
|
+
const os_1 = __importDefault(require("os"));
|
|
8
|
+
const crypto_1 = require("crypto");
|
|
9
|
+
const nanoid_1 = require("nanoid");
|
|
10
|
+
const ms_1 = __importDefault(require("ms"));
|
|
11
|
+
const logger_1 = require("../services/logger");
|
|
12
|
+
const enums_1 = require("./enums");
|
|
13
|
+
const logger = new logger_1.LoggerService('hotmesh', 'utils');
|
|
14
|
+
/**
|
|
15
|
+
* @private
|
|
16
|
+
*/
|
|
17
|
+
const hashOptions = (options) => {
|
|
18
|
+
const str = JSON.stringify(options);
|
|
19
|
+
return (0, crypto_1.createHash)('sha256').update(str).digest('hex');
|
|
20
|
+
};
|
|
21
|
+
exports.hashOptions = hashOptions;
|
|
22
|
+
async function getSystemHealth() {
|
|
23
|
+
const totalMemory = os_1.default.totalmem();
|
|
24
|
+
const freeMemory = os_1.default.freemem();
|
|
25
|
+
const usedMemory = totalMemory - freeMemory;
|
|
26
|
+
const systemHealth = {
|
|
27
|
+
TotalMemoryGB: `${(totalMemory / 1024 / 1024 / 1024).toFixed(2)} GB`,
|
|
28
|
+
FreeMemoryGB: `${(freeMemory / 1024 / 1024 / 1024).toFixed(2)} GB`,
|
|
29
|
+
UsedMemoryGB: `${(usedMemory / 1024 / 1024 / 1024).toFixed(2)} GB`,
|
|
30
|
+
CPULoad: [],
|
|
31
|
+
NetworkStats: [],
|
|
32
|
+
};
|
|
33
|
+
return systemHealth;
|
|
34
|
+
}
|
|
35
|
+
exports.getSystemHealth = getSystemHealth;
|
|
36
|
+
function deepCopy(obj) {
|
|
37
|
+
return JSON.parse(JSON.stringify(obj));
|
|
38
|
+
}
|
|
39
|
+
exports.deepCopy = deepCopy;
|
|
40
|
+
function deterministicRandom(seed) {
|
|
41
|
+
const x = Math.sin(seed) * 10000;
|
|
42
|
+
return x - Math.floor(x);
|
|
43
|
+
}
|
|
44
|
+
exports.deterministicRandom = deterministicRandom;
|
|
45
|
+
function guid(size = enums_1.HMSH_GUID_SIZE) {
|
|
46
|
+
return `H` + (0, nanoid_1.nanoid)(size);
|
|
47
|
+
}
|
|
48
|
+
exports.guid = guid;
|
|
49
|
+
async function sleepFor(ms) {
|
|
50
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
51
|
+
}
|
|
52
|
+
exports.sleepFor = sleepFor;
|
|
53
|
+
function sleepImmediate() {
|
|
54
|
+
return new Promise((resolve) => setImmediate(resolve));
|
|
55
|
+
}
|
|
56
|
+
exports.sleepImmediate = sleepImmediate;
|
|
57
|
+
function XSleepFor(ms) {
|
|
58
|
+
//can be interrupted with `clearTimeout`
|
|
59
|
+
let timerId;
|
|
60
|
+
const promise = new Promise((resolve) => {
|
|
61
|
+
timerId = setTimeout(resolve, ms);
|
|
62
|
+
});
|
|
63
|
+
return { promise, timerId };
|
|
64
|
+
}
|
|
65
|
+
exports.XSleepFor = XSleepFor;
|
|
66
|
+
/**
|
|
67
|
+
* Identies the provider type based on the provider object. Customers may
|
|
68
|
+
* explicitly set the provider type in the configuration. But this is a
|
|
69
|
+
* convenience method to automatically identify the provider type.
|
|
70
|
+
* @private
|
|
71
|
+
*/
|
|
72
|
+
function identifyProvider(provider) {
|
|
73
|
+
const prototype = Object.getPrototypeOf(provider);
|
|
74
|
+
if (provider.Query?.prototype ||
|
|
75
|
+
Object.keys(provider).includes('database') ||
|
|
76
|
+
prototype.name === 'Pool') {
|
|
77
|
+
return 'postgres';
|
|
78
|
+
}
|
|
79
|
+
else if (provider.toString().toLowerCase().includes('nats')) {
|
|
80
|
+
return 'nats';
|
|
81
|
+
}
|
|
82
|
+
else if ('defineCommand' in prototype ||
|
|
83
|
+
Object.keys(prototype).includes('multi')) {
|
|
84
|
+
return 'ioredis';
|
|
85
|
+
}
|
|
86
|
+
else if (Object.keys(prototype).includes('Multi')) {
|
|
87
|
+
return 'redis';
|
|
88
|
+
}
|
|
89
|
+
if (provider.constructor) {
|
|
90
|
+
if (provider.constructor.name === 'Redis' ||
|
|
91
|
+
provider.constructor.name === 'EventEmitter') {
|
|
92
|
+
if ('hset' in provider) {
|
|
93
|
+
return 'ioredis';
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
else if (provider.constructor.name === 'ProviderClient' ||
|
|
97
|
+
provider.constructor.name === 'Commander') {
|
|
98
|
+
if ('HSET' in provider) {
|
|
99
|
+
return 'redis';
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
let type = null;
|
|
104
|
+
if (Object.keys(provider).includes('connection') ||
|
|
105
|
+
!isNaN(provider.totalCount) && !isNaN(provider.idleCount)) {
|
|
106
|
+
type = 'postgres';
|
|
107
|
+
}
|
|
108
|
+
else if (Object.keys(provider).includes('Pipeline')) {
|
|
109
|
+
type = 'ioredis';
|
|
110
|
+
}
|
|
111
|
+
else if (Object.keys(provider).includes('createClient')) {
|
|
112
|
+
type = 'redis';
|
|
113
|
+
}
|
|
114
|
+
else if (prototype.constructor.toString().includes('NatsConnectionImpl')) {
|
|
115
|
+
type = 'nats';
|
|
116
|
+
}
|
|
117
|
+
return type;
|
|
118
|
+
}
|
|
119
|
+
exports.identifyProvider = identifyProvider;
|
|
120
|
+
/**
|
|
121
|
+
* @private
|
|
122
|
+
*/
|
|
123
|
+
exports.polyfill = {
|
|
124
|
+
/**
|
|
125
|
+
* `redis` is deprecated; `connection` is the generic replacement
|
|
126
|
+
*/
|
|
127
|
+
providerConfig(obj) {
|
|
128
|
+
return obj?.connection ?? obj?.redis ?? obj?.connections;
|
|
129
|
+
},
|
|
130
|
+
/**
|
|
131
|
+
* NOTE: `redisClass and redisOptions` input parameters are deprecated; use `connection` for all configuration inputs
|
|
132
|
+
*/
|
|
133
|
+
meshDataConfig(obj) {
|
|
134
|
+
return { ...obj.connection };
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* @private
|
|
139
|
+
*/
|
|
140
|
+
function matchesStatusCode(code, pattern) {
|
|
141
|
+
if (typeof pattern === 'string') {
|
|
142
|
+
// Convert '*' wildcard to its regex equivalent (\d)
|
|
143
|
+
const regexPattern = `^${pattern.replace(/\*/g, '\\d')}$`;
|
|
144
|
+
return new RegExp(regexPattern).test(code.toString());
|
|
145
|
+
}
|
|
146
|
+
return pattern.test(code.toString());
|
|
147
|
+
}
|
|
148
|
+
exports.matchesStatusCode = matchesStatusCode;
|
|
149
|
+
/**
|
|
150
|
+
* @private
|
|
151
|
+
*/
|
|
152
|
+
function matchesStatus(status, targetStatus) {
|
|
153
|
+
return status === targetStatus;
|
|
154
|
+
}
|
|
155
|
+
exports.matchesStatus = matchesStatus;
|
|
156
|
+
/**
|
|
157
|
+
* @private
|
|
158
|
+
*/
|
|
159
|
+
function findTopKey(obj, input) {
|
|
160
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
161
|
+
if (value.hasOwnProperty(input)) {
|
|
162
|
+
const parentKey = findTopKey(obj, key.replace(/^\./, ''));
|
|
163
|
+
return (parentKey || key).replace(/^\./, '');
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
exports.findTopKey = findTopKey;
|
|
169
|
+
/**
|
|
170
|
+
* @private
|
|
171
|
+
*/
|
|
172
|
+
function findSubscriptionForTrigger(obj, value) {
|
|
173
|
+
for (const [key, itemValue] of Object.entries(obj)) {
|
|
174
|
+
if (itemValue === value) {
|
|
175
|
+
return key;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
exports.findSubscriptionForTrigger = findSubscriptionForTrigger;
|
|
181
|
+
/**
|
|
182
|
+
* Get the subscription topic for the flow to which activityId belongs.
|
|
183
|
+
* @private
|
|
184
|
+
*/
|
|
185
|
+
async function getSubscriptionTopic(activityId, store, appVID) {
|
|
186
|
+
const appTransitions = await store.getTransitions(appVID);
|
|
187
|
+
const appSubscriptions = await store.getSubscriptions(appVID);
|
|
188
|
+
const triggerId = findTopKey(appTransitions, activityId);
|
|
189
|
+
const topic = findSubscriptionForTrigger(appSubscriptions, triggerId);
|
|
190
|
+
return topic;
|
|
191
|
+
}
|
|
192
|
+
exports.getSubscriptionTopic = getSubscriptionTopic;
|
|
193
|
+
/**
|
|
194
|
+
* returns the 12-digit format of the iso timestamp (e.g, 202101010000); returns
|
|
195
|
+
* an empty string if overridden by the user to not segment by time (infinity).
|
|
196
|
+
* @private
|
|
197
|
+
*/
|
|
198
|
+
function getTimeSeries(granularity) {
|
|
199
|
+
if (granularity.toString() === 'infinity') {
|
|
200
|
+
return '0';
|
|
201
|
+
}
|
|
202
|
+
const now = new Date();
|
|
203
|
+
const granularityUnit = granularity.slice(-1);
|
|
204
|
+
const granularityValue = parseInt(granularity.slice(0, -1), 10);
|
|
205
|
+
if (granularityUnit === 'm') {
|
|
206
|
+
const minute = Math.floor(now.getMinutes() / granularityValue) * granularityValue;
|
|
207
|
+
now.setUTCMinutes(minute, 0, 0);
|
|
208
|
+
}
|
|
209
|
+
else if (granularityUnit === 'h') {
|
|
210
|
+
now.setUTCMinutes(0, 0, 0);
|
|
211
|
+
}
|
|
212
|
+
return now
|
|
213
|
+
.toISOString()
|
|
214
|
+
.replace(/:\d\d\..+|-|T/g, '')
|
|
215
|
+
.replace(':', '');
|
|
216
|
+
}
|
|
217
|
+
exports.getTimeSeries = getTimeSeries;
|
|
218
|
+
/**
|
|
219
|
+
* @private
|
|
220
|
+
*/
|
|
221
|
+
function formatISODate(input) {
|
|
222
|
+
const date = input instanceof Date ? input : new Date(input);
|
|
223
|
+
return date.toISOString().replace(/[:TZ-]/g, '');
|
|
224
|
+
}
|
|
225
|
+
exports.formatISODate = formatISODate;
|
|
226
|
+
/**
|
|
227
|
+
* @private
|
|
228
|
+
*/
|
|
229
|
+
function getSymKey(number) {
|
|
230
|
+
const alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
231
|
+
const base = alphabet.length;
|
|
232
|
+
if (number < 0 || number >= Math.pow(base, 3)) {
|
|
233
|
+
throw new Error('Number out of range');
|
|
234
|
+
}
|
|
235
|
+
const [q1, r1] = divmod(number, base);
|
|
236
|
+
const [q2, r2] = divmod(q1, base);
|
|
237
|
+
return alphabet[q2] + alphabet[r1] + alphabet[r2];
|
|
238
|
+
}
|
|
239
|
+
exports.getSymKey = getSymKey;
|
|
240
|
+
/**
|
|
241
|
+
* @private
|
|
242
|
+
*/
|
|
243
|
+
function getSymVal(number) {
|
|
244
|
+
const alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
245
|
+
const base = alphabet.length;
|
|
246
|
+
if (number < 0 || number >= Math.pow(base, 2)) {
|
|
247
|
+
throw new Error('Number out of range');
|
|
248
|
+
}
|
|
249
|
+
const [q, r] = divmod(number, base);
|
|
250
|
+
return alphabet[q] + alphabet[r];
|
|
251
|
+
}
|
|
252
|
+
exports.getSymVal = getSymVal;
|
|
253
|
+
/**
|
|
254
|
+
* @private
|
|
255
|
+
*/
|
|
256
|
+
function divmod(m, n) {
|
|
257
|
+
return [Math.floor(m / n), m % n];
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* @private
|
|
261
|
+
*/
|
|
262
|
+
function getIndexedHash(hash, target) {
|
|
263
|
+
const index = hash[target] || 0;
|
|
264
|
+
const newHash = { ...hash };
|
|
265
|
+
delete newHash[target];
|
|
266
|
+
return [index, newHash];
|
|
267
|
+
}
|
|
268
|
+
exports.getIndexedHash = getIndexedHash;
|
|
269
|
+
/**
|
|
270
|
+
* @private
|
|
271
|
+
*/
|
|
272
|
+
function getValueByPath(obj, path) {
|
|
273
|
+
const pathParts = path.split('/');
|
|
274
|
+
let currentValue = obj;
|
|
275
|
+
for (const part of pathParts) {
|
|
276
|
+
if (currentValue[part] !== undefined) {
|
|
277
|
+
currentValue = currentValue[part];
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
return undefined;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return currentValue;
|
|
284
|
+
}
|
|
285
|
+
exports.getValueByPath = getValueByPath;
|
|
286
|
+
/**
|
|
287
|
+
* @private
|
|
288
|
+
*/
|
|
289
|
+
function restoreHierarchy(obj) {
|
|
290
|
+
const result = {};
|
|
291
|
+
for (const key in obj) {
|
|
292
|
+
if (obj[key] === undefined)
|
|
293
|
+
continue;
|
|
294
|
+
const keys = key.split('/');
|
|
295
|
+
let current = result;
|
|
296
|
+
for (let i = 0; i < keys.length; i++) {
|
|
297
|
+
if (i === keys.length - 1) {
|
|
298
|
+
current[keys[i]] = obj[key];
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
current[keys[i]] = current[keys[i]] || {};
|
|
302
|
+
current = current[keys[i]];
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return result;
|
|
307
|
+
}
|
|
308
|
+
exports.restoreHierarchy = restoreHierarchy;
|
|
309
|
+
/**
|
|
310
|
+
* @private
|
|
311
|
+
*/
|
|
312
|
+
function isValidCron(cronExpression) {
|
|
313
|
+
const cronRegex = /^(\*|([0-5]?\d)) (\*|([01]?\d|2[0-3])) (\*|([12]?\d|3[01])) (\*|([1-9]|1[0-2])) (\*|([0-6](?:-[0-6])?(?:,[0-6])?))$/;
|
|
314
|
+
return cronRegex.test(cronExpression);
|
|
315
|
+
}
|
|
316
|
+
exports.isValidCron = isValidCron;
|
|
317
|
+
/**
|
|
318
|
+
* Returns the number of seconds for a string using the milliseconds format
|
|
319
|
+
* used by the `ms` npm package as the input.
|
|
320
|
+
*/
|
|
321
|
+
const s = (input) => {
|
|
322
|
+
return (0, ms_1.default)(input) / 1000;
|
|
323
|
+
};
|
|
324
|
+
exports.s = s;
|
|
325
|
+
/**
|
|
326
|
+
* @private
|
|
327
|
+
*/
|
|
328
|
+
const parseStreamMessage = (message) => {
|
|
329
|
+
try {
|
|
330
|
+
return JSON.parse(message);
|
|
331
|
+
}
|
|
332
|
+
catch (error) {
|
|
333
|
+
logger.error('Error parsing Stream message', { error });
|
|
334
|
+
throw error;
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
exports.parseStreamMessage = parseStreamMessage;
|
|
338
|
+
/**
|
|
339
|
+
* @private
|
|
340
|
+
*/
|
|
341
|
+
const isStreamMessage = (result) => {
|
|
342
|
+
return Array.isArray(result) && Array.isArray(result[0]);
|
|
343
|
+
};
|
|
344
|
+
exports.isStreamMessage = isStreamMessage;
|
|
345
|
+
/**
|
|
346
|
+
* Transforms an array of arrays to an array of objects.
|
|
347
|
+
*/
|
|
348
|
+
const arrayToHash = (response) => {
|
|
349
|
+
const results = [];
|
|
350
|
+
let key;
|
|
351
|
+
for (let i = 1; i < response.length; i++) {
|
|
352
|
+
// ignore count
|
|
353
|
+
const row = response[i];
|
|
354
|
+
const result = {};
|
|
355
|
+
if (Array.isArray(row)) {
|
|
356
|
+
// Check if row is an array
|
|
357
|
+
for (let j = 0; j < row.length; j += 2) {
|
|
358
|
+
const key = row[j];
|
|
359
|
+
const value = row[j + 1];
|
|
360
|
+
result[key] = value;
|
|
361
|
+
}
|
|
362
|
+
if (key) {
|
|
363
|
+
result.$ = key;
|
|
364
|
+
}
|
|
365
|
+
results.push(result);
|
|
366
|
+
key = undefined;
|
|
367
|
+
}
|
|
368
|
+
else {
|
|
369
|
+
key = row;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
return results;
|
|
373
|
+
};
|
|
374
|
+
exports.arrayToHash = arrayToHash;
|
package/build/package.json
CHANGED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { EngineService } from '../engine';
|
|
2
|
+
import { ILogger } from '../logger';
|
|
3
|
+
import { StoreService } from '../store';
|
|
4
|
+
import { TelemetryService } from '../telemetry';
|
|
5
|
+
import { ActivityData, ActivityLeg, ActivityMetadata, ActivityType } from '../../types/activity';
|
|
6
|
+
import { ProviderClient, ProviderTransaction, TransactionResultList } from '../../types/provider';
|
|
7
|
+
import { JobState, JobStatus } from '../../types/job';
|
|
8
|
+
import { StringAnyType } from '../../types/serializer';
|
|
9
|
+
import { StreamCode, StreamData, StreamStatus } from '../../types/stream';
|
|
10
|
+
/**
|
|
11
|
+
* The base class for all activities
|
|
12
|
+
*/
|
|
13
|
+
declare class Activity {
|
|
14
|
+
config: ActivityType;
|
|
15
|
+
data: ActivityData;
|
|
16
|
+
hook: ActivityData;
|
|
17
|
+
metadata: ActivityMetadata;
|
|
18
|
+
store: StoreService<ProviderClient, ProviderTransaction>;
|
|
19
|
+
context: JobState;
|
|
20
|
+
engine: EngineService;
|
|
21
|
+
logger: ILogger;
|
|
22
|
+
status: StreamStatus;
|
|
23
|
+
code: StreamCode;
|
|
24
|
+
leg: ActivityLeg;
|
|
25
|
+
adjacencyList: StreamData[];
|
|
26
|
+
adjacentIndex: number;
|
|
27
|
+
constructor(config: ActivityType, data: ActivityData, metadata: ActivityMetadata, hook: ActivityData | null, engine: EngineService, context?: JobState);
|
|
28
|
+
setLeg(leg: ActivityLeg): void;
|
|
29
|
+
/**
|
|
30
|
+
* A job is assumed to be complete when its status (a semaphore)
|
|
31
|
+
* reaches `0`. A different threshold can be set in the
|
|
32
|
+
* activity YAML, in support of Dynamic Activation Control.
|
|
33
|
+
*/
|
|
34
|
+
mapStatusThreshold(): number;
|
|
35
|
+
/**
|
|
36
|
+
* Upon entering leg 1 of a duplexed activity
|
|
37
|
+
*/
|
|
38
|
+
verifyEntry(): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Upon entering leg 2 of a duplexed activity
|
|
41
|
+
*/
|
|
42
|
+
verifyReentry(): Promise<number>;
|
|
43
|
+
processEvent(status?: StreamStatus, code?: StreamCode, type?: 'hook' | 'output'): Promise<void>;
|
|
44
|
+
processPending(type: 'hook' | 'output'): Promise<TransactionResultList>;
|
|
45
|
+
processSuccess(type: 'hook' | 'output'): Promise<TransactionResultList>;
|
|
46
|
+
processError(): Promise<TransactionResultList>;
|
|
47
|
+
transitionAdjacent(multiResponse: TransactionResultList, telemetry: TelemetryService): Promise<void>;
|
|
48
|
+
resolveStatus(multiResponse: TransactionResultList): number;
|
|
49
|
+
mapJobData(): void;
|
|
50
|
+
mapInputData(): void;
|
|
51
|
+
mapOutputData(): void;
|
|
52
|
+
registerTimeout(): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Any StreamMessage with a status of ERROR is bound to the activity
|
|
55
|
+
*/
|
|
56
|
+
bindActivityError(data: Record<string, unknown>): void;
|
|
57
|
+
/**
|
|
58
|
+
* unhandled activity errors (activities that return an ERROR StreamMessage
|
|
59
|
+
* status and have no adjacent children to transition to) are bound to the job
|
|
60
|
+
*/
|
|
61
|
+
bindJobError(data: Record<string, unknown>): void;
|
|
62
|
+
getTriggerConfig(): Promise<ActivityType>;
|
|
63
|
+
getJobStatus(): null | number;
|
|
64
|
+
setStatus(amount: number, transaction?: ProviderTransaction): Promise<void | any>;
|
|
65
|
+
authorizeEntry(state: StringAnyType): string[];
|
|
66
|
+
bindDimensionalAddress(state: StringAnyType): void;
|
|
67
|
+
setState(transaction?: ProviderTransaction): Promise<string>;
|
|
68
|
+
bindJobMetadata(): void;
|
|
69
|
+
bindActivityMetadata(): void;
|
|
70
|
+
bindJobState(state: StringAnyType): Promise<void>;
|
|
71
|
+
bindActivityState(state: StringAnyType): void;
|
|
72
|
+
bindJobMetadataPaths(): string[];
|
|
73
|
+
bindActivityMetadataPaths(): string[];
|
|
74
|
+
getState(): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* if the job is created/deleted/created with the same key,
|
|
77
|
+
* the 'gid' ensures no stale messages (such as sleep delays)
|
|
78
|
+
* enter the workstream. Any message with a mismatched gid
|
|
79
|
+
* belongs to a prior job and can safely be ignored/dropped.
|
|
80
|
+
*/
|
|
81
|
+
assertGenerationalId(jobGID: string, msgGID?: string): void;
|
|
82
|
+
initDimensionalAddress(dad: string): void;
|
|
83
|
+
initSelf(context: StringAnyType): JobState;
|
|
84
|
+
initPolicies(context: JobState): void;
|
|
85
|
+
bindActivityData(type: 'output' | 'hook'): void;
|
|
86
|
+
resolveDad(): string;
|
|
87
|
+
resolveAdjacentDad(): string;
|
|
88
|
+
filterAdjacent(): Promise<StreamData[]>;
|
|
89
|
+
isJobComplete(jobStatus: JobStatus): boolean;
|
|
90
|
+
shouldEmit(): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* emits the job completed event while leaving the job active, allowing
|
|
93
|
+
* a `main` thread to exit while other threads continue to run.
|
|
94
|
+
* @private
|
|
95
|
+
*/
|
|
96
|
+
shouldPersistJob(): boolean;
|
|
97
|
+
transition(adjacencyList: StreamData[], jobStatus: JobStatus): Promise<string[]>;
|
|
98
|
+
/**
|
|
99
|
+
* A job with a vale < -100_000_000 is considered interrupted,
|
|
100
|
+
* as the interruption event decrements the job status by 1billion.
|
|
101
|
+
*/
|
|
102
|
+
jobWasInterrupted(jobStatus: JobStatus): boolean;
|
|
103
|
+
}
|
|
104
|
+
export { Activity, ActivityType };
|