@hotmeshio/hotmesh 0.3.5 → 0.3.7
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/index.d.ts +6 -4
- package/build/index.js +13 -5
- package/build/modules/key.js +1 -62
- package/build/modules/utils.d.ts +1 -0
- package/build/modules/utils.js +1 -242
- package/build/package.json +14 -9
- package/build/services/activities/activity.js +1 -495
- package/build/services/activities/await.js +1 -109
- package/build/services/activities/cycle.js +1 -96
- package/build/services/activities/hook.js +1 -154
- package/build/services/activities/index.js +1 -20
- package/build/services/activities/interrupt.js +1 -149
- package/build/services/activities/signal.js +1 -118
- package/build/services/activities/trigger.d.ts +0 -1
- package/build/services/activities/trigger.js +1 -269
- package/build/services/activities/worker.js +1 -101
- package/build/services/collator/index.js +1 -197
- package/build/services/compiler/deployer.d.ts +3 -1
- package/build/services/compiler/deployer.js +1 -455
- package/build/services/compiler/index.d.ts +3 -1
- package/build/services/compiler/index.js +1 -91
- package/build/services/compiler/validator.js +1 -122
- package/build/services/engine/index.d.ts +5 -2
- package/build/services/engine/index.js +1 -583
- package/build/services/exporter/index.js +1 -93
- package/build/services/mapper/index.js +1 -67
- package/build/services/meshdata/index.d.ts +0 -1
- package/build/services/meshdata/index.js +16 -24
- package/build/services/meshflow/client.js +4 -8
- package/build/services/meshflow/exporter.js +1 -186
- package/build/services/meshflow/search.d.ts +4 -5
- package/build/services/meshflow/search.js +48 -36
- package/build/services/meshflow/worker.js +1 -1
- package/build/services/meshflow/workflow.d.ts +1 -1
- package/build/services/meshflow/workflow.js +5 -30
- package/build/services/meshos/index.d.ts +81 -0
- package/build/services/meshos/index.js +339 -0
- package/build/services/pipe/functions/array.js +1 -74
- package/build/services/pipe/functions/bitwise.js +1 -24
- package/build/services/pipe/functions/conditional.js +1 -36
- package/build/services/pipe/functions/cron.js +1 -32
- package/build/services/pipe/functions/date.js +1 -164
- package/build/services/pipe/functions/index.js +1 -30
- package/build/services/pipe/functions/json.js +1 -12
- package/build/services/pipe/functions/logical.js +1 -12
- package/build/services/pipe/functions/math.js +1 -182
- package/build/services/pipe/functions/number.js +1 -60
- package/build/services/pipe/functions/object.js +1 -81
- package/build/services/pipe/functions/string.js +1 -69
- package/build/services/pipe/functions/symbol.js +1 -33
- package/build/services/pipe/functions/unary.js +1 -18
- package/build/services/pipe/index.js +1 -221
- package/build/services/quorum/index.d.ts +1 -1
- package/build/services/quorum/index.js +1 -233
- package/build/services/reporter/index.js +1 -331
- package/build/services/router/index.js +1 -420
- package/build/services/search/factory.d.ts +7 -0
- package/build/services/search/factory.js +20 -0
- package/build/services/search/index.d.ts +21 -0
- package/build/services/search/index.js +10 -0
- package/build/services/search/providers/redis/ioredis.d.ts +18 -0
- package/build/services/search/providers/redis/ioredis.js +1 -0
- package/build/services/search/providers/redis/redis.d.ts +18 -0
- package/build/services/search/providers/redis/redis.js +1 -0
- package/build/services/serializer/index.js +1 -265
- package/build/services/store/factory.d.ts +8 -0
- package/build/services/store/factory.js +20 -0
- package/build/services/store/index.d.ts +71 -98
- package/build/services/store/index.js +2 -941
- package/build/services/store/providers/postgres/postgres.d.ts +0 -0
- package/build/services/store/providers/postgres/postgres.js +0 -0
- package/build/services/store/providers/postgres/types/hash.d.ts +0 -0
- package/build/services/store/providers/postgres/types/hash.js +0 -0
- package/build/services/store/providers/postgres/types/list.d.ts +0 -0
- package/build/services/store/providers/postgres/types/list.js +0 -0
- package/build/services/store/providers/postgres/types/string.d.ts +0 -0
- package/build/services/store/providers/postgres/types/string.js +0 -0
- package/build/services/store/providers/postgres/types/zset.d.ts +0 -0
- package/build/services/store/providers/postgres/types/zset.js +0 -0
- package/build/services/store/providers/redis/_base.d.ts +98 -0
- package/build/services/store/providers/redis/_base.js +1 -0
- package/build/services/store/providers/redis/ioredis.d.ts +12 -0
- package/build/services/store/providers/redis/ioredis.js +1 -0
- package/build/services/store/providers/redis/redis.d.ts +13 -0
- package/build/services/store/providers/redis/redis.js +1 -0
- package/build/services/store/providers/store-initializable.d.ts +5 -0
- package/build/services/store/providers/store-initializable.js +1 -0
- package/build/services/stream/factory.d.ts +8 -0
- package/build/services/stream/factory.js +20 -0
- package/build/services/stream/index.d.ts +13 -14
- package/build/services/stream/index.js +3 -2
- package/build/services/stream/providers/postgres/_deploy.d.ts +4 -0
- package/build/services/stream/providers/postgres/_deploy.js +1 -0
- package/build/services/stream/providers/redis/ioredis.d.ts +21 -0
- package/build/services/stream/providers/redis/ioredis.js +1 -0
- package/build/services/stream/providers/redis/redis.d.ts +21 -0
- package/build/services/stream/providers/redis/redis.js +1 -0
- package/build/services/stream/providers/stream-initializable.d.ts +5 -0
- package/build/services/stream/providers/stream-initializable.js +1 -0
- package/build/services/sub/factory.d.ts +7 -0
- package/build/services/sub/factory.js +20 -0
- package/build/services/sub/index.d.ts +9 -7
- package/build/services/sub/index.js +3 -2
- package/build/services/sub/{clients → providers/redis}/ioredis.d.ts +7 -10
- package/build/services/sub/providers/redis/ioredis.js +1 -0
- package/build/services/sub/{clients → providers/redis}/redis.d.ts +7 -10
- package/build/services/sub/providers/redis/redis.js +1 -0
- package/build/services/task/index.js +1 -171
- package/build/services/telemetry/index.js +1 -225
- package/build/services/worker/index.d.ts +2 -2
- package/build/services/worker/index.js +1 -179
- package/build/types/index.d.ts +1 -0
- package/build/types/manifest.d.ts +49 -0
- package/build/types/manifest.js +2 -0
- package/build/types/redis.d.ts +5 -5
- package/index.ts +19 -4
- package/package.json +14 -9
- package/typedoc.json +1 -0
- package/types/index.ts +15 -0
- package/types/manifest.ts +68 -0
- package/types/meshflow.ts +1 -1
- package/types/redis.ts +5 -5
- package/build/services/store/clients/ioredis.d.ts +0 -30
- package/build/services/store/clients/ioredis.js +0 -220
- package/build/services/store/clients/redis.d.ts +0 -32
- package/build/services/store/clients/redis.js +0 -319
- package/build/services/stream/clients/ioredis.d.ts +0 -24
- package/build/services/stream/clients/ioredis.js +0 -121
- package/build/services/stream/clients/redis.d.ts +0 -24
- package/build/services/stream/clients/redis.js +0 -161
- package/build/services/sub/clients/ioredis.js +0 -72
- package/build/services/sub/clients/redis.js +0 -63
|
@@ -1,583 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.EngineService = void 0;
|
|
7
|
-
const key_1 = require("../../modules/key");
|
|
8
|
-
const enums_1 = require("../../modules/enums");
|
|
9
|
-
const utils_1 = require("../../modules/utils");
|
|
10
|
-
const activities_1 = __importDefault(require("../activities"));
|
|
11
|
-
const compiler_1 = require("../compiler");
|
|
12
|
-
const exporter_1 = require("../exporter");
|
|
13
|
-
const reporter_1 = require("../reporter");
|
|
14
|
-
const router_1 = require("../router");
|
|
15
|
-
const serializer_1 = require("../serializer");
|
|
16
|
-
const redis_1 = require("../store/clients/redis");
|
|
17
|
-
const ioredis_1 = require("../store/clients/ioredis");
|
|
18
|
-
const redis_2 = require("../stream/clients/redis");
|
|
19
|
-
const ioredis_2 = require("../stream/clients/ioredis");
|
|
20
|
-
const ioredis_3 = require("../sub/clients/ioredis");
|
|
21
|
-
const redis_3 = require("../sub/clients/redis");
|
|
22
|
-
const task_1 = require("../task");
|
|
23
|
-
const stream_1 = require("../../types/stream");
|
|
24
|
-
class EngineService {
|
|
25
|
-
constructor() {
|
|
26
|
-
this.cacheMode = 'cache';
|
|
27
|
-
this.untilVersion = null;
|
|
28
|
-
this.jobCallbacks = {};
|
|
29
|
-
this.reporting = false;
|
|
30
|
-
this.jobId = 1;
|
|
31
|
-
}
|
|
32
|
-
static async init(namespace, appId, guid, config, logger) {
|
|
33
|
-
if (config.engine) {
|
|
34
|
-
const instance = new EngineService();
|
|
35
|
-
instance.verifyEngineFields(config);
|
|
36
|
-
instance.namespace = namespace;
|
|
37
|
-
instance.appId = appId;
|
|
38
|
-
instance.guid = guid;
|
|
39
|
-
instance.logger = logger;
|
|
40
|
-
await instance.initStoreChannel(config.engine.store);
|
|
41
|
-
await instance.initSubChannel(config.engine.sub);
|
|
42
|
-
await instance.initStreamChannel(config.engine.stream);
|
|
43
|
-
instance.router = await instance.initRouter(config);
|
|
44
|
-
instance.router.consumeMessages(instance.stream.mintKey(key_1.KeyType.STREAMS, { appId: instance.appId }), 'ENGINE', instance.guid, instance.processStreamMessage.bind(instance));
|
|
45
|
-
instance.taskService = new task_1.TaskService(instance.store, logger);
|
|
46
|
-
instance.exporter = new exporter_1.ExporterService(instance.appId, instance.store, logger);
|
|
47
|
-
instance.inited = (0, utils_1.formatISODate)(new Date());
|
|
48
|
-
return instance;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
verifyEngineFields(config) {
|
|
52
|
-
if (!(0, utils_1.identifyRedisType)(config.engine.store) ||
|
|
53
|
-
!(0, utils_1.identifyRedisType)(config.engine.stream) ||
|
|
54
|
-
!(0, utils_1.identifyRedisType)(config.engine.sub)) {
|
|
55
|
-
throw new Error('engine config must reference 3 redis client instances');
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
async initStoreChannel(store) {
|
|
59
|
-
if ((0, utils_1.identifyRedisType)(store) === 'redis') {
|
|
60
|
-
this.store = new redis_1.RedisStoreService(store);
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
this.store = new ioredis_1.IORedisStoreService(store);
|
|
64
|
-
}
|
|
65
|
-
await this.store.init(this.namespace, this.appId, this.logger);
|
|
66
|
-
}
|
|
67
|
-
async initSubChannel(sub) {
|
|
68
|
-
if ((0, utils_1.identifyRedisType)(sub) === 'redis') {
|
|
69
|
-
this.subscribe = new redis_3.RedisSubService(sub);
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
this.subscribe = new ioredis_3.IORedisSubService(sub);
|
|
73
|
-
}
|
|
74
|
-
await this.subscribe.init(this.namespace, this.appId, this.guid, this.logger);
|
|
75
|
-
}
|
|
76
|
-
async initStreamChannel(stream) {
|
|
77
|
-
if ((0, utils_1.identifyRedisType)(stream) === 'redis') {
|
|
78
|
-
this.stream = new redis_2.RedisStreamService(stream);
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
this.stream = new ioredis_2.IORedisStreamService(stream);
|
|
82
|
-
}
|
|
83
|
-
await this.stream.init(this.namespace, this.appId, this.logger);
|
|
84
|
-
}
|
|
85
|
-
async initRouter(config) {
|
|
86
|
-
const throttle = await this.store.getThrottleRate(':');
|
|
87
|
-
return new router_1.Router({
|
|
88
|
-
namespace: this.namespace,
|
|
89
|
-
appId: this.appId,
|
|
90
|
-
guid: this.guid,
|
|
91
|
-
role: stream_1.StreamRole.ENGINE,
|
|
92
|
-
reclaimDelay: config.engine.reclaimDelay,
|
|
93
|
-
reclaimCount: config.engine.reclaimCount,
|
|
94
|
-
throttle,
|
|
95
|
-
readonly: config.engine.readonly,
|
|
96
|
-
}, this.stream, this.store, this.logger);
|
|
97
|
-
}
|
|
98
|
-
async fetchAndVerifyVID(vid, count = 0) {
|
|
99
|
-
if (isNaN(Number(vid.version))) {
|
|
100
|
-
const app = await this.store.getApp(vid.id, true);
|
|
101
|
-
if (!isNaN(Number(app.version))) {
|
|
102
|
-
if (!this.apps)
|
|
103
|
-
this.apps = {};
|
|
104
|
-
this.apps[vid.id] = app;
|
|
105
|
-
return { id: vid.id, version: app.version };
|
|
106
|
-
}
|
|
107
|
-
else if (count < 10) {
|
|
108
|
-
await (0, utils_1.sleepFor)(enums_1.HMSH_QUORUM_DELAY_MS * 2);
|
|
109
|
-
return await this.fetchAndVerifyVID(vid, count + 1);
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
this.logger.error('engine-vid-resolution-error', {
|
|
113
|
-
id: vid.id,
|
|
114
|
-
guid: this.guid,
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
return vid;
|
|
119
|
-
}
|
|
120
|
-
async getVID(vid) {
|
|
121
|
-
if (this.cacheMode === 'nocache') {
|
|
122
|
-
const app = await this.store.getApp(this.appId, true);
|
|
123
|
-
if (app.version.toString() === this.untilVersion.toString()) {
|
|
124
|
-
if (!this.apps)
|
|
125
|
-
this.apps = {};
|
|
126
|
-
this.apps[this.appId] = app;
|
|
127
|
-
this.setCacheMode('cache', app.version.toString());
|
|
128
|
-
}
|
|
129
|
-
return { id: this.appId, version: app.version };
|
|
130
|
-
}
|
|
131
|
-
else if (!this.apps && vid) {
|
|
132
|
-
this.apps = {};
|
|
133
|
-
this.apps[this.appId] = vid;
|
|
134
|
-
return vid;
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
return await this.fetchAndVerifyVID({
|
|
138
|
-
id: this.appId,
|
|
139
|
-
version: this.apps?.[this.appId].version,
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
setCacheMode(cacheMode, untilVersion) {
|
|
144
|
-
this.logger.info(`engine-executable-cache`, {
|
|
145
|
-
mode: cacheMode,
|
|
146
|
-
[cacheMode === 'cache' ? 'target' : 'until']: untilVersion,
|
|
147
|
-
});
|
|
148
|
-
this.cacheMode = cacheMode;
|
|
149
|
-
this.untilVersion = untilVersion;
|
|
150
|
-
}
|
|
151
|
-
async routeToSubscribers(topic, message) {
|
|
152
|
-
const jobCallback = this.jobCallbacks[message.metadata.jid];
|
|
153
|
-
if (jobCallback) {
|
|
154
|
-
this.delistJobCallback(message.metadata.jid);
|
|
155
|
-
jobCallback(topic, message);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
async processWebHooks() {
|
|
159
|
-
this.taskService.processWebHooks(this.hook.bind(this));
|
|
160
|
-
}
|
|
161
|
-
async processTimeHooks() {
|
|
162
|
-
this.taskService.processTimeHooks(this.hookTime.bind(this));
|
|
163
|
-
}
|
|
164
|
-
async throttle(delayInMillis) {
|
|
165
|
-
try {
|
|
166
|
-
this.router.setThrottle(delayInMillis);
|
|
167
|
-
}
|
|
168
|
-
catch (e) {
|
|
169
|
-
this.logger.error('engine-throttle-error', { error: e });
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
async initActivity(topic, data = {}, context) {
|
|
173
|
-
const [activityId, schema] = await this.getSchema(topic);
|
|
174
|
-
const ActivityHandler = activities_1.default[utils_1.polyfill.resolveActivityType(schema.type)];
|
|
175
|
-
if (ActivityHandler) {
|
|
176
|
-
const utc = (0, utils_1.formatISODate)(new Date());
|
|
177
|
-
const metadata = {
|
|
178
|
-
aid: activityId,
|
|
179
|
-
atp: schema.type,
|
|
180
|
-
stp: schema.subtype,
|
|
181
|
-
ac: utc,
|
|
182
|
-
au: utc,
|
|
183
|
-
};
|
|
184
|
-
const hook = null;
|
|
185
|
-
return new ActivityHandler(schema, data, metadata, hook, this, context);
|
|
186
|
-
}
|
|
187
|
-
else {
|
|
188
|
-
throw new Error(`activity type ${schema.type} not found`);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
async getSchema(topic) {
|
|
192
|
-
const app = (await this.store.getApp(this.appId));
|
|
193
|
-
if (!app) {
|
|
194
|
-
throw new Error(`no app found for id ${this.appId}`);
|
|
195
|
-
}
|
|
196
|
-
if (this.isPrivate(topic)) {
|
|
197
|
-
const activityId = topic.substring(1);
|
|
198
|
-
const schema = await this.store.getSchema(activityId, await this.getVID(app));
|
|
199
|
-
return [activityId, schema];
|
|
200
|
-
}
|
|
201
|
-
else {
|
|
202
|
-
const activityId = await this.store.getSubscription(topic, await this.getVID(app));
|
|
203
|
-
if (activityId) {
|
|
204
|
-
const schema = await this.store.getSchema(activityId, await this.getVID(app));
|
|
205
|
-
return [activityId, schema];
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
throw new Error(`no subscription found for topic ${topic} in app ${this.appId} for app version ${app.version}`);
|
|
209
|
-
}
|
|
210
|
-
async getSettings() {
|
|
211
|
-
return await this.store.getSettings();
|
|
212
|
-
}
|
|
213
|
-
isPrivate(topic) {
|
|
214
|
-
return topic.startsWith('.');
|
|
215
|
-
}
|
|
216
|
-
async plan(pathOrYAML) {
|
|
217
|
-
const compiler = new compiler_1.CompilerService(this.store, this.logger);
|
|
218
|
-
return await compiler.plan(pathOrYAML);
|
|
219
|
-
}
|
|
220
|
-
async deploy(pathOrYAML) {
|
|
221
|
-
const compiler = new compiler_1.CompilerService(this.store, this.logger);
|
|
222
|
-
return await compiler.deploy(pathOrYAML);
|
|
223
|
-
}
|
|
224
|
-
async getStats(topic, query) {
|
|
225
|
-
const { id, version } = await this.getVID();
|
|
226
|
-
const reporter = new reporter_1.ReporterService({ id, version }, this.store, this.logger);
|
|
227
|
-
const resolvedQuery = await this.resolveQuery(topic, query);
|
|
228
|
-
return await reporter.getStats(resolvedQuery);
|
|
229
|
-
}
|
|
230
|
-
async getIds(topic, query, queryFacets = []) {
|
|
231
|
-
const { id, version } = await this.getVID();
|
|
232
|
-
const reporter = new reporter_1.ReporterService({ id, version }, this.store, this.logger);
|
|
233
|
-
const resolvedQuery = await this.resolveQuery(topic, query);
|
|
234
|
-
return await reporter.getIds(resolvedQuery, queryFacets);
|
|
235
|
-
}
|
|
236
|
-
async resolveQuery(topic, query) {
|
|
237
|
-
const trigger = (await this.initActivity(topic, query.data));
|
|
238
|
-
await trigger.getState();
|
|
239
|
-
return {
|
|
240
|
-
end: query.end,
|
|
241
|
-
start: query.start,
|
|
242
|
-
range: query.range,
|
|
243
|
-
granularity: trigger.resolveGranularity(),
|
|
244
|
-
key: trigger.resolveJobKey(trigger.createInputContext()),
|
|
245
|
-
sparse: query.sparse,
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
async processStreamMessage(streamData) {
|
|
249
|
-
this.logger.debug('engine-process', {
|
|
250
|
-
jid: streamData.metadata.jid,
|
|
251
|
-
gid: streamData.metadata.gid,
|
|
252
|
-
dad: streamData.metadata.dad,
|
|
253
|
-
aid: streamData.metadata.aid,
|
|
254
|
-
status: streamData.status || stream_1.StreamStatus.SUCCESS,
|
|
255
|
-
code: streamData.code || 200,
|
|
256
|
-
type: streamData.type,
|
|
257
|
-
});
|
|
258
|
-
const context = {
|
|
259
|
-
metadata: {
|
|
260
|
-
guid: streamData.metadata.guid,
|
|
261
|
-
jid: streamData.metadata.jid,
|
|
262
|
-
gid: streamData.metadata.gid,
|
|
263
|
-
dad: streamData.metadata.dad,
|
|
264
|
-
aid: streamData.metadata.aid,
|
|
265
|
-
},
|
|
266
|
-
data: streamData.data,
|
|
267
|
-
};
|
|
268
|
-
if (streamData.type === stream_1.StreamDataType.TIMEHOOK) {
|
|
269
|
-
const activityHandler = (await this.initActivity(`.${streamData.metadata.aid}`, context.data, context));
|
|
270
|
-
await activityHandler.processTimeHookEvent(streamData.metadata.jid);
|
|
271
|
-
}
|
|
272
|
-
else if (streamData.type === stream_1.StreamDataType.WEBHOOK) {
|
|
273
|
-
const activityHandler = (await this.initActivity(`.${streamData.metadata.aid}`, context.data, context));
|
|
274
|
-
await activityHandler.processWebHookEvent(streamData.status, streamData.code);
|
|
275
|
-
}
|
|
276
|
-
else if (streamData.type === stream_1.StreamDataType.TRANSITION) {
|
|
277
|
-
const activityHandler = (await this.initActivity(`.${streamData.metadata.aid}`, context.data, context));
|
|
278
|
-
await activityHandler.process();
|
|
279
|
-
}
|
|
280
|
-
else if (streamData.type === stream_1.StreamDataType.AWAIT) {
|
|
281
|
-
context.metadata = {
|
|
282
|
-
...context.metadata,
|
|
283
|
-
pj: streamData.metadata.jid,
|
|
284
|
-
pg: streamData.metadata.gid,
|
|
285
|
-
pd: streamData.metadata.dad,
|
|
286
|
-
pa: streamData.metadata.aid,
|
|
287
|
-
px: streamData.metadata.await === false,
|
|
288
|
-
trc: streamData.metadata.trc,
|
|
289
|
-
spn: streamData.metadata.spn,
|
|
290
|
-
};
|
|
291
|
-
const activityHandler = (await this.initActivity(streamData.metadata.topic, streamData.data, context));
|
|
292
|
-
await activityHandler.process();
|
|
293
|
-
}
|
|
294
|
-
else if (streamData.type === stream_1.StreamDataType.RESULT) {
|
|
295
|
-
const activityHandler = (await this.initActivity(`.${context.metadata.aid}`, streamData.data, context));
|
|
296
|
-
await activityHandler.processEvent(streamData.status, streamData.code);
|
|
297
|
-
}
|
|
298
|
-
else {
|
|
299
|
-
const activityHandler = (await this.initActivity(`.${streamData.metadata.aid}`, streamData.data, context));
|
|
300
|
-
await activityHandler.processEvent(streamData.status, streamData.code, 'output');
|
|
301
|
-
}
|
|
302
|
-
this.logger.debug('engine-process-end', {
|
|
303
|
-
jid: streamData.metadata.jid,
|
|
304
|
-
gid: streamData.metadata.gid,
|
|
305
|
-
aid: streamData.metadata.aid,
|
|
306
|
-
});
|
|
307
|
-
}
|
|
308
|
-
async execAdjacentParent(context, jobOutput, emit = false) {
|
|
309
|
-
if (this.hasParentJob(context)) {
|
|
310
|
-
const error = this.resolveError(jobOutput.metadata);
|
|
311
|
-
const spn = context['$self']?.output?.metadata?.l2s ||
|
|
312
|
-
context['$self']?.output?.metadata?.l1s;
|
|
313
|
-
const streamData = {
|
|
314
|
-
metadata: {
|
|
315
|
-
guid: (0, utils_1.guid)(),
|
|
316
|
-
jid: context.metadata.pj,
|
|
317
|
-
gid: context.metadata.pg,
|
|
318
|
-
dad: context.metadata.pd,
|
|
319
|
-
aid: context.metadata.pa,
|
|
320
|
-
trc: context.metadata.trc,
|
|
321
|
-
spn,
|
|
322
|
-
},
|
|
323
|
-
type: stream_1.StreamDataType.RESULT,
|
|
324
|
-
data: jobOutput.data,
|
|
325
|
-
};
|
|
326
|
-
if (error && error.code) {
|
|
327
|
-
streamData.status = stream_1.StreamStatus.ERROR;
|
|
328
|
-
streamData.data = error;
|
|
329
|
-
streamData.code = error.code;
|
|
330
|
-
streamData.stack = error.stack;
|
|
331
|
-
}
|
|
332
|
-
else if (emit) {
|
|
333
|
-
streamData.status = stream_1.StreamStatus.PENDING;
|
|
334
|
-
streamData.code = enums_1.HMSH_CODE_PENDING;
|
|
335
|
-
}
|
|
336
|
-
else {
|
|
337
|
-
streamData.status = stream_1.StreamStatus.SUCCESS;
|
|
338
|
-
streamData.code = enums_1.HMSH_CODE_SUCCESS;
|
|
339
|
-
}
|
|
340
|
-
return (await this.router?.publishMessage(null, streamData));
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
hasParentJob(context, checkSevered = false) {
|
|
344
|
-
if (checkSevered) {
|
|
345
|
-
return Boolean(context.metadata.pj && context.metadata.pa && !context.metadata.px);
|
|
346
|
-
}
|
|
347
|
-
return Boolean(context.metadata.pj && context.metadata.pa);
|
|
348
|
-
}
|
|
349
|
-
resolveError(metadata) {
|
|
350
|
-
if (metadata && metadata.err) {
|
|
351
|
-
return JSON.parse(metadata.err);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
async interrupt(topic, jobId, options = {}) {
|
|
355
|
-
await this.store.interrupt(topic, jobId, options);
|
|
356
|
-
const context = (await this.getState(topic, jobId));
|
|
357
|
-
const completionOpts = {
|
|
358
|
-
interrupt: options.descend,
|
|
359
|
-
expire: options.expire,
|
|
360
|
-
};
|
|
361
|
-
return (await this.runJobCompletionTasks(context, completionOpts));
|
|
362
|
-
}
|
|
363
|
-
async scrub(jobId) {
|
|
364
|
-
await this.store.scrub(jobId);
|
|
365
|
-
}
|
|
366
|
-
async hook(topic, data, status = stream_1.StreamStatus.SUCCESS, code = 200) {
|
|
367
|
-
const hookRule = await this.taskService.getHookRule(topic);
|
|
368
|
-
const [aid] = await this.getSchema(`.${hookRule.to}`);
|
|
369
|
-
const streamData = {
|
|
370
|
-
type: stream_1.StreamDataType.WEBHOOK,
|
|
371
|
-
status,
|
|
372
|
-
code,
|
|
373
|
-
metadata: {
|
|
374
|
-
guid: (0, utils_1.guid)(),
|
|
375
|
-
aid,
|
|
376
|
-
topic,
|
|
377
|
-
},
|
|
378
|
-
data,
|
|
379
|
-
};
|
|
380
|
-
return (await this.router.publishMessage(null, streamData));
|
|
381
|
-
}
|
|
382
|
-
async hookTime(jobId, gId, topicOrActivity, type) {
|
|
383
|
-
if (type === 'interrupt' || type === 'expire') {
|
|
384
|
-
return await this.interrupt(topicOrActivity, jobId, {
|
|
385
|
-
suppress: true,
|
|
386
|
-
expire: 1,
|
|
387
|
-
});
|
|
388
|
-
}
|
|
389
|
-
const [aid, ...dimensions] = topicOrActivity.split(',');
|
|
390
|
-
const dad = `,${dimensions.join(',')}`;
|
|
391
|
-
const streamData = {
|
|
392
|
-
type: stream_1.StreamDataType.TIMEHOOK,
|
|
393
|
-
metadata: {
|
|
394
|
-
guid: (0, utils_1.guid)(),
|
|
395
|
-
jid: jobId,
|
|
396
|
-
gid: gId,
|
|
397
|
-
dad,
|
|
398
|
-
aid,
|
|
399
|
-
},
|
|
400
|
-
data: { timestamp: Date.now() },
|
|
401
|
-
};
|
|
402
|
-
await this.router.publishMessage(null, streamData);
|
|
403
|
-
}
|
|
404
|
-
async hookAll(hookTopic, data, keyResolver, queryFacets = []) {
|
|
405
|
-
const config = await this.getVID();
|
|
406
|
-
const hookRule = await this.taskService.getHookRule(hookTopic);
|
|
407
|
-
if (hookRule) {
|
|
408
|
-
const subscriptionTopic = await (0, utils_1.getSubscriptionTopic)(hookRule.to, this.store, config);
|
|
409
|
-
const resolvedQuery = await this.resolveQuery(subscriptionTopic, keyResolver);
|
|
410
|
-
const reporter = new reporter_1.ReporterService(config, this.store, this.logger);
|
|
411
|
-
const workItems = await reporter.getWorkItems(resolvedQuery, queryFacets);
|
|
412
|
-
if (workItems.length) {
|
|
413
|
-
const taskService = new task_1.TaskService(this.store, this.logger);
|
|
414
|
-
await taskService.enqueueWorkItems(workItems.map((workItem) => [
|
|
415
|
-
hookTopic,
|
|
416
|
-
workItem,
|
|
417
|
-
keyResolver.scrub || false,
|
|
418
|
-
JSON.stringify(data),
|
|
419
|
-
].join(key_1.VALSEP)));
|
|
420
|
-
this.store.publish(key_1.KeyType.QUORUM, { type: 'work', originator: this.guid }, this.appId);
|
|
421
|
-
}
|
|
422
|
-
return workItems;
|
|
423
|
-
}
|
|
424
|
-
else {
|
|
425
|
-
throw new Error(`unable to find hook rule for topic ${hookTopic}`);
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
async pub(topic, data, context, extended) {
|
|
429
|
-
const activityHandler = await this.initActivity(topic, data, context);
|
|
430
|
-
if (activityHandler) {
|
|
431
|
-
return await activityHandler.process(extended);
|
|
432
|
-
}
|
|
433
|
-
else {
|
|
434
|
-
throw new Error(`unable to process activity for topic ${topic}`);
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
async sub(topic, callback) {
|
|
438
|
-
const subscriptionCallback = async (topic, message) => {
|
|
439
|
-
callback(message.topic, message.job);
|
|
440
|
-
};
|
|
441
|
-
return await this.subscribe.subscribe(key_1.KeyType.QUORUM, subscriptionCallback, this.appId, topic);
|
|
442
|
-
}
|
|
443
|
-
async unsub(topic) {
|
|
444
|
-
return await this.subscribe.unsubscribe(key_1.KeyType.QUORUM, this.appId, topic);
|
|
445
|
-
}
|
|
446
|
-
async psub(wild, callback) {
|
|
447
|
-
const subscriptionCallback = async (topic, message) => {
|
|
448
|
-
callback(message.topic, message.job);
|
|
449
|
-
};
|
|
450
|
-
return await this.subscribe.psubscribe(key_1.KeyType.QUORUM, subscriptionCallback, this.appId, wild);
|
|
451
|
-
}
|
|
452
|
-
async punsub(wild) {
|
|
453
|
-
return await this.subscribe.punsubscribe(key_1.KeyType.QUORUM, this.appId, wild);
|
|
454
|
-
}
|
|
455
|
-
async pubsub(topic, data, context, timeout = enums_1.HMSH_OTT_WAIT_TIME) {
|
|
456
|
-
context = {
|
|
457
|
-
metadata: {
|
|
458
|
-
ngn: this.guid,
|
|
459
|
-
trc: context?.metadata?.trc,
|
|
460
|
-
spn: context?.metadata?.spn,
|
|
461
|
-
},
|
|
462
|
-
};
|
|
463
|
-
const jobId = await this.pub(topic, data, context);
|
|
464
|
-
return new Promise((resolve, reject) => {
|
|
465
|
-
this.registerJobCallback(jobId, (topic, output) => {
|
|
466
|
-
if (output.metadata.err) {
|
|
467
|
-
const error = JSON.parse(output.metadata.err);
|
|
468
|
-
reject({
|
|
469
|
-
...error,
|
|
470
|
-
job_id: output.metadata.jid,
|
|
471
|
-
});
|
|
472
|
-
}
|
|
473
|
-
else {
|
|
474
|
-
resolve(output);
|
|
475
|
-
}
|
|
476
|
-
});
|
|
477
|
-
setTimeout(() => {
|
|
478
|
-
this.delistJobCallback(jobId);
|
|
479
|
-
reject({
|
|
480
|
-
code: enums_1.HMSH_CODE_TIMEOUT,
|
|
481
|
-
message: 'timeout',
|
|
482
|
-
job_id: jobId,
|
|
483
|
-
});
|
|
484
|
-
}, timeout);
|
|
485
|
-
});
|
|
486
|
-
}
|
|
487
|
-
async pubOneTimeSubs(context, jobOutput, emit = false) {
|
|
488
|
-
if (this.hasOneTimeSubscription(context)) {
|
|
489
|
-
const message = {
|
|
490
|
-
type: 'job',
|
|
491
|
-
topic: context.metadata.jid,
|
|
492
|
-
job: (0, utils_1.restoreHierarchy)(jobOutput),
|
|
493
|
-
};
|
|
494
|
-
this.store.publish(key_1.KeyType.QUORUM, message, this.appId, context.metadata.ngn);
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
async getPublishesTopic(context) {
|
|
498
|
-
const config = await this.getVID();
|
|
499
|
-
const activityId = context.metadata.aid || context['$self']?.output?.metadata?.aid;
|
|
500
|
-
const schema = await this.store.getSchema(activityId, config);
|
|
501
|
-
return schema.publishes;
|
|
502
|
-
}
|
|
503
|
-
async pubPermSubs(context, jobOutput, emit = false) {
|
|
504
|
-
const topic = await this.getPublishesTopic(context);
|
|
505
|
-
if (topic) {
|
|
506
|
-
const message = {
|
|
507
|
-
type: 'job',
|
|
508
|
-
topic,
|
|
509
|
-
job: (0, utils_1.restoreHierarchy)(jobOutput),
|
|
510
|
-
};
|
|
511
|
-
this.store.publish(key_1.KeyType.QUORUM, message, this.appId, `${topic}.${context.metadata.jid}`);
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
async add(streamData) {
|
|
515
|
-
return (await this.router.publishMessage(null, streamData));
|
|
516
|
-
}
|
|
517
|
-
registerJobCallback(jobId, jobCallback) {
|
|
518
|
-
this.jobCallbacks[jobId] = jobCallback;
|
|
519
|
-
}
|
|
520
|
-
delistJobCallback(jobId) {
|
|
521
|
-
delete this.jobCallbacks[jobId];
|
|
522
|
-
}
|
|
523
|
-
hasOneTimeSubscription(context) {
|
|
524
|
-
return Boolean(context.metadata.ngn);
|
|
525
|
-
}
|
|
526
|
-
async runJobCompletionTasks(context, options = {}) {
|
|
527
|
-
const isAwait = this.hasParentJob(context, true);
|
|
528
|
-
const isOneTimeSub = this.hasOneTimeSubscription(context);
|
|
529
|
-
const topic = await this.getPublishesTopic(context);
|
|
530
|
-
let msgId;
|
|
531
|
-
if (isAwait || isOneTimeSub || topic) {
|
|
532
|
-
const jobOutput = await this.getState(context.metadata.tpc, context.metadata.jid);
|
|
533
|
-
msgId = await this.execAdjacentParent(context, jobOutput, options.emit);
|
|
534
|
-
this.pubOneTimeSubs(context, jobOutput, options.emit);
|
|
535
|
-
this.pubPermSubs(context, jobOutput, options.emit);
|
|
536
|
-
}
|
|
537
|
-
if (!options.emit) {
|
|
538
|
-
this.taskService.registerJobForCleanup(context.metadata.jid, this.resolveExpires(context, options), options);
|
|
539
|
-
}
|
|
540
|
-
return msgId;
|
|
541
|
-
}
|
|
542
|
-
resolveExpires(context, options) {
|
|
543
|
-
return options.expire ?? context.metadata.expire ?? enums_1.HMSH_EXPIRE_JOB_SECONDS;
|
|
544
|
-
}
|
|
545
|
-
async export(jobId) {
|
|
546
|
-
return await this.exporter.export(jobId);
|
|
547
|
-
}
|
|
548
|
-
async getRaw(jobId) {
|
|
549
|
-
return await this.store.getRaw(jobId);
|
|
550
|
-
}
|
|
551
|
-
async getStatus(jobId) {
|
|
552
|
-
const { id: appId } = await this.getVID();
|
|
553
|
-
return await this.store.getStatus(jobId, appId);
|
|
554
|
-
}
|
|
555
|
-
async getState(topic, jobId) {
|
|
556
|
-
const jobSymbols = await this.store.getSymbols(`$${topic}`);
|
|
557
|
-
const consumes = {
|
|
558
|
-
[`$${topic}`]: Object.keys(jobSymbols),
|
|
559
|
-
};
|
|
560
|
-
const dIds = {};
|
|
561
|
-
const output = await this.store.getState(jobId, consumes, dIds);
|
|
562
|
-
if (!output) {
|
|
563
|
-
throw new Error(`not found ${jobId}`);
|
|
564
|
-
}
|
|
565
|
-
const [state, status] = output;
|
|
566
|
-
const stateTree = (0, utils_1.restoreHierarchy)(state);
|
|
567
|
-
if (status && stateTree.metadata) {
|
|
568
|
-
stateTree.metadata.js = status;
|
|
569
|
-
}
|
|
570
|
-
return stateTree;
|
|
571
|
-
}
|
|
572
|
-
async getQueryState(jobId, fields) {
|
|
573
|
-
return await this.store.getQueryState(jobId, fields);
|
|
574
|
-
}
|
|
575
|
-
async compress(terms) {
|
|
576
|
-
const existingSymbols = await this.store.getSymbolValues();
|
|
577
|
-
const startIndex = Object.keys(existingSymbols).length;
|
|
578
|
-
const maxIndex = Math.pow(52, 2) - 1;
|
|
579
|
-
const newSymbols = serializer_1.SerializerService.filterSymVals(startIndex, maxIndex, existingSymbols, new Set(terms));
|
|
580
|
-
return await this.store.addSymbolValues(newSymbols);
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
exports.EngineService = EngineService;
|
|
1
|
+
'use strict';function _0x2345(_0x41451b,_0x9381c9){const _0x14db4f=_0x14db();return _0x2345=function(_0x234523,_0x5bd035){_0x234523=_0x234523-0x1e7;let _0x5b0a12=_0x14db4f[_0x234523];return _0x5b0a12;},_0x2345(_0x41451b,_0x9381c9);}function _0x14db(){const _0x487e17=['2681574htFWMn','555190nuVtZr','2357296iMPZRa','23556731sfVTze','7krreqS','375597ljLWFC','279nIVfpy','4NRCgWY','2sbFQQo','131280WlDfAW','429806BGXdjW'];_0x14db=function(){return _0x487e17;};return _0x14db();}(function(_0x245ba0,_0x34618d){const _0x5225f1=_0x2345,_0x1d7617=_0x245ba0();while(!![]){try{const _0x1312f1=-parseInt(_0x5225f1(0x1e7))/0x1*(parseInt(_0x5225f1(0x1f0))/0x2)+-parseInt(_0x5225f1(0x1ed))/0x3*(parseInt(_0x5225f1(0x1ef))/0x4)+-parseInt(_0x5225f1(0x1e9))/0x5+parseInt(_0x5225f1(0x1e8))/0x6*(-parseInt(_0x5225f1(0x1ec))/0x7)+-parseInt(_0x5225f1(0x1ea))/0x8+parseInt(_0x5225f1(0x1ee))/0x9*(-parseInt(_0x5225f1(0x1f1))/0xa)+parseInt(_0x5225f1(0x1eb))/0xb;if(_0x1312f1===_0x34618d)break;else _0x1d7617['push'](_0x1d7617['shift']());}catch(_0xc8bf35){_0x1d7617['push'](_0x1d7617['shift']());}}}(_0x14db,0x4fd07));var __importDefault=this&&this['__importDefault']||function(_0x529fc2){return _0x529fc2&&_0x529fc2['__esModule']?_0x529fc2:{'default':_0x529fc2};};Object['defineProperty'](exports,'__esModule',{'value':!![]}),exports['EngineService']=void 0x0;const key_1=require('../../modules/key'),enums_1=require('../../modules/enums'),utils_1=require('../../modules/utils'),activities_1=__importDefault(require('../activities')),compiler_1=require('../compiler'),exporter_1=require('../exporter'),reporter_1=require('../reporter'),router_1=require('../router'),serializer_1=require('../serializer'),task_1=require('../task'),stream_1=require('../../types/stream'),factory_1=require('../stream/factory'),factory_2=require('../sub/factory'),factory_3=require('../store/factory'),factory_4=require('../search/factory');class EngineService{constructor(){this['cacheMode']='cache',this['untilVersion']=null,this['jobCallbacks']={},this['reporting']=![],this['jobId']=0x1;}static async['init'](_0x3ccf48,_0x5d65b6,_0x5f2674,_0x15cdf3,_0x4588d5){if(_0x15cdf3['engine']){const _0x139df8=new EngineService();_0x139df8['verifyEngineFields'](_0x15cdf3),_0x139df8['namespace']=_0x3ccf48,_0x139df8['appId']=_0x5d65b6,_0x139df8['guid']=_0x5f2674,_0x139df8['logger']=_0x4588d5,await _0x139df8['initSearchChannel'](_0x15cdf3['engine']['store']),await _0x139df8['initStoreChannel'](_0x15cdf3['engine']['store']),await _0x139df8['initSubChannel'](_0x15cdf3['engine']['sub'],_0x15cdf3['engine']['store']),await _0x139df8['initStreamChannel'](_0x15cdf3['engine']['stream'],_0x15cdf3['engine']['store']),_0x139df8['router']=await _0x139df8['initRouter'](_0x15cdf3);const _0x20fb10=_0x139df8['store']['mintKey'](key_1['KeyType']['STREAMS'],{'appId':_0x139df8['appId']});return _0x139df8['router']['consumeMessages'](_0x20fb10,'ENGINE',_0x139df8['guid'],_0x139df8['processStreamMessage']['bind'](_0x139df8)),_0x139df8['taskService']=new task_1['TaskService'](_0x139df8['store'],_0x4588d5),_0x139df8['exporter']=new exporter_1['ExporterService'](_0x139df8['appId'],_0x139df8['store'],_0x4588d5),_0x139df8['inited']=(0x0,utils_1['formatISODate'])(new Date()),_0x139df8;}}['verifyEngineFields'](_0x4a6fa3){if(!(0x0,utils_1['identifyRedisType'])(_0x4a6fa3['engine']['store'])||!(0x0,utils_1['identifyRedisType'])(_0x4a6fa3['engine']['stream'])||!(0x0,utils_1['identifyRedisType'])(_0x4a6fa3['engine']['sub']))throw new Error('engine\x20config\x20must\x20reference\x203\x20redis\x20client\x20instances');}async['initSearchChannel'](_0x59b975,_0x4fe907){this['search']=await factory_4['SearchServiceFactory']['init'](_0x59b975,_0x4fe907,this['namespace'],this['appId'],this['logger']);}async['initStoreChannel'](_0x49b30d){this['store']=await factory_3['StoreServiceFactory']['init'](_0x49b30d,this['namespace'],this['appId'],this['logger']);}async['initSubChannel'](_0x387754,_0x37e7c8){this['subscribe']=await factory_2['SubServiceFactory']['init'](_0x387754,_0x37e7c8,this['namespace'],this['appId'],this['guid'],this['logger']);}async['initStreamChannel'](_0x246495,_0x2843a5){this['stream']=await factory_1['StreamServiceFactory']['init'](_0x246495,_0x2843a5,this['namespace'],this['appId'],this['logger']);}async['initRouter'](_0x2ac130){const _0x1f9249=await this['store']['getThrottleRate'](':');return new router_1['Router']({'namespace':this['namespace'],'appId':this['appId'],'guid':this['guid'],'role':stream_1['StreamRole']['ENGINE'],'reclaimDelay':_0x2ac130['engine']['reclaimDelay'],'reclaimCount':_0x2ac130['engine']['reclaimCount'],'throttle':_0x1f9249,'readonly':_0x2ac130['engine']['readonly']},this['stream'],this['store'],this['logger']);}async['fetchAndVerifyVID'](_0x1a32a0,_0x3d7a5e=0x0){if(isNaN(Number(_0x1a32a0['version']))){const _0x37f10b=await this['store']['getApp'](_0x1a32a0['id'],!![]);if(!isNaN(Number(_0x37f10b['version']))){if(!this['apps'])this['apps']={};return this['apps'][_0x1a32a0['id']]=_0x37f10b,{'id':_0x1a32a0['id'],'version':_0x37f10b['version']};}else{if(_0x3d7a5e<0xa)return await(0x0,utils_1['sleepFor'])(enums_1['HMSH_QUORUM_DELAY_MS']*0x2),await this['fetchAndVerifyVID'](_0x1a32a0,_0x3d7a5e+0x1);else this['logger']['error']('engine-vid-resolution-error',{'id':_0x1a32a0['id'],'guid':this['guid']});}}return _0x1a32a0;}async['getVID'](_0x340c9c){if(this['cacheMode']==='nocache'){const _0x23ac24=await this['store']['getApp'](this['appId'],!![]);if(_0x23ac24['version']['toString']()===this['untilVersion']['toString']()){if(!this['apps'])this['apps']={};this['apps'][this['appId']]=_0x23ac24,this['setCacheMode']('cache',_0x23ac24['version']['toString']());}return{'id':this['appId'],'version':_0x23ac24['version']};}else return!this['apps']&&_0x340c9c?(this['apps']={},this['apps'][this['appId']]=_0x340c9c,_0x340c9c):await this['fetchAndVerifyVID']({'id':this['appId'],'version':this['apps']?.[this['appId']]['version']});}['setCacheMode'](_0x2ad9d6,_0x5b578a){this['logger']['info']('engine-executable-cache',{'mode':_0x2ad9d6,[_0x2ad9d6==='cache'?'target':'until']:_0x5b578a}),this['cacheMode']=_0x2ad9d6,this['untilVersion']=_0x5b578a;}async['routeToSubscribers'](_0x230a80,_0x4694c3){const _0x1e76dc=this['jobCallbacks'][_0x4694c3['metadata']['jid']];_0x1e76dc&&(this['delistJobCallback'](_0x4694c3['metadata']['jid']),_0x1e76dc(_0x230a80,_0x4694c3));}async['processWebHooks'](){this['taskService']['processWebHooks'](this['hook']['bind'](this));}async['processTimeHooks'](){this['taskService']['processTimeHooks'](this['hookTime']['bind'](this));}async['throttle'](_0x3afea8){try{this['router']['setThrottle'](_0x3afea8);}catch(_0x3bf743){this['logger']['error']('engine-throttle-error',{'error':_0x3bf743});}}async['initActivity'](_0x4b1885,_0x1e02bb={},_0x9a9b40){const [_0x31aef5,_0x407aef]=await this['getSchema'](_0x4b1885),_0xafb91c=activities_1['default'][utils_1['polyfill']['resolveActivityType'](_0x407aef['type'])];if(_0xafb91c){const _0x591f50=(0x0,utils_1['formatISODate'])(new Date()),_0x57b024={'aid':_0x31aef5,'atp':_0x407aef['type'],'stp':_0x407aef['subtype'],'ac':_0x591f50,'au':_0x591f50},_0x39ba15=null;return new _0xafb91c(_0x407aef,_0x1e02bb,_0x57b024,_0x39ba15,this,_0x9a9b40);}else throw new Error('activity\x20type\x20'+_0x407aef['type']+'\x20not\x20found');}async['getSchema'](_0x4959d7){const _0x1379f4=await this['store']['getApp'](this['appId']);if(!_0x1379f4)throw new Error('no\x20app\x20found\x20for\x20id\x20'+this['appId']);if(this['isPrivate'](_0x4959d7)){const _0x1068de=_0x4959d7['substring'](0x1),_0x2a0a36=await this['store']['getSchema'](_0x1068de,await this['getVID'](_0x1379f4));return[_0x1068de,_0x2a0a36];}else{const _0x5860fe=await this['store']['getSubscription'](_0x4959d7,await this['getVID'](_0x1379f4));if(_0x5860fe){const _0x4f5a1e=await this['store']['getSchema'](_0x5860fe,await this['getVID'](_0x1379f4));return[_0x5860fe,_0x4f5a1e];}}throw new Error('no\x20subscription\x20found\x20for\x20topic\x20'+_0x4959d7+'\x20in\x20app\x20'+this['appId']+'\x20for\x20app\x20version\x20'+_0x1379f4['version']);}async['getSettings'](){return await this['store']['getSettings']();}['isPrivate'](_0x32223e){return _0x32223e['startsWith']('.');}async['plan'](_0x1a5c8a){const _0x1283cd=new compiler_1['CompilerService'](this['store'],this['stream'],this['logger']);return await _0x1283cd['plan'](_0x1a5c8a);}async['deploy'](_0x51acbc){const _0x326d64=new compiler_1['CompilerService'](this['store'],this['stream'],this['logger']);return await _0x326d64['deploy'](_0x51acbc);}async['getStats'](_0x2d5880,_0x31e117){const {id:_0x1c0861,version:_0x282ab2}=await this['getVID'](),_0x4a532f=new reporter_1['ReporterService']({'id':_0x1c0861,'version':_0x282ab2},this['store'],this['logger']),_0x552775=await this['resolveQuery'](_0x2d5880,_0x31e117);return await _0x4a532f['getStats'](_0x552775);}async['getIds'](_0x2a362e,_0x6c02d0,_0x169bbd=[]){const {id:_0x46bc7d,version:_0x18e40d}=await this['getVID'](),_0x2a9f83=new reporter_1['ReporterService']({'id':_0x46bc7d,'version':_0x18e40d},this['store'],this['logger']),_0x4a087d=await this['resolveQuery'](_0x2a362e,_0x6c02d0);return await _0x2a9f83['getIds'](_0x4a087d,_0x169bbd);}async['resolveQuery'](_0xcaa20,_0x236208){const _0x3e32e8=await this['initActivity'](_0xcaa20,_0x236208['data']);return await _0x3e32e8['getState'](),{'end':_0x236208['end'],'start':_0x236208['start'],'range':_0x236208['range'],'granularity':_0x3e32e8['resolveGranularity'](),'key':_0x3e32e8['resolveJobKey'](_0x3e32e8['createInputContext']()),'sparse':_0x236208['sparse']};}async['processStreamMessage'](_0xc887df){this['logger']['debug']('engine-process',{'jid':_0xc887df['metadata']['jid'],'gid':_0xc887df['metadata']['gid'],'dad':_0xc887df['metadata']['dad'],'aid':_0xc887df['metadata']['aid'],'status':_0xc887df['status']||stream_1['StreamStatus']['SUCCESS'],'code':_0xc887df['code']||0xc8,'type':_0xc887df['type']});const _0x5b773e={'metadata':{'guid':_0xc887df['metadata']['guid'],'jid':_0xc887df['metadata']['jid'],'gid':_0xc887df['metadata']['gid'],'dad':_0xc887df['metadata']['dad'],'aid':_0xc887df['metadata']['aid']},'data':_0xc887df['data']};if(_0xc887df['type']===stream_1['StreamDataType']['TIMEHOOK']){const _0xb54eae=await this['initActivity']('.'+_0xc887df['metadata']['aid'],_0x5b773e['data'],_0x5b773e);await _0xb54eae['processTimeHookEvent'](_0xc887df['metadata']['jid']);}else{if(_0xc887df['type']===stream_1['StreamDataType']['WEBHOOK']){const _0x329ff1=await this['initActivity']('.'+_0xc887df['metadata']['aid'],_0x5b773e['data'],_0x5b773e);await _0x329ff1['processWebHookEvent'](_0xc887df['status'],_0xc887df['code']);}else{if(_0xc887df['type']===stream_1['StreamDataType']['TRANSITION']){const _0x4fa135=await this['initActivity']('.'+_0xc887df['metadata']['aid'],_0x5b773e['data'],_0x5b773e);await _0x4fa135['process']();}else{if(_0xc887df['type']===stream_1['StreamDataType']['AWAIT']){_0x5b773e['metadata']={..._0x5b773e['metadata'],'pj':_0xc887df['metadata']['jid'],'pg':_0xc887df['metadata']['gid'],'pd':_0xc887df['metadata']['dad'],'pa':_0xc887df['metadata']['aid'],'px':_0xc887df['metadata']['await']===![],'trc':_0xc887df['metadata']['trc'],'spn':_0xc887df['metadata']['spn']};const _0x54d6df=await this['initActivity'](_0xc887df['metadata']['topic'],_0xc887df['data'],_0x5b773e);await _0x54d6df['process']();}else{if(_0xc887df['type']===stream_1['StreamDataType']['RESULT']){const _0x518c07=await this['initActivity']('.'+_0x5b773e['metadata']['aid'],_0xc887df['data'],_0x5b773e);await _0x518c07['processEvent'](_0xc887df['status'],_0xc887df['code']);}else{const _0x43abf8=await this['initActivity']('.'+_0xc887df['metadata']['aid'],_0xc887df['data'],_0x5b773e);await _0x43abf8['processEvent'](_0xc887df['status'],_0xc887df['code'],'output');}}}}}this['logger']['debug']('engine-process-end',{'jid':_0xc887df['metadata']['jid'],'gid':_0xc887df['metadata']['gid'],'aid':_0xc887df['metadata']['aid']});}async['execAdjacentParent'](_0x49081c,_0x521151,_0x296e4f=![]){if(this['hasParentJob'](_0x49081c)){const _0x118033=this['resolveError'](_0x521151['metadata']),_0x38c6a3=_0x49081c['$self']?.['output']?.['metadata']?.['l2s']||_0x49081c['$self']?.['output']?.['metadata']?.['l1s'],_0x11f9a1={'metadata':{'guid':(0x0,utils_1['guid'])(),'jid':_0x49081c['metadata']['pj'],'gid':_0x49081c['metadata']['pg'],'dad':_0x49081c['metadata']['pd'],'aid':_0x49081c['metadata']['pa'],'trc':_0x49081c['metadata']['trc'],'spn':_0x38c6a3},'type':stream_1['StreamDataType']['RESULT'],'data':_0x521151['data']};if(_0x118033&&_0x118033['code'])_0x11f9a1['status']=stream_1['StreamStatus']['ERROR'],_0x11f9a1['data']=_0x118033,_0x11f9a1['code']=_0x118033['code'],_0x11f9a1['stack']=_0x118033['stack'];else _0x296e4f?(_0x11f9a1['status']=stream_1['StreamStatus']['PENDING'],_0x11f9a1['code']=enums_1['HMSH_CODE_PENDING']):(_0x11f9a1['status']=stream_1['StreamStatus']['SUCCESS'],_0x11f9a1['code']=enums_1['HMSH_CODE_SUCCESS']);return await this['router']?.['publishMessage'](null,_0x11f9a1);}}['hasParentJob'](_0x158809,_0x1c9ca1=![]){if(_0x1c9ca1)return Boolean(_0x158809['metadata']['pj']&&_0x158809['metadata']['pa']&&!_0x158809['metadata']['px']);return Boolean(_0x158809['metadata']['pj']&&_0x158809['metadata']['pa']);}['resolveError'](_0x5be46f){if(_0x5be46f&&_0x5be46f['err'])return JSON['parse'](_0x5be46f['err']);}async['interrupt'](_0x402b22,_0x461fc5,_0x3773f5={}){await this['store']['interrupt'](_0x402b22,_0x461fc5,_0x3773f5);const _0x4f2d8a=await this['getState'](_0x402b22,_0x461fc5),_0xe1d0b4={'interrupt':_0x3773f5['descend'],'expire':_0x3773f5['expire']};return await this['runJobCompletionTasks'](_0x4f2d8a,_0xe1d0b4);}async['scrub'](_0x5b6316){await this['store']['scrub'](_0x5b6316);}async['hook'](_0x12db32,_0x2db6fc,_0x363e8e=stream_1['StreamStatus']['SUCCESS'],_0x4cf882=0xc8){const _0x17c880=await this['taskService']['getHookRule'](_0x12db32),[_0x586fcf]=await this['getSchema']('.'+_0x17c880['to']),_0x404d76={'type':stream_1['StreamDataType']['WEBHOOK'],'status':_0x363e8e,'code':_0x4cf882,'metadata':{'guid':(0x0,utils_1['guid'])(),'aid':_0x586fcf,'topic':_0x12db32},'data':_0x2db6fc};return await this['router']['publishMessage'](null,_0x404d76);}async['hookTime'](_0x1fcb59,_0x120d61,_0x6bcc0d,_0x463cc2){if(_0x463cc2==='interrupt'||_0x463cc2==='expire')return await this['interrupt'](_0x6bcc0d,_0x1fcb59,{'suppress':!![],'expire':0x1});const [_0x5be472,..._0x4cc426]=_0x6bcc0d['split'](','),_0x4bd616=','+_0x4cc426['join'](','),_0xcfe3a3={'type':stream_1['StreamDataType']['TIMEHOOK'],'metadata':{'guid':(0x0,utils_1['guid'])(),'jid':_0x1fcb59,'gid':_0x120d61,'dad':_0x4bd616,'aid':_0x5be472},'data':{'timestamp':Date['now']()}};await this['router']['publishMessage'](null,_0xcfe3a3);}async['hookAll'](_0x23f5cf,_0xa4df41,_0x2e71c7,_0x39defd=[]){const _0x3d46fa=await this['getVID'](),_0x431d1b=await this['taskService']['getHookRule'](_0x23f5cf);if(_0x431d1b){const _0x2116f5=await(0x0,utils_1['getSubscriptionTopic'])(_0x431d1b['to'],this['store'],_0x3d46fa),_0xa832=await this['resolveQuery'](_0x2116f5,_0x2e71c7),_0x302bde=new reporter_1['ReporterService'](_0x3d46fa,this['store'],this['logger']),_0x4491c0=await _0x302bde['getWorkItems'](_0xa832,_0x39defd);if(_0x4491c0['length']){const _0x4b18b9=new task_1['TaskService'](this['store'],this['logger']);await _0x4b18b9['enqueueWorkItems'](_0x4491c0['map'](_0x4911a8=>[_0x23f5cf,_0x4911a8,_0x2e71c7['scrub']||![],JSON['stringify'](_0xa4df41)]['join'](key_1['VALSEP']))),this['subscribe']['publish'](key_1['KeyType']['QUORUM'],{'type':'work','originator':this['guid']},this['appId']);}return _0x4491c0;}else throw new Error('unable\x20to\x20find\x20hook\x20rule\x20for\x20topic\x20'+_0x23f5cf);}async['pub'](_0x547514,_0x1997a5,_0x593079,_0x406f44){const _0xc0ce3f=await this['initActivity'](_0x547514,_0x1997a5,_0x593079);if(_0xc0ce3f)return await _0xc0ce3f['process'](_0x406f44);else throw new Error('unable\x20to\x20process\x20activity\x20for\x20topic\x20'+_0x547514);}async['sub'](_0x1cc31b,_0x4794fd){const _0x63a75b=async(_0x55f364,_0x365a6b)=>{_0x4794fd(_0x365a6b['topic'],_0x365a6b['job']);};return await this['subscribe']['subscribe'](key_1['KeyType']['QUORUM'],_0x63a75b,this['appId'],_0x1cc31b);}async['unsub'](_0x4ca14f){return await this['subscribe']['unsubscribe'](key_1['KeyType']['QUORUM'],this['appId'],_0x4ca14f);}async['psub'](_0x2bbe35,_0x2b3828){const _0x200257=async(_0x3db4e7,_0x112340)=>{_0x2b3828(_0x112340['topic'],_0x112340['job']);};return await this['subscribe']['psubscribe'](key_1['KeyType']['QUORUM'],_0x200257,this['appId'],_0x2bbe35);}async['punsub'](_0x4d1bf4){return await this['subscribe']['punsubscribe'](key_1['KeyType']['QUORUM'],this['appId'],_0x4d1bf4);}async['pubsub'](_0xd7a951,_0x45f044,_0x21618d,_0x3566a1=enums_1['HMSH_OTT_WAIT_TIME']){_0x21618d={'metadata':{'ngn':this['guid'],'trc':_0x21618d?.['metadata']?.['trc'],'spn':_0x21618d?.['metadata']?.['spn']}};const _0x30ad5f=await this['pub'](_0xd7a951,_0x45f044,_0x21618d);return new Promise((_0x1abaf6,_0x5337ca)=>{this['registerJobCallback'](_0x30ad5f,(_0x581cee,_0x14d906)=>{if(_0x14d906['metadata']['err']){const _0x2122a7=JSON['parse'](_0x14d906['metadata']['err']);_0x5337ca({..._0x2122a7,'job_id':_0x14d906['metadata']['jid']});}else _0x1abaf6(_0x14d906);}),setTimeout(()=>{this['delistJobCallback'](_0x30ad5f),_0x5337ca({'code':enums_1['HMSH_CODE_TIMEOUT'],'message':'timeout','job_id':_0x30ad5f});},_0x3566a1);});}async['pubOneTimeSubs'](_0x22c39d,_0x1e9c0a,_0x44ca3f=![]){if(this['hasOneTimeSubscription'](_0x22c39d)){const _0x2b333d={'type':'job','topic':_0x22c39d['metadata']['jid'],'job':(0x0,utils_1['restoreHierarchy'])(_0x1e9c0a)};this['subscribe']['publish'](key_1['KeyType']['QUORUM'],_0x2b333d,this['appId'],_0x22c39d['metadata']['ngn']);}}async['getPublishesTopic'](_0x239d3b){const _0x1c0070=await this['getVID'](),_0xba56e2=_0x239d3b['metadata']['aid']||_0x239d3b['$self']?.['output']?.['metadata']?.['aid'],_0x122573=await this['store']['getSchema'](_0xba56e2,_0x1c0070);return _0x122573['publishes'];}async['pubPermSubs'](_0x2a5930,_0x2d9f88,_0x479eba=![]){const _0x2de9a1=await this['getPublishesTopic'](_0x2a5930);if(_0x2de9a1){const _0x2d9154={'type':'job','topic':_0x2de9a1,'job':(0x0,utils_1['restoreHierarchy'])(_0x2d9f88)};this['subscribe']['publish'](key_1['KeyType']['QUORUM'],_0x2d9154,this['appId'],_0x2de9a1+'.'+_0x2a5930['metadata']['jid']);}}async['add'](_0x2aa7db){return await this['router']['publishMessage'](null,_0x2aa7db);}['registerJobCallback'](_0x1e7642,_0x2080f8){this['jobCallbacks'][_0x1e7642]=_0x2080f8;}['delistJobCallback'](_0x1a8a64){delete this['jobCallbacks'][_0x1a8a64];}['hasOneTimeSubscription'](_0x56ae71){return Boolean(_0x56ae71['metadata']['ngn']);}async['runJobCompletionTasks'](_0x3f49a9,_0x492d47={}){const _0x44436f=this['hasParentJob'](_0x3f49a9,!![]),_0x4bfcfb=this['hasOneTimeSubscription'](_0x3f49a9),_0x526a4b=await this['getPublishesTopic'](_0x3f49a9);let _0x3fa5ff;if(_0x44436f||_0x4bfcfb||_0x526a4b){const _0x356837=await this['getState'](_0x3f49a9['metadata']['tpc'],_0x3f49a9['metadata']['jid']);_0x3fa5ff=await this['execAdjacentParent'](_0x3f49a9,_0x356837,_0x492d47['emit']),this['pubOneTimeSubs'](_0x3f49a9,_0x356837,_0x492d47['emit']),this['pubPermSubs'](_0x3f49a9,_0x356837,_0x492d47['emit']);}return!_0x492d47['emit']&&this['taskService']['registerJobForCleanup'](_0x3f49a9['metadata']['jid'],this['resolveExpires'](_0x3f49a9,_0x492d47),_0x492d47),_0x3fa5ff;}['resolveExpires'](_0x54dbcc,_0x1f4761){return _0x1f4761['expire']??_0x54dbcc['metadata']['expire']??enums_1['HMSH_EXPIRE_JOB_SECONDS'];}async['export'](_0x5e4675){return await this['exporter']['export'](_0x5e4675);}async['getRaw'](_0x81913){return await this['store']['getRaw'](_0x81913);}async['getStatus'](_0x46898a){const {id:_0x51dbce}=await this['getVID']();return await this['store']['getStatus'](_0x46898a,_0x51dbce);}async['getState'](_0x41f90c,_0x1c2a4c){const _0x16e34a=await this['store']['getSymbols']('$'+_0x41f90c),_0x356c96={['$'+_0x41f90c]:Object['keys'](_0x16e34a)},_0x3aba4b={},_0x531066=await this['store']['getState'](_0x1c2a4c,_0x356c96,_0x3aba4b);if(!_0x531066)throw new Error('not\x20found\x20'+_0x1c2a4c);const [_0x2abb00,_0x3cb26c]=_0x531066,_0x2883ce=(0x0,utils_1['restoreHierarchy'])(_0x2abb00);return _0x3cb26c&&_0x2883ce['metadata']&&(_0x2883ce['metadata']['js']=_0x3cb26c),_0x2883ce;}async['getQueryState'](_0x1633fe,_0x1a1be1){return await this['store']['getQueryState'](_0x1633fe,_0x1a1be1);}async['compress'](_0x14441b){const _0x34215d=await this['store']['getSymbolValues'](),_0xdc2d29=Object['keys'](_0x34215d)['length'],_0x265af0=Math['pow'](0x34,0x2)-0x1,_0x396fce=serializer_1['SerializerService']['filterSymVals'](_0xdc2d29,_0x265af0,_0x34215d,new Set(_0x14441b));return await this['store']['addSymbolValues'](_0x396fce);}}exports['EngineService']=EngineService;
|