@hotmeshio/hotmesh 0.3.6 → 0.3.8
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 +13 -1
- package/build/index.d.ts +3 -1
- package/build/index.js +10 -1
- package/build/modules/key.js +1 -62
- package/build/modules/utils.js +1 -267
- package/build/package.json +12 -8
- 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.js +1 -237
- 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 -562
- 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/index.d.ts +2 -0
- package/build/services/meshflow/index.js +2 -0
- package/build/services/meshflow/search.d.ts +4 -5
- package/build/services/meshflow/search.js +45 -35
- package/build/services/meshflow/workflow.d.ts +1 -1
- package/build/services/meshflow/workflow.js +3 -28
- 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 -219
- 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 +2 -1
- package/build/services/store/factory.js +2 -2
- package/build/services/store/index.d.ts +71 -97
- package/build/services/store/index.js +2 -939
- 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 +2 -1
- package/build/services/stream/factory.js +5 -5
- 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 +1 -1
- package/build/services/sub/factory.js +5 -5
- 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 -158
- package/build/types/redis.d.ts +5 -5
- package/index.ts +18 -1
- package/package.json +12 -8
- package/typedoc.json +2 -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,562 +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 task_1 = require("../task");
|
|
17
|
-
const stream_1 = require("../../types/stream");
|
|
18
|
-
const factory_1 = require("../stream/factory");
|
|
19
|
-
const factory_2 = require("../sub/factory");
|
|
20
|
-
const factory_3 = require("../store/factory");
|
|
21
|
-
class EngineService {
|
|
22
|
-
constructor() {
|
|
23
|
-
this.cacheMode = 'cache';
|
|
24
|
-
this.untilVersion = null;
|
|
25
|
-
this.jobCallbacks = {};
|
|
26
|
-
this.reporting = false;
|
|
27
|
-
this.jobId = 1;
|
|
28
|
-
}
|
|
29
|
-
static async init(namespace, appId, guid, config, logger) {
|
|
30
|
-
if (config.engine) {
|
|
31
|
-
const instance = new EngineService();
|
|
32
|
-
instance.verifyEngineFields(config);
|
|
33
|
-
instance.namespace = namespace;
|
|
34
|
-
instance.appId = appId;
|
|
35
|
-
instance.guid = guid;
|
|
36
|
-
instance.logger = logger;
|
|
37
|
-
await instance.initStoreChannel(config.engine.store);
|
|
38
|
-
await instance.initSubChannel(config.engine.sub);
|
|
39
|
-
await instance.initStreamChannel(config.engine.stream);
|
|
40
|
-
instance.router = await instance.initRouter(config);
|
|
41
|
-
instance.router.consumeMessages(instance.stream.mintKey(key_1.KeyType.STREAMS, { appId: instance.appId }), 'ENGINE', instance.guid, instance.processStreamMessage.bind(instance));
|
|
42
|
-
instance.taskService = new task_1.TaskService(instance.store, logger);
|
|
43
|
-
instance.exporter = new exporter_1.ExporterService(instance.appId, instance.store, logger);
|
|
44
|
-
instance.inited = (0, utils_1.formatISODate)(new Date());
|
|
45
|
-
return instance;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
verifyEngineFields(config) {
|
|
49
|
-
if (!(0, utils_1.identifyRedisType)(config.engine.store) ||
|
|
50
|
-
!(0, utils_1.identifyRedisType)(config.engine.stream) ||
|
|
51
|
-
!(0, utils_1.identifyRedisType)(config.engine.sub)) {
|
|
52
|
-
throw new Error('engine config must reference 3 redis client instances');
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
async initStoreChannel(store) {
|
|
56
|
-
this.store = await factory_3.StoreServiceFactory.init(store, this.namespace, this.appId, this.logger);
|
|
57
|
-
}
|
|
58
|
-
async initSubChannel(sub) {
|
|
59
|
-
this.subscribe = await factory_2.SubServiceFactory.init(sub, this.namespace, this.appId, this.guid, this.logger);
|
|
60
|
-
}
|
|
61
|
-
async initStreamChannel(stream) {
|
|
62
|
-
this.stream = await factory_1.StreamServiceFactory.init(stream, this.namespace, this.appId, this.logger);
|
|
63
|
-
}
|
|
64
|
-
async initRouter(config) {
|
|
65
|
-
const throttle = await this.store.getThrottleRate(':');
|
|
66
|
-
return new router_1.Router({
|
|
67
|
-
namespace: this.namespace,
|
|
68
|
-
appId: this.appId,
|
|
69
|
-
guid: this.guid,
|
|
70
|
-
role: stream_1.StreamRole.ENGINE,
|
|
71
|
-
reclaimDelay: config.engine.reclaimDelay,
|
|
72
|
-
reclaimCount: config.engine.reclaimCount,
|
|
73
|
-
throttle,
|
|
74
|
-
readonly: config.engine.readonly,
|
|
75
|
-
}, this.stream, this.store, this.logger);
|
|
76
|
-
}
|
|
77
|
-
async fetchAndVerifyVID(vid, count = 0) {
|
|
78
|
-
if (isNaN(Number(vid.version))) {
|
|
79
|
-
const app = await this.store.getApp(vid.id, true);
|
|
80
|
-
if (!isNaN(Number(app.version))) {
|
|
81
|
-
if (!this.apps)
|
|
82
|
-
this.apps = {};
|
|
83
|
-
this.apps[vid.id] = app;
|
|
84
|
-
return { id: vid.id, version: app.version };
|
|
85
|
-
}
|
|
86
|
-
else if (count < 10) {
|
|
87
|
-
await (0, utils_1.sleepFor)(enums_1.HMSH_QUORUM_DELAY_MS * 2);
|
|
88
|
-
return await this.fetchAndVerifyVID(vid, count + 1);
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
this.logger.error('engine-vid-resolution-error', {
|
|
92
|
-
id: vid.id,
|
|
93
|
-
guid: this.guid,
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return vid;
|
|
98
|
-
}
|
|
99
|
-
async getVID(vid) {
|
|
100
|
-
if (this.cacheMode === 'nocache') {
|
|
101
|
-
const app = await this.store.getApp(this.appId, true);
|
|
102
|
-
if (app.version.toString() === this.untilVersion.toString()) {
|
|
103
|
-
if (!this.apps)
|
|
104
|
-
this.apps = {};
|
|
105
|
-
this.apps[this.appId] = app;
|
|
106
|
-
this.setCacheMode('cache', app.version.toString());
|
|
107
|
-
}
|
|
108
|
-
return { id: this.appId, version: app.version };
|
|
109
|
-
}
|
|
110
|
-
else if (!this.apps && vid) {
|
|
111
|
-
this.apps = {};
|
|
112
|
-
this.apps[this.appId] = vid;
|
|
113
|
-
return vid;
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
return await this.fetchAndVerifyVID({
|
|
117
|
-
id: this.appId,
|
|
118
|
-
version: this.apps?.[this.appId].version,
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
setCacheMode(cacheMode, untilVersion) {
|
|
123
|
-
this.logger.info(`engine-executable-cache`, {
|
|
124
|
-
mode: cacheMode,
|
|
125
|
-
[cacheMode === 'cache' ? 'target' : 'until']: untilVersion,
|
|
126
|
-
});
|
|
127
|
-
this.cacheMode = cacheMode;
|
|
128
|
-
this.untilVersion = untilVersion;
|
|
129
|
-
}
|
|
130
|
-
async routeToSubscribers(topic, message) {
|
|
131
|
-
const jobCallback = this.jobCallbacks[message.metadata.jid];
|
|
132
|
-
if (jobCallback) {
|
|
133
|
-
this.delistJobCallback(message.metadata.jid);
|
|
134
|
-
jobCallback(topic, message);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
async processWebHooks() {
|
|
138
|
-
this.taskService.processWebHooks(this.hook.bind(this));
|
|
139
|
-
}
|
|
140
|
-
async processTimeHooks() {
|
|
141
|
-
this.taskService.processTimeHooks(this.hookTime.bind(this));
|
|
142
|
-
}
|
|
143
|
-
async throttle(delayInMillis) {
|
|
144
|
-
try {
|
|
145
|
-
this.router.setThrottle(delayInMillis);
|
|
146
|
-
}
|
|
147
|
-
catch (e) {
|
|
148
|
-
this.logger.error('engine-throttle-error', { error: e });
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
async initActivity(topic, data = {}, context) {
|
|
152
|
-
const [activityId, schema] = await this.getSchema(topic);
|
|
153
|
-
const ActivityHandler = activities_1.default[utils_1.polyfill.resolveActivityType(schema.type)];
|
|
154
|
-
if (ActivityHandler) {
|
|
155
|
-
const utc = (0, utils_1.formatISODate)(new Date());
|
|
156
|
-
const metadata = {
|
|
157
|
-
aid: activityId,
|
|
158
|
-
atp: schema.type,
|
|
159
|
-
stp: schema.subtype,
|
|
160
|
-
ac: utc,
|
|
161
|
-
au: utc,
|
|
162
|
-
};
|
|
163
|
-
const hook = null;
|
|
164
|
-
return new ActivityHandler(schema, data, metadata, hook, this, context);
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
throw new Error(`activity type ${schema.type} not found`);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
async getSchema(topic) {
|
|
171
|
-
const app = (await this.store.getApp(this.appId));
|
|
172
|
-
if (!app) {
|
|
173
|
-
throw new Error(`no app found for id ${this.appId}`);
|
|
174
|
-
}
|
|
175
|
-
if (this.isPrivate(topic)) {
|
|
176
|
-
const activityId = topic.substring(1);
|
|
177
|
-
const schema = await this.store.getSchema(activityId, await this.getVID(app));
|
|
178
|
-
return [activityId, schema];
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
181
|
-
const activityId = await this.store.getSubscription(topic, await this.getVID(app));
|
|
182
|
-
if (activityId) {
|
|
183
|
-
const schema = await this.store.getSchema(activityId, await this.getVID(app));
|
|
184
|
-
return [activityId, schema];
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
throw new Error(`no subscription found for topic ${topic} in app ${this.appId} for app version ${app.version}`);
|
|
188
|
-
}
|
|
189
|
-
async getSettings() {
|
|
190
|
-
return await this.store.getSettings();
|
|
191
|
-
}
|
|
192
|
-
isPrivate(topic) {
|
|
193
|
-
return topic.startsWith('.');
|
|
194
|
-
}
|
|
195
|
-
async plan(pathOrYAML) {
|
|
196
|
-
const compiler = new compiler_1.CompilerService(this.store, this.logger);
|
|
197
|
-
return await compiler.plan(pathOrYAML);
|
|
198
|
-
}
|
|
199
|
-
async deploy(pathOrYAML) {
|
|
200
|
-
const compiler = new compiler_1.CompilerService(this.store, this.logger);
|
|
201
|
-
return await compiler.deploy(pathOrYAML);
|
|
202
|
-
}
|
|
203
|
-
async getStats(topic, query) {
|
|
204
|
-
const { id, version } = await this.getVID();
|
|
205
|
-
const reporter = new reporter_1.ReporterService({ id, version }, this.store, this.logger);
|
|
206
|
-
const resolvedQuery = await this.resolveQuery(topic, query);
|
|
207
|
-
return await reporter.getStats(resolvedQuery);
|
|
208
|
-
}
|
|
209
|
-
async getIds(topic, query, queryFacets = []) {
|
|
210
|
-
const { id, version } = await this.getVID();
|
|
211
|
-
const reporter = new reporter_1.ReporterService({ id, version }, this.store, this.logger);
|
|
212
|
-
const resolvedQuery = await this.resolveQuery(topic, query);
|
|
213
|
-
return await reporter.getIds(resolvedQuery, queryFacets);
|
|
214
|
-
}
|
|
215
|
-
async resolveQuery(topic, query) {
|
|
216
|
-
const trigger = (await this.initActivity(topic, query.data));
|
|
217
|
-
await trigger.getState();
|
|
218
|
-
return {
|
|
219
|
-
end: query.end,
|
|
220
|
-
start: query.start,
|
|
221
|
-
range: query.range,
|
|
222
|
-
granularity: trigger.resolveGranularity(),
|
|
223
|
-
key: trigger.resolveJobKey(trigger.createInputContext()),
|
|
224
|
-
sparse: query.sparse,
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
async processStreamMessage(streamData) {
|
|
228
|
-
this.logger.debug('engine-process', {
|
|
229
|
-
jid: streamData.metadata.jid,
|
|
230
|
-
gid: streamData.metadata.gid,
|
|
231
|
-
dad: streamData.metadata.dad,
|
|
232
|
-
aid: streamData.metadata.aid,
|
|
233
|
-
status: streamData.status || stream_1.StreamStatus.SUCCESS,
|
|
234
|
-
code: streamData.code || 200,
|
|
235
|
-
type: streamData.type,
|
|
236
|
-
});
|
|
237
|
-
const context = {
|
|
238
|
-
metadata: {
|
|
239
|
-
guid: streamData.metadata.guid,
|
|
240
|
-
jid: streamData.metadata.jid,
|
|
241
|
-
gid: streamData.metadata.gid,
|
|
242
|
-
dad: streamData.metadata.dad,
|
|
243
|
-
aid: streamData.metadata.aid,
|
|
244
|
-
},
|
|
245
|
-
data: streamData.data,
|
|
246
|
-
};
|
|
247
|
-
if (streamData.type === stream_1.StreamDataType.TIMEHOOK) {
|
|
248
|
-
const activityHandler = (await this.initActivity(`.${streamData.metadata.aid}`, context.data, context));
|
|
249
|
-
await activityHandler.processTimeHookEvent(streamData.metadata.jid);
|
|
250
|
-
}
|
|
251
|
-
else if (streamData.type === stream_1.StreamDataType.WEBHOOK) {
|
|
252
|
-
const activityHandler = (await this.initActivity(`.${streamData.metadata.aid}`, context.data, context));
|
|
253
|
-
await activityHandler.processWebHookEvent(streamData.status, streamData.code);
|
|
254
|
-
}
|
|
255
|
-
else if (streamData.type === stream_1.StreamDataType.TRANSITION) {
|
|
256
|
-
const activityHandler = (await this.initActivity(`.${streamData.metadata.aid}`, context.data, context));
|
|
257
|
-
await activityHandler.process();
|
|
258
|
-
}
|
|
259
|
-
else if (streamData.type === stream_1.StreamDataType.AWAIT) {
|
|
260
|
-
context.metadata = {
|
|
261
|
-
...context.metadata,
|
|
262
|
-
pj: streamData.metadata.jid,
|
|
263
|
-
pg: streamData.metadata.gid,
|
|
264
|
-
pd: streamData.metadata.dad,
|
|
265
|
-
pa: streamData.metadata.aid,
|
|
266
|
-
px: streamData.metadata.await === false,
|
|
267
|
-
trc: streamData.metadata.trc,
|
|
268
|
-
spn: streamData.metadata.spn,
|
|
269
|
-
};
|
|
270
|
-
const activityHandler = (await this.initActivity(streamData.metadata.topic, streamData.data, context));
|
|
271
|
-
await activityHandler.process();
|
|
272
|
-
}
|
|
273
|
-
else if (streamData.type === stream_1.StreamDataType.RESULT) {
|
|
274
|
-
const activityHandler = (await this.initActivity(`.${context.metadata.aid}`, streamData.data, context));
|
|
275
|
-
await activityHandler.processEvent(streamData.status, streamData.code);
|
|
276
|
-
}
|
|
277
|
-
else {
|
|
278
|
-
const activityHandler = (await this.initActivity(`.${streamData.metadata.aid}`, streamData.data, context));
|
|
279
|
-
await activityHandler.processEvent(streamData.status, streamData.code, 'output');
|
|
280
|
-
}
|
|
281
|
-
this.logger.debug('engine-process-end', {
|
|
282
|
-
jid: streamData.metadata.jid,
|
|
283
|
-
gid: streamData.metadata.gid,
|
|
284
|
-
aid: streamData.metadata.aid,
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
async execAdjacentParent(context, jobOutput, emit = false) {
|
|
288
|
-
if (this.hasParentJob(context)) {
|
|
289
|
-
const error = this.resolveError(jobOutput.metadata);
|
|
290
|
-
const spn = context['$self']?.output?.metadata?.l2s ||
|
|
291
|
-
context['$self']?.output?.metadata?.l1s;
|
|
292
|
-
const streamData = {
|
|
293
|
-
metadata: {
|
|
294
|
-
guid: (0, utils_1.guid)(),
|
|
295
|
-
jid: context.metadata.pj,
|
|
296
|
-
gid: context.metadata.pg,
|
|
297
|
-
dad: context.metadata.pd,
|
|
298
|
-
aid: context.metadata.pa,
|
|
299
|
-
trc: context.metadata.trc,
|
|
300
|
-
spn,
|
|
301
|
-
},
|
|
302
|
-
type: stream_1.StreamDataType.RESULT,
|
|
303
|
-
data: jobOutput.data,
|
|
304
|
-
};
|
|
305
|
-
if (error && error.code) {
|
|
306
|
-
streamData.status = stream_1.StreamStatus.ERROR;
|
|
307
|
-
streamData.data = error;
|
|
308
|
-
streamData.code = error.code;
|
|
309
|
-
streamData.stack = error.stack;
|
|
310
|
-
}
|
|
311
|
-
else if (emit) {
|
|
312
|
-
streamData.status = stream_1.StreamStatus.PENDING;
|
|
313
|
-
streamData.code = enums_1.HMSH_CODE_PENDING;
|
|
314
|
-
}
|
|
315
|
-
else {
|
|
316
|
-
streamData.status = stream_1.StreamStatus.SUCCESS;
|
|
317
|
-
streamData.code = enums_1.HMSH_CODE_SUCCESS;
|
|
318
|
-
}
|
|
319
|
-
return (await this.router?.publishMessage(null, streamData));
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
hasParentJob(context, checkSevered = false) {
|
|
323
|
-
if (checkSevered) {
|
|
324
|
-
return Boolean(context.metadata.pj && context.metadata.pa && !context.metadata.px);
|
|
325
|
-
}
|
|
326
|
-
return Boolean(context.metadata.pj && context.metadata.pa);
|
|
327
|
-
}
|
|
328
|
-
resolveError(metadata) {
|
|
329
|
-
if (metadata && metadata.err) {
|
|
330
|
-
return JSON.parse(metadata.err);
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
async interrupt(topic, jobId, options = {}) {
|
|
334
|
-
await this.store.interrupt(topic, jobId, options);
|
|
335
|
-
const context = (await this.getState(topic, jobId));
|
|
336
|
-
const completionOpts = {
|
|
337
|
-
interrupt: options.descend,
|
|
338
|
-
expire: options.expire,
|
|
339
|
-
};
|
|
340
|
-
return (await this.runJobCompletionTasks(context, completionOpts));
|
|
341
|
-
}
|
|
342
|
-
async scrub(jobId) {
|
|
343
|
-
await this.store.scrub(jobId);
|
|
344
|
-
}
|
|
345
|
-
async hook(topic, data, status = stream_1.StreamStatus.SUCCESS, code = 200) {
|
|
346
|
-
const hookRule = await this.taskService.getHookRule(topic);
|
|
347
|
-
const [aid] = await this.getSchema(`.${hookRule.to}`);
|
|
348
|
-
const streamData = {
|
|
349
|
-
type: stream_1.StreamDataType.WEBHOOK,
|
|
350
|
-
status,
|
|
351
|
-
code,
|
|
352
|
-
metadata: {
|
|
353
|
-
guid: (0, utils_1.guid)(),
|
|
354
|
-
aid,
|
|
355
|
-
topic,
|
|
356
|
-
},
|
|
357
|
-
data,
|
|
358
|
-
};
|
|
359
|
-
return (await this.router.publishMessage(null, streamData));
|
|
360
|
-
}
|
|
361
|
-
async hookTime(jobId, gId, topicOrActivity, type) {
|
|
362
|
-
if (type === 'interrupt' || type === 'expire') {
|
|
363
|
-
return await this.interrupt(topicOrActivity, jobId, {
|
|
364
|
-
suppress: true,
|
|
365
|
-
expire: 1,
|
|
366
|
-
});
|
|
367
|
-
}
|
|
368
|
-
const [aid, ...dimensions] = topicOrActivity.split(',');
|
|
369
|
-
const dad = `,${dimensions.join(',')}`;
|
|
370
|
-
const streamData = {
|
|
371
|
-
type: stream_1.StreamDataType.TIMEHOOK,
|
|
372
|
-
metadata: {
|
|
373
|
-
guid: (0, utils_1.guid)(),
|
|
374
|
-
jid: jobId,
|
|
375
|
-
gid: gId,
|
|
376
|
-
dad,
|
|
377
|
-
aid,
|
|
378
|
-
},
|
|
379
|
-
data: { timestamp: Date.now() },
|
|
380
|
-
};
|
|
381
|
-
await this.router.publishMessage(null, streamData);
|
|
382
|
-
}
|
|
383
|
-
async hookAll(hookTopic, data, keyResolver, queryFacets = []) {
|
|
384
|
-
const config = await this.getVID();
|
|
385
|
-
const hookRule = await this.taskService.getHookRule(hookTopic);
|
|
386
|
-
if (hookRule) {
|
|
387
|
-
const subscriptionTopic = await (0, utils_1.getSubscriptionTopic)(hookRule.to, this.store, config);
|
|
388
|
-
const resolvedQuery = await this.resolveQuery(subscriptionTopic, keyResolver);
|
|
389
|
-
const reporter = new reporter_1.ReporterService(config, this.store, this.logger);
|
|
390
|
-
const workItems = await reporter.getWorkItems(resolvedQuery, queryFacets);
|
|
391
|
-
if (workItems.length) {
|
|
392
|
-
const taskService = new task_1.TaskService(this.store, this.logger);
|
|
393
|
-
await taskService.enqueueWorkItems(workItems.map((workItem) => [
|
|
394
|
-
hookTopic,
|
|
395
|
-
workItem,
|
|
396
|
-
keyResolver.scrub || false,
|
|
397
|
-
JSON.stringify(data),
|
|
398
|
-
].join(key_1.VALSEP)));
|
|
399
|
-
this.store.publish(key_1.KeyType.QUORUM, { type: 'work', originator: this.guid }, this.appId);
|
|
400
|
-
}
|
|
401
|
-
return workItems;
|
|
402
|
-
}
|
|
403
|
-
else {
|
|
404
|
-
throw new Error(`unable to find hook rule for topic ${hookTopic}`);
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
async pub(topic, data, context, extended) {
|
|
408
|
-
const activityHandler = await this.initActivity(topic, data, context);
|
|
409
|
-
if (activityHandler) {
|
|
410
|
-
return await activityHandler.process(extended);
|
|
411
|
-
}
|
|
412
|
-
else {
|
|
413
|
-
throw new Error(`unable to process activity for topic ${topic}`);
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
async sub(topic, callback) {
|
|
417
|
-
const subscriptionCallback = async (topic, message) => {
|
|
418
|
-
callback(message.topic, message.job);
|
|
419
|
-
};
|
|
420
|
-
return await this.subscribe.subscribe(key_1.KeyType.QUORUM, subscriptionCallback, this.appId, topic);
|
|
421
|
-
}
|
|
422
|
-
async unsub(topic) {
|
|
423
|
-
return await this.subscribe.unsubscribe(key_1.KeyType.QUORUM, this.appId, topic);
|
|
424
|
-
}
|
|
425
|
-
async psub(wild, callback) {
|
|
426
|
-
const subscriptionCallback = async (topic, message) => {
|
|
427
|
-
callback(message.topic, message.job);
|
|
428
|
-
};
|
|
429
|
-
return await this.subscribe.psubscribe(key_1.KeyType.QUORUM, subscriptionCallback, this.appId, wild);
|
|
430
|
-
}
|
|
431
|
-
async punsub(wild) {
|
|
432
|
-
return await this.subscribe.punsubscribe(key_1.KeyType.QUORUM, this.appId, wild);
|
|
433
|
-
}
|
|
434
|
-
async pubsub(topic, data, context, timeout = enums_1.HMSH_OTT_WAIT_TIME) {
|
|
435
|
-
context = {
|
|
436
|
-
metadata: {
|
|
437
|
-
ngn: this.guid,
|
|
438
|
-
trc: context?.metadata?.trc,
|
|
439
|
-
spn: context?.metadata?.spn,
|
|
440
|
-
},
|
|
441
|
-
};
|
|
442
|
-
const jobId = await this.pub(topic, data, context);
|
|
443
|
-
return new Promise((resolve, reject) => {
|
|
444
|
-
this.registerJobCallback(jobId, (topic, output) => {
|
|
445
|
-
if (output.metadata.err) {
|
|
446
|
-
const error = JSON.parse(output.metadata.err);
|
|
447
|
-
reject({
|
|
448
|
-
...error,
|
|
449
|
-
job_id: output.metadata.jid,
|
|
450
|
-
});
|
|
451
|
-
}
|
|
452
|
-
else {
|
|
453
|
-
resolve(output);
|
|
454
|
-
}
|
|
455
|
-
});
|
|
456
|
-
setTimeout(() => {
|
|
457
|
-
this.delistJobCallback(jobId);
|
|
458
|
-
reject({
|
|
459
|
-
code: enums_1.HMSH_CODE_TIMEOUT,
|
|
460
|
-
message: 'timeout',
|
|
461
|
-
job_id: jobId,
|
|
462
|
-
});
|
|
463
|
-
}, timeout);
|
|
464
|
-
});
|
|
465
|
-
}
|
|
466
|
-
async pubOneTimeSubs(context, jobOutput, emit = false) {
|
|
467
|
-
if (this.hasOneTimeSubscription(context)) {
|
|
468
|
-
const message = {
|
|
469
|
-
type: 'job',
|
|
470
|
-
topic: context.metadata.jid,
|
|
471
|
-
job: (0, utils_1.restoreHierarchy)(jobOutput),
|
|
472
|
-
};
|
|
473
|
-
this.store.publish(key_1.KeyType.QUORUM, message, this.appId, context.metadata.ngn);
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
async getPublishesTopic(context) {
|
|
477
|
-
const config = await this.getVID();
|
|
478
|
-
const activityId = context.metadata.aid || context['$self']?.output?.metadata?.aid;
|
|
479
|
-
const schema = await this.store.getSchema(activityId, config);
|
|
480
|
-
return schema.publishes;
|
|
481
|
-
}
|
|
482
|
-
async pubPermSubs(context, jobOutput, emit = false) {
|
|
483
|
-
const topic = await this.getPublishesTopic(context);
|
|
484
|
-
if (topic) {
|
|
485
|
-
const message = {
|
|
486
|
-
type: 'job',
|
|
487
|
-
topic,
|
|
488
|
-
job: (0, utils_1.restoreHierarchy)(jobOutput),
|
|
489
|
-
};
|
|
490
|
-
this.store.publish(key_1.KeyType.QUORUM, message, this.appId, `${topic}.${context.metadata.jid}`);
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
async add(streamData) {
|
|
494
|
-
return (await this.router.publishMessage(null, streamData));
|
|
495
|
-
}
|
|
496
|
-
registerJobCallback(jobId, jobCallback) {
|
|
497
|
-
this.jobCallbacks[jobId] = jobCallback;
|
|
498
|
-
}
|
|
499
|
-
delistJobCallback(jobId) {
|
|
500
|
-
delete this.jobCallbacks[jobId];
|
|
501
|
-
}
|
|
502
|
-
hasOneTimeSubscription(context) {
|
|
503
|
-
return Boolean(context.metadata.ngn);
|
|
504
|
-
}
|
|
505
|
-
async runJobCompletionTasks(context, options = {}) {
|
|
506
|
-
const isAwait = this.hasParentJob(context, true);
|
|
507
|
-
const isOneTimeSub = this.hasOneTimeSubscription(context);
|
|
508
|
-
const topic = await this.getPublishesTopic(context);
|
|
509
|
-
let msgId;
|
|
510
|
-
if (isAwait || isOneTimeSub || topic) {
|
|
511
|
-
const jobOutput = await this.getState(context.metadata.tpc, context.metadata.jid);
|
|
512
|
-
msgId = await this.execAdjacentParent(context, jobOutput, options.emit);
|
|
513
|
-
this.pubOneTimeSubs(context, jobOutput, options.emit);
|
|
514
|
-
this.pubPermSubs(context, jobOutput, options.emit);
|
|
515
|
-
}
|
|
516
|
-
if (!options.emit) {
|
|
517
|
-
this.taskService.registerJobForCleanup(context.metadata.jid, this.resolveExpires(context, options), options);
|
|
518
|
-
}
|
|
519
|
-
return msgId;
|
|
520
|
-
}
|
|
521
|
-
resolveExpires(context, options) {
|
|
522
|
-
return options.expire ?? context.metadata.expire ?? enums_1.HMSH_EXPIRE_JOB_SECONDS;
|
|
523
|
-
}
|
|
524
|
-
async export(jobId) {
|
|
525
|
-
return await this.exporter.export(jobId);
|
|
526
|
-
}
|
|
527
|
-
async getRaw(jobId) {
|
|
528
|
-
return await this.store.getRaw(jobId);
|
|
529
|
-
}
|
|
530
|
-
async getStatus(jobId) {
|
|
531
|
-
const { id: appId } = await this.getVID();
|
|
532
|
-
return await this.store.getStatus(jobId, appId);
|
|
533
|
-
}
|
|
534
|
-
async getState(topic, jobId) {
|
|
535
|
-
const jobSymbols = await this.store.getSymbols(`$${topic}`);
|
|
536
|
-
const consumes = {
|
|
537
|
-
[`$${topic}`]: Object.keys(jobSymbols),
|
|
538
|
-
};
|
|
539
|
-
const dIds = {};
|
|
540
|
-
const output = await this.store.getState(jobId, consumes, dIds);
|
|
541
|
-
if (!output) {
|
|
542
|
-
throw new Error(`not found ${jobId}`);
|
|
543
|
-
}
|
|
544
|
-
const [state, status] = output;
|
|
545
|
-
const stateTree = (0, utils_1.restoreHierarchy)(state);
|
|
546
|
-
if (status && stateTree.metadata) {
|
|
547
|
-
stateTree.metadata.js = status;
|
|
548
|
-
}
|
|
549
|
-
return stateTree;
|
|
550
|
-
}
|
|
551
|
-
async getQueryState(jobId, fields) {
|
|
552
|
-
return await this.store.getQueryState(jobId, fields);
|
|
553
|
-
}
|
|
554
|
-
async compress(terms) {
|
|
555
|
-
const existingSymbols = await this.store.getSymbolValues();
|
|
556
|
-
const startIndex = Object.keys(existingSymbols).length;
|
|
557
|
-
const maxIndex = Math.pow(52, 2) - 1;
|
|
558
|
-
const newSymbols = serializer_1.SerializerService.filterSymVals(startIndex, maxIndex, existingSymbols, new Set(terms));
|
|
559
|
-
return await this.store.addSymbolValues(newSymbols);
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
exports.EngineService = EngineService;
|
|
1
|
+
'use strict';(function(_0x11b0f6,_0x2b685d){const _0x2bbb11=_0xd44c,_0x867552=_0x11b0f6();while(!![]){try{const _0x2016d6=parseInt(_0x2bbb11(0x128))/0x1*(parseInt(_0x2bbb11(0x12e))/0x2)+parseInt(_0x2bbb11(0x126))/0x3*(parseInt(_0x2bbb11(0x130))/0x4)+-parseInt(_0x2bbb11(0x129))/0x5*(parseInt(_0x2bbb11(0x12c))/0x6)+-parseInt(_0x2bbb11(0x12d))/0x7+parseInt(_0x2bbb11(0x12a))/0x8*(parseInt(_0x2bbb11(0x127))/0x9)+parseInt(_0x2bbb11(0x125))/0xa*(-parseInt(_0x2bbb11(0x12b))/0xb)+parseInt(_0x2bbb11(0x12f))/0xc;if(_0x2016d6===_0x2b685d)break;else _0x867552['push'](_0x867552['shift']());}catch(_0x4b1e27){_0x867552['push'](_0x867552['shift']());}}}(_0xc6db,0x3de1b));var __importDefault=this&&this['__importDefault']||function(_0x52128f){return _0x52128f&&_0x52128f['__esModule']?_0x52128f:{'default':_0x52128f};};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'](_0x40b9ab,_0x4b4d82,_0x5d318a,_0x5bef8c,_0x377de9){if(_0x5bef8c['engine']){const _0x18e4a0=new EngineService();_0x18e4a0['verifyEngineFields'](_0x5bef8c),_0x18e4a0['namespace']=_0x40b9ab,_0x18e4a0['appId']=_0x4b4d82,_0x18e4a0['guid']=_0x5d318a,_0x18e4a0['logger']=_0x377de9,await _0x18e4a0['initSearchChannel'](_0x5bef8c['engine']['store']),await _0x18e4a0['initStoreChannel'](_0x5bef8c['engine']['store']),await _0x18e4a0['initSubChannel'](_0x5bef8c['engine']['sub'],_0x5bef8c['engine']['store']),await _0x18e4a0['initStreamChannel'](_0x5bef8c['engine']['stream'],_0x5bef8c['engine']['store']),_0x18e4a0['router']=await _0x18e4a0['initRouter'](_0x5bef8c);const _0x428b46=_0x18e4a0['store']['mintKey'](key_1['KeyType']['STREAMS'],{'appId':_0x18e4a0['appId']});return _0x18e4a0['router']['consumeMessages'](_0x428b46,'ENGINE',_0x18e4a0['guid'],_0x18e4a0['processStreamMessage']['bind'](_0x18e4a0)),_0x18e4a0['taskService']=new task_1['TaskService'](_0x18e4a0['store'],_0x377de9),_0x18e4a0['exporter']=new exporter_1['ExporterService'](_0x18e4a0['appId'],_0x18e4a0['store'],_0x377de9),_0x18e4a0['inited']=(0x0,utils_1['formatISODate'])(new Date()),_0x18e4a0;}}['verifyEngineFields'](_0x55c70d){if(!(0x0,utils_1['identifyRedisType'])(_0x55c70d['engine']['store'])||!(0x0,utils_1['identifyRedisType'])(_0x55c70d['engine']['stream'])||!(0x0,utils_1['identifyRedisType'])(_0x55c70d['engine']['sub']))throw new Error('engine\x20config\x20must\x20reference\x203\x20redis\x20client\x20instances');}async['initSearchChannel'](_0x41929a,_0xc3e149){this['search']=await factory_4['SearchServiceFactory']['init'](_0x41929a,_0xc3e149,this['namespace'],this['appId'],this['logger']);}async['initStoreChannel'](_0x5c4a67){this['store']=await factory_3['StoreServiceFactory']['init'](_0x5c4a67,this['namespace'],this['appId'],this['logger']);}async['initSubChannel'](_0x5f427b,_0x39ddfc){this['subscribe']=await factory_2['SubServiceFactory']['init'](_0x5f427b,_0x39ddfc,this['namespace'],this['appId'],this['guid'],this['logger']);}async['initStreamChannel'](_0x1744e4,_0x2c99c6){this['stream']=await factory_1['StreamServiceFactory']['init'](_0x1744e4,_0x2c99c6,this['namespace'],this['appId'],this['logger']);}async['initRouter'](_0x233a1a){const _0xd386ad=await this['store']['getThrottleRate'](':');return new router_1['Router']({'namespace':this['namespace'],'appId':this['appId'],'guid':this['guid'],'role':stream_1['StreamRole']['ENGINE'],'reclaimDelay':_0x233a1a['engine']['reclaimDelay'],'reclaimCount':_0x233a1a['engine']['reclaimCount'],'throttle':_0xd386ad,'readonly':_0x233a1a['engine']['readonly']},this['stream'],this['store'],this['logger']);}async['fetchAndVerifyVID'](_0x5b342f,_0x3fe3e8=0x0){if(isNaN(Number(_0x5b342f['version']))){const _0x62f25b=await this['store']['getApp'](_0x5b342f['id'],!![]);if(!isNaN(Number(_0x62f25b['version']))){if(!this['apps'])this['apps']={};return this['apps'][_0x5b342f['id']]=_0x62f25b,{'id':_0x5b342f['id'],'version':_0x62f25b['version']};}else{if(_0x3fe3e8<0xa)return await(0x0,utils_1['sleepFor'])(enums_1['HMSH_QUORUM_DELAY_MS']*0x2),await this['fetchAndVerifyVID'](_0x5b342f,_0x3fe3e8+0x1);else this['logger']['error']('engine-vid-resolution-error',{'id':_0x5b342f['id'],'guid':this['guid']});}}return _0x5b342f;}async['getVID'](_0x4feced){if(this['cacheMode']==='nocache'){const _0x273d5e=await this['store']['getApp'](this['appId'],!![]);if(_0x273d5e['version']['toString']()===this['untilVersion']['toString']()){if(!this['apps'])this['apps']={};this['apps'][this['appId']]=_0x273d5e,this['setCacheMode']('cache',_0x273d5e['version']['toString']());}return{'id':this['appId'],'version':_0x273d5e['version']};}else return!this['apps']&&_0x4feced?(this['apps']={},this['apps'][this['appId']]=_0x4feced,_0x4feced):await this['fetchAndVerifyVID']({'id':this['appId'],'version':this['apps']?.[this['appId']]['version']});}['setCacheMode'](_0x1492fe,_0x12e4a7){this['logger']['info']('engine-executable-cache',{'mode':_0x1492fe,[_0x1492fe==='cache'?'target':'until']:_0x12e4a7}),this['cacheMode']=_0x1492fe,this['untilVersion']=_0x12e4a7;}async['routeToSubscribers'](_0x27350e,_0x2a9d41){const _0x1db86a=this['jobCallbacks'][_0x2a9d41['metadata']['jid']];_0x1db86a&&(this['delistJobCallback'](_0x2a9d41['metadata']['jid']),_0x1db86a(_0x27350e,_0x2a9d41));}async['processWebHooks'](){this['taskService']['processWebHooks'](this['hook']['bind'](this));}async['processTimeHooks'](){this['taskService']['processTimeHooks'](this['hookTime']['bind'](this));}async['throttle'](_0x642c7d){try{this['router']['setThrottle'](_0x642c7d);}catch(_0x485436){this['logger']['error']('engine-throttle-error',{'error':_0x485436});}}async['initActivity'](_0x371138,_0x254115={},_0x4e28c8){const [_0x43d13b,_0x374af4]=await this['getSchema'](_0x371138),_0x3b7d23=activities_1['default'][utils_1['polyfill']['resolveActivityType'](_0x374af4['type'])];if(_0x3b7d23){const _0x3b0e6e=(0x0,utils_1['formatISODate'])(new Date()),_0x98f6f8={'aid':_0x43d13b,'atp':_0x374af4['type'],'stp':_0x374af4['subtype'],'ac':_0x3b0e6e,'au':_0x3b0e6e},_0x25f904=null;return new _0x3b7d23(_0x374af4,_0x254115,_0x98f6f8,_0x25f904,this,_0x4e28c8);}else throw new Error('activity\x20type\x20'+_0x374af4['type']+'\x20not\x20found');}async['getSchema'](_0x3a07d3){const _0x49bd3b=await this['store']['getApp'](this['appId']);if(!_0x49bd3b)throw new Error('no\x20app\x20found\x20for\x20id\x20'+this['appId']);if(this['isPrivate'](_0x3a07d3)){const _0x54e34d=_0x3a07d3['substring'](0x1),_0x5eaf98=await this['store']['getSchema'](_0x54e34d,await this['getVID'](_0x49bd3b));return[_0x54e34d,_0x5eaf98];}else{const _0x52e96c=await this['store']['getSubscription'](_0x3a07d3,await this['getVID'](_0x49bd3b));if(_0x52e96c){const _0x224283=await this['store']['getSchema'](_0x52e96c,await this['getVID'](_0x49bd3b));return[_0x52e96c,_0x224283];}}throw new Error('no\x20subscription\x20found\x20for\x20topic\x20'+_0x3a07d3+'\x20in\x20app\x20'+this['appId']+'\x20for\x20app\x20version\x20'+_0x49bd3b['version']);}async['getSettings'](){return await this['store']['getSettings']();}['isPrivate'](_0x10dd02){return _0x10dd02['startsWith']('.');}async['plan'](_0x5077c6){const _0x88ba49=new compiler_1['CompilerService'](this['store'],this['stream'],this['logger']);return await _0x88ba49['plan'](_0x5077c6);}async['deploy'](_0x2de35a){const _0x55a139=new compiler_1['CompilerService'](this['store'],this['stream'],this['logger']);return await _0x55a139['deploy'](_0x2de35a);}async['getStats'](_0x4b7480,_0x439ea3){const {id:_0x18d658,version:_0x339090}=await this['getVID'](),_0x1bc1e1=new reporter_1['ReporterService']({'id':_0x18d658,'version':_0x339090},this['store'],this['logger']),_0x1e3fb1=await this['resolveQuery'](_0x4b7480,_0x439ea3);return await _0x1bc1e1['getStats'](_0x1e3fb1);}async['getIds'](_0x650207,_0x342817,_0x57914a=[]){const {id:_0x44e2d2,version:_0x1b2877}=await this['getVID'](),_0x4b2991=new reporter_1['ReporterService']({'id':_0x44e2d2,'version':_0x1b2877},this['store'],this['logger']),_0x336650=await this['resolveQuery'](_0x650207,_0x342817);return await _0x4b2991['getIds'](_0x336650,_0x57914a);}async['resolveQuery'](_0x248943,_0x231fdd){const _0x5d5f0d=await this['initActivity'](_0x248943,_0x231fdd['data']);return await _0x5d5f0d['getState'](),{'end':_0x231fdd['end'],'start':_0x231fdd['start'],'range':_0x231fdd['range'],'granularity':_0x5d5f0d['resolveGranularity'](),'key':_0x5d5f0d['resolveJobKey'](_0x5d5f0d['createInputContext']()),'sparse':_0x231fdd['sparse']};}async['processStreamMessage'](_0x57979a){this['logger']['debug']('engine-process',{'jid':_0x57979a['metadata']['jid'],'gid':_0x57979a['metadata']['gid'],'dad':_0x57979a['metadata']['dad'],'aid':_0x57979a['metadata']['aid'],'status':_0x57979a['status']||stream_1['StreamStatus']['SUCCESS'],'code':_0x57979a['code']||0xc8,'type':_0x57979a['type']});const _0x292732={'metadata':{'guid':_0x57979a['metadata']['guid'],'jid':_0x57979a['metadata']['jid'],'gid':_0x57979a['metadata']['gid'],'dad':_0x57979a['metadata']['dad'],'aid':_0x57979a['metadata']['aid']},'data':_0x57979a['data']};if(_0x57979a['type']===stream_1['StreamDataType']['TIMEHOOK']){const _0x10c158=await this['initActivity']('.'+_0x57979a['metadata']['aid'],_0x292732['data'],_0x292732);await _0x10c158['processTimeHookEvent'](_0x57979a['metadata']['jid']);}else{if(_0x57979a['type']===stream_1['StreamDataType']['WEBHOOK']){const _0x2d4255=await this['initActivity']('.'+_0x57979a['metadata']['aid'],_0x292732['data'],_0x292732);await _0x2d4255['processWebHookEvent'](_0x57979a['status'],_0x57979a['code']);}else{if(_0x57979a['type']===stream_1['StreamDataType']['TRANSITION']){const _0x4cd2f9=await this['initActivity']('.'+_0x57979a['metadata']['aid'],_0x292732['data'],_0x292732);await _0x4cd2f9['process']();}else{if(_0x57979a['type']===stream_1['StreamDataType']['AWAIT']){_0x292732['metadata']={..._0x292732['metadata'],'pj':_0x57979a['metadata']['jid'],'pg':_0x57979a['metadata']['gid'],'pd':_0x57979a['metadata']['dad'],'pa':_0x57979a['metadata']['aid'],'px':_0x57979a['metadata']['await']===![],'trc':_0x57979a['metadata']['trc'],'spn':_0x57979a['metadata']['spn']};const _0x38faee=await this['initActivity'](_0x57979a['metadata']['topic'],_0x57979a['data'],_0x292732);await _0x38faee['process']();}else{if(_0x57979a['type']===stream_1['StreamDataType']['RESULT']){const _0x51642a=await this['initActivity']('.'+_0x292732['metadata']['aid'],_0x57979a['data'],_0x292732);await _0x51642a['processEvent'](_0x57979a['status'],_0x57979a['code']);}else{const _0x57a5dc=await this['initActivity']('.'+_0x57979a['metadata']['aid'],_0x57979a['data'],_0x292732);await _0x57a5dc['processEvent'](_0x57979a['status'],_0x57979a['code'],'output');}}}}}this['logger']['debug']('engine-process-end',{'jid':_0x57979a['metadata']['jid'],'gid':_0x57979a['metadata']['gid'],'aid':_0x57979a['metadata']['aid']});}async['execAdjacentParent'](_0x14a3b0,_0x211d51,_0x463eb0=![]){if(this['hasParentJob'](_0x14a3b0)){const _0x153beb=this['resolveError'](_0x211d51['metadata']),_0x2608db=_0x14a3b0['$self']?.['output']?.['metadata']?.['l2s']||_0x14a3b0['$self']?.['output']?.['metadata']?.['l1s'],_0x46f682={'metadata':{'guid':(0x0,utils_1['guid'])(),'jid':_0x14a3b0['metadata']['pj'],'gid':_0x14a3b0['metadata']['pg'],'dad':_0x14a3b0['metadata']['pd'],'aid':_0x14a3b0['metadata']['pa'],'trc':_0x14a3b0['metadata']['trc'],'spn':_0x2608db},'type':stream_1['StreamDataType']['RESULT'],'data':_0x211d51['data']};if(_0x153beb&&_0x153beb['code'])_0x46f682['status']=stream_1['StreamStatus']['ERROR'],_0x46f682['data']=_0x153beb,_0x46f682['code']=_0x153beb['code'],_0x46f682['stack']=_0x153beb['stack'];else _0x463eb0?(_0x46f682['status']=stream_1['StreamStatus']['PENDING'],_0x46f682['code']=enums_1['HMSH_CODE_PENDING']):(_0x46f682['status']=stream_1['StreamStatus']['SUCCESS'],_0x46f682['code']=enums_1['HMSH_CODE_SUCCESS']);return await this['router']?.['publishMessage'](null,_0x46f682);}}['hasParentJob'](_0x893832,_0xcdcefa=![]){if(_0xcdcefa)return Boolean(_0x893832['metadata']['pj']&&_0x893832['metadata']['pa']&&!_0x893832['metadata']['px']);return Boolean(_0x893832['metadata']['pj']&&_0x893832['metadata']['pa']);}['resolveError'](_0xf81660){if(_0xf81660&&_0xf81660['err'])return JSON['parse'](_0xf81660['err']);}async['interrupt'](_0x25e41f,_0x34a592,_0x45d270={}){await this['store']['interrupt'](_0x25e41f,_0x34a592,_0x45d270);const _0x6655f6=await this['getState'](_0x25e41f,_0x34a592),_0x2df8c9={'interrupt':_0x45d270['descend'],'expire':_0x45d270['expire']};return await this['runJobCompletionTasks'](_0x6655f6,_0x2df8c9);}async['scrub'](_0x17b96b){await this['store']['scrub'](_0x17b96b);}async['hook'](_0x2a0c96,_0x54aedc,_0x2168f3=stream_1['StreamStatus']['SUCCESS'],_0x4bb68e=0xc8){const _0x1d0d7a=await this['taskService']['getHookRule'](_0x2a0c96),[_0x23dd57]=await this['getSchema']('.'+_0x1d0d7a['to']),_0x27799d={'type':stream_1['StreamDataType']['WEBHOOK'],'status':_0x2168f3,'code':_0x4bb68e,'metadata':{'guid':(0x0,utils_1['guid'])(),'aid':_0x23dd57,'topic':_0x2a0c96},'data':_0x54aedc};return await this['router']['publishMessage'](null,_0x27799d);}async['hookTime'](_0x4d87d7,_0x5a9d66,_0x1fd8d9,_0x3b9e55){if(_0x3b9e55==='interrupt'||_0x3b9e55==='expire')return await this['interrupt'](_0x1fd8d9,_0x4d87d7,{'suppress':!![],'expire':0x1});const [_0x741ffe,..._0x1c7a91]=_0x1fd8d9['split'](','),_0x144590=','+_0x1c7a91['join'](','),_0x1e18ac={'type':stream_1['StreamDataType']['TIMEHOOK'],'metadata':{'guid':(0x0,utils_1['guid'])(),'jid':_0x4d87d7,'gid':_0x5a9d66,'dad':_0x144590,'aid':_0x741ffe},'data':{'timestamp':Date['now']()}};await this['router']['publishMessage'](null,_0x1e18ac);}async['hookAll'](_0x53fc6c,_0x2c193d,_0x208cdd,_0x347c0e=[]){const _0x39fd33=await this['getVID'](),_0x4b3125=await this['taskService']['getHookRule'](_0x53fc6c);if(_0x4b3125){const _0x300e17=await(0x0,utils_1['getSubscriptionTopic'])(_0x4b3125['to'],this['store'],_0x39fd33),_0x1654b3=await this['resolveQuery'](_0x300e17,_0x208cdd),_0x407c9f=new reporter_1['ReporterService'](_0x39fd33,this['store'],this['logger']),_0x254019=await _0x407c9f['getWorkItems'](_0x1654b3,_0x347c0e);if(_0x254019['length']){const _0x33e425=new task_1['TaskService'](this['store'],this['logger']);await _0x33e425['enqueueWorkItems'](_0x254019['map'](_0xada6e=>[_0x53fc6c,_0xada6e,_0x208cdd['scrub']||![],JSON['stringify'](_0x2c193d)]['join'](key_1['VALSEP']))),this['subscribe']['publish'](key_1['KeyType']['QUORUM'],{'type':'work','originator':this['guid']},this['appId']);}return _0x254019;}else throw new Error('unable\x20to\x20find\x20hook\x20rule\x20for\x20topic\x20'+_0x53fc6c);}async['pub'](_0x30b64a,_0x53ec0d,_0x572566,_0x319560){const _0x20cdc4=await this['initActivity'](_0x30b64a,_0x53ec0d,_0x572566);if(_0x20cdc4)return await _0x20cdc4['process'](_0x319560);else throw new Error('unable\x20to\x20process\x20activity\x20for\x20topic\x20'+_0x30b64a);}async['sub'](_0x35d78f,_0x269eca){const _0x73cd85=async(_0x75fbf1,_0x356bcc)=>{_0x269eca(_0x356bcc['topic'],_0x356bcc['job']);};return await this['subscribe']['subscribe'](key_1['KeyType']['QUORUM'],_0x73cd85,this['appId'],_0x35d78f);}async['unsub'](_0x224d9b){return await this['subscribe']['unsubscribe'](key_1['KeyType']['QUORUM'],this['appId'],_0x224d9b);}async['psub'](_0x9f0dfb,_0x329931){const _0x3a4572=async(_0x24f53f,_0x6ea174)=>{_0x329931(_0x6ea174['topic'],_0x6ea174['job']);};return await this['subscribe']['psubscribe'](key_1['KeyType']['QUORUM'],_0x3a4572,this['appId'],_0x9f0dfb);}async['punsub'](_0x261a88){return await this['subscribe']['punsubscribe'](key_1['KeyType']['QUORUM'],this['appId'],_0x261a88);}async['pubsub'](_0x30437c,_0x3dc08f,_0x431bf1,_0x1cb9cc=enums_1['HMSH_OTT_WAIT_TIME']){_0x431bf1={'metadata':{'ngn':this['guid'],'trc':_0x431bf1?.['metadata']?.['trc'],'spn':_0x431bf1?.['metadata']?.['spn']}};const _0x295b7c=await this['pub'](_0x30437c,_0x3dc08f,_0x431bf1);return new Promise((_0x4f8c33,_0x39297b)=>{this['registerJobCallback'](_0x295b7c,(_0x24d836,_0x5c0867)=>{if(_0x5c0867['metadata']['err']){const _0x24affa=JSON['parse'](_0x5c0867['metadata']['err']);_0x39297b({..._0x24affa,'job_id':_0x5c0867['metadata']['jid']});}else _0x4f8c33(_0x5c0867);}),setTimeout(()=>{this['delistJobCallback'](_0x295b7c),_0x39297b({'code':enums_1['HMSH_CODE_TIMEOUT'],'message':'timeout','job_id':_0x295b7c});},_0x1cb9cc);});}async['pubOneTimeSubs'](_0xa49e2a,_0x47bacb,_0x119619=![]){if(this['hasOneTimeSubscription'](_0xa49e2a)){const _0x3b68a9={'type':'job','topic':_0xa49e2a['metadata']['jid'],'job':(0x0,utils_1['restoreHierarchy'])(_0x47bacb)};this['subscribe']['publish'](key_1['KeyType']['QUORUM'],_0x3b68a9,this['appId'],_0xa49e2a['metadata']['ngn']);}}async['getPublishesTopic'](_0x3dba85){const _0x57b348=await this['getVID'](),_0x3780b7=_0x3dba85['metadata']['aid']||_0x3dba85['$self']?.['output']?.['metadata']?.['aid'],_0x2aaa70=await this['store']['getSchema'](_0x3780b7,_0x57b348);return _0x2aaa70['publishes'];}async['pubPermSubs'](_0x1ede49,_0x4ced98,_0x2d78d8=![]){const _0x29a9f6=await this['getPublishesTopic'](_0x1ede49);if(_0x29a9f6){const _0x1d329b={'type':'job','topic':_0x29a9f6,'job':(0x0,utils_1['restoreHierarchy'])(_0x4ced98)};this['subscribe']['publish'](key_1['KeyType']['QUORUM'],_0x1d329b,this['appId'],_0x29a9f6+'.'+_0x1ede49['metadata']['jid']);}}async['add'](_0x19d8fa){return await this['router']['publishMessage'](null,_0x19d8fa);}['registerJobCallback'](_0x4ce850,_0x3945ac){this['jobCallbacks'][_0x4ce850]=_0x3945ac;}['delistJobCallback'](_0x45bfe6){delete this['jobCallbacks'][_0x45bfe6];}['hasOneTimeSubscription'](_0x4b82bb){return Boolean(_0x4b82bb['metadata']['ngn']);}async['runJobCompletionTasks'](_0x580998,_0x520d3f={}){const _0x150b30=this['hasParentJob'](_0x580998,!![]),_0x21d696=this['hasOneTimeSubscription'](_0x580998),_0x1ebbe3=await this['getPublishesTopic'](_0x580998);let _0x5a5b06;if(_0x150b30||_0x21d696||_0x1ebbe3){const _0x259066=await this['getState'](_0x580998['metadata']['tpc'],_0x580998['metadata']['jid']);_0x5a5b06=await this['execAdjacentParent'](_0x580998,_0x259066,_0x520d3f['emit']),this['pubOneTimeSubs'](_0x580998,_0x259066,_0x520d3f['emit']),this['pubPermSubs'](_0x580998,_0x259066,_0x520d3f['emit']);}return!_0x520d3f['emit']&&this['taskService']['registerJobForCleanup'](_0x580998['metadata']['jid'],this['resolveExpires'](_0x580998,_0x520d3f),_0x520d3f),_0x5a5b06;}['resolveExpires'](_0x37373f,_0x423cf3){return _0x423cf3['expire']??_0x37373f['metadata']['expire']??enums_1['HMSH_EXPIRE_JOB_SECONDS'];}async['export'](_0x50ad38){return await this['exporter']['export'](_0x50ad38);}async['getRaw'](_0x339077){return await this['store']['getRaw'](_0x339077);}async['getStatus'](_0x35b35e){const {id:_0x22cbf0}=await this['getVID']();return await this['store']['getStatus'](_0x35b35e,_0x22cbf0);}async['getState'](_0x37e1b2,_0x17de57){const _0x4615a7=await this['store']['getSymbols']('$'+_0x37e1b2),_0x48cbde={['$'+_0x37e1b2]:Object['keys'](_0x4615a7)},_0x2c2882={},_0x458284=await this['store']['getState'](_0x17de57,_0x48cbde,_0x2c2882);if(!_0x458284)throw new Error('not\x20found\x20'+_0x17de57);const [_0x489b4f,_0x17facc]=_0x458284,_0x28ef55=(0x0,utils_1['restoreHierarchy'])(_0x489b4f);return _0x17facc&&_0x28ef55['metadata']&&(_0x28ef55['metadata']['js']=_0x17facc),_0x28ef55;}async['getQueryState'](_0x20423d,_0x1fb6e1){return await this['store']['getQueryState'](_0x20423d,_0x1fb6e1);}async['compress'](_0x1e8119){const _0x1ddd4c=await this['store']['getSymbolValues'](),_0x1dfbfd=Object['keys'](_0x1ddd4c)['length'],_0x4603eb=Math['pow'](0x34,0x2)-0x1,_0x1e5622=serializer_1['SerializerService']['filterSymVals'](_0x1dfbfd,_0x4603eb,_0x1ddd4c,new Set(_0x1e8119));return await this['store']['addSymbolValues'](_0x1e5622);}}function _0xd44c(_0x592ee5,_0x583bfa){const _0xc6db74=_0xc6db();return _0xd44c=function(_0xd44cb9,_0x119313){_0xd44cb9=_0xd44cb9-0x125;let _0x124b55=_0xc6db74[_0xd44cb9];return _0x124b55;},_0xd44c(_0x592ee5,_0x583bfa);}function _0xc6db(){const _0x4b2afa=['77432TSmxxA','10jsxwNB','51suQnED','9EeaLtS','192JAYWma','5sbeWvS','531224gViMjI','2868437vtUAQR','1871166ZNLENV','3187674CaFwPf','5126lVAzCY','4726704DaqFjD'];_0xc6db=function(){return _0x4b2afa;};return _0xc6db();}exports['EngineService']=EngineService;
|