@hotmeshio/hotmesh 0.4.0 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (284) hide show
  1. package/README.md +39 -14
  2. package/build/modules/enums.d.ts +110 -0
  3. package/build/modules/enums.js +134 -0
  4. package/build/modules/errors.d.ts +124 -0
  5. package/build/modules/errors.js +191 -0
  6. package/build/modules/key.d.ts +66 -0
  7. package/build/modules/key.js +190 -0
  8. package/build/modules/storage.d.ts +3 -0
  9. package/build/modules/storage.js +5 -0
  10. package/build/modules/utils.d.ts +119 -0
  11. package/build/modules/utils.js +374 -0
  12. package/build/package.json +1 -1
  13. package/build/services/activities/activity.d.ts +104 -0
  14. package/build/services/activities/activity.js +549 -0
  15. package/build/services/activities/await.d.ts +12 -0
  16. package/build/services/activities/await.js +114 -0
  17. package/build/services/activities/cycle.d.ts +19 -0
  18. package/build/services/activities/cycle.js +112 -0
  19. package/build/services/activities/hook.d.ts +27 -0
  20. package/build/services/activities/hook.js +168 -0
  21. package/build/services/activities/index.d.ts +19 -0
  22. package/build/services/activities/index.js +20 -0
  23. package/build/services/activities/interrupt.d.ts +16 -0
  24. package/build/services/activities/interrupt.js +158 -0
  25. package/build/services/activities/signal.d.ts +20 -0
  26. package/build/services/activities/signal.js +134 -0
  27. package/build/services/activities/trigger.d.ts +37 -0
  28. package/build/services/activities/trigger.js +246 -0
  29. package/build/services/activities/worker.d.ts +12 -0
  30. package/build/services/activities/worker.js +106 -0
  31. package/build/services/collator/index.d.ts +111 -0
  32. package/build/services/collator/index.js +293 -0
  33. package/build/services/compiler/deployer.d.ts +40 -0
  34. package/build/services/compiler/deployer.js +488 -0
  35. package/build/services/compiler/index.d.ts +32 -0
  36. package/build/services/compiler/index.js +112 -0
  37. package/build/services/compiler/validator.d.ts +34 -0
  38. package/build/services/compiler/validator.js +147 -0
  39. package/build/services/connector/factory.d.ts +22 -0
  40. package/build/services/connector/factory.js +99 -0
  41. package/build/services/connector/index.d.ts +30 -0
  42. package/build/services/connector/index.js +54 -0
  43. package/build/services/connector/providers/ioredis.d.ts +9 -0
  44. package/build/services/connector/providers/ioredis.js +26 -0
  45. package/build/services/connector/providers/nats.d.ts +9 -0
  46. package/build/services/connector/providers/nats.js +34 -0
  47. package/build/services/connector/providers/postgres.d.ts +20 -0
  48. package/build/services/connector/providers/postgres.js +102 -0
  49. package/build/services/connector/providers/redis.d.ts +9 -0
  50. package/build/services/connector/providers/redis.js +38 -0
  51. package/build/services/engine/index.d.ts +264 -0
  52. package/build/services/engine/index.js +761 -0
  53. package/build/services/exporter/index.d.ts +44 -0
  54. package/build/services/exporter/index.js +126 -0
  55. package/build/services/hotmesh/index.d.ts +483 -0
  56. package/build/services/hotmesh/index.js +622 -0
  57. package/build/services/logger/index.d.ts +16 -0
  58. package/build/services/logger/index.js +54 -0
  59. package/build/services/mapper/index.d.ts +28 -0
  60. package/build/services/mapper/index.js +81 -0
  61. package/build/services/memflow/client.d.ts +108 -0
  62. package/build/services/memflow/client.js +372 -0
  63. package/build/services/memflow/connection.d.ts +23 -0
  64. package/build/services/memflow/connection.js +33 -0
  65. package/build/services/memflow/context.d.ts +143 -0
  66. package/build/services/memflow/context.js +299 -0
  67. package/build/services/memflow/exporter.d.ts +51 -0
  68. package/build/services/memflow/exporter.js +215 -0
  69. package/build/services/memflow/handle.d.ts +90 -0
  70. package/build/services/memflow/handle.js +176 -0
  71. package/build/services/memflow/index.d.ts +116 -0
  72. package/build/services/memflow/index.js +122 -0
  73. package/build/services/memflow/schemas/factory.d.ts +29 -0
  74. package/build/services/memflow/schemas/factory.js +2492 -0
  75. package/build/services/memflow/search.d.ts +142 -0
  76. package/build/services/memflow/search.js +320 -0
  77. package/build/services/memflow/worker.d.ts +124 -0
  78. package/build/services/memflow/worker.js +514 -0
  79. package/build/services/memflow/workflow/all.d.ts +7 -0
  80. package/build/services/memflow/workflow/all.js +15 -0
  81. package/build/services/memflow/workflow/common.d.ts +20 -0
  82. package/build/services/memflow/workflow/common.js +47 -0
  83. package/build/services/memflow/workflow/context.d.ts +6 -0
  84. package/build/services/memflow/workflow/context.js +45 -0
  85. package/build/services/memflow/workflow/contextMethods.d.ts +14 -0
  86. package/build/services/memflow/workflow/contextMethods.js +33 -0
  87. package/build/services/memflow/workflow/didRun.d.ts +7 -0
  88. package/build/services/memflow/workflow/didRun.js +22 -0
  89. package/build/services/memflow/workflow/emit.d.ts +11 -0
  90. package/build/services/memflow/workflow/emit.js +29 -0
  91. package/build/services/memflow/workflow/enrich.d.ts +9 -0
  92. package/build/services/memflow/workflow/enrich.js +17 -0
  93. package/build/services/memflow/workflow/execChild.d.ts +18 -0
  94. package/build/services/memflow/workflow/execChild.js +102 -0
  95. package/build/services/memflow/workflow/execHook.d.ts +65 -0
  96. package/build/services/memflow/workflow/execHook.js +73 -0
  97. package/build/services/memflow/workflow/hook.d.ts +9 -0
  98. package/build/services/memflow/workflow/hook.js +56 -0
  99. package/build/services/memflow/workflow/index.d.ts +74 -0
  100. package/build/services/memflow/workflow/index.js +87 -0
  101. package/build/services/memflow/workflow/interrupt.d.ts +9 -0
  102. package/build/services/memflow/workflow/interrupt.js +24 -0
  103. package/build/services/memflow/workflow/isSideEffectAllowed.d.ts +10 -0
  104. package/build/services/memflow/workflow/isSideEffectAllowed.js +33 -0
  105. package/build/services/memflow/workflow/proxyActivities.d.ts +20 -0
  106. package/build/services/memflow/workflow/proxyActivities.js +97 -0
  107. package/build/services/memflow/workflow/random.d.ts +6 -0
  108. package/build/services/memflow/workflow/random.js +16 -0
  109. package/build/services/memflow/workflow/searchMethods.d.ts +6 -0
  110. package/build/services/memflow/workflow/searchMethods.js +25 -0
  111. package/build/services/memflow/workflow/signal.d.ts +29 -0
  112. package/build/services/memflow/workflow/signal.js +50 -0
  113. package/build/services/memflow/workflow/sleepFor.d.ts +24 -0
  114. package/build/services/memflow/workflow/sleepFor.js +51 -0
  115. package/build/services/memflow/workflow/trace.d.ts +14 -0
  116. package/build/services/memflow/workflow/trace.js +33 -0
  117. package/build/services/memflow/workflow/waitFor.d.ts +29 -0
  118. package/build/services/memflow/workflow/waitFor.js +56 -0
  119. package/build/services/meshcall/index.d.ts +194 -0
  120. package/build/services/meshcall/index.js +452 -0
  121. package/build/services/meshcall/schemas/factory.d.ts +9 -0
  122. package/build/services/meshcall/schemas/factory.js +189 -0
  123. package/build/services/meshdata/index.d.ts +795 -0
  124. package/build/services/meshdata/index.js +1235 -0
  125. package/build/services/meshos/index.d.ts +293 -0
  126. package/build/services/meshos/index.js +547 -0
  127. package/build/services/pipe/functions/array.d.ts +17 -0
  128. package/build/services/pipe/functions/array.js +74 -0
  129. package/build/services/pipe/functions/bitwise.d.ts +9 -0
  130. package/build/services/pipe/functions/bitwise.js +24 -0
  131. package/build/services/pipe/functions/conditional.d.ts +13 -0
  132. package/build/services/pipe/functions/conditional.js +36 -0
  133. package/build/services/pipe/functions/cron.d.ts +12 -0
  134. package/build/services/pipe/functions/cron.js +40 -0
  135. package/build/services/pipe/functions/date.d.ts +58 -0
  136. package/build/services/pipe/functions/date.js +171 -0
  137. package/build/services/pipe/functions/index.d.ts +29 -0
  138. package/build/services/pipe/functions/index.js +30 -0
  139. package/build/services/pipe/functions/json.d.ts +5 -0
  140. package/build/services/pipe/functions/json.js +12 -0
  141. package/build/services/pipe/functions/logical.d.ts +5 -0
  142. package/build/services/pipe/functions/logical.js +12 -0
  143. package/build/services/pipe/functions/math.d.ts +42 -0
  144. package/build/services/pipe/functions/math.js +184 -0
  145. package/build/services/pipe/functions/number.d.ts +21 -0
  146. package/build/services/pipe/functions/number.js +60 -0
  147. package/build/services/pipe/functions/object.d.ts +25 -0
  148. package/build/services/pipe/functions/object.js +81 -0
  149. package/build/services/pipe/functions/string.d.ts +23 -0
  150. package/build/services/pipe/functions/string.js +69 -0
  151. package/build/services/pipe/functions/symbol.d.ts +12 -0
  152. package/build/services/pipe/functions/symbol.js +33 -0
  153. package/build/services/pipe/functions/unary.d.ts +7 -0
  154. package/build/services/pipe/functions/unary.js +18 -0
  155. package/build/services/pipe/index.d.ts +48 -0
  156. package/build/services/pipe/index.js +242 -0
  157. package/build/services/quorum/index.d.ts +90 -0
  158. package/build/services/quorum/index.js +263 -0
  159. package/build/services/reporter/index.d.ts +50 -0
  160. package/build/services/reporter/index.js +348 -0
  161. package/build/services/router/config/index.d.ts +11 -0
  162. package/build/services/router/config/index.js +36 -0
  163. package/build/services/router/consumption/index.d.ts +34 -0
  164. package/build/services/router/consumption/index.js +395 -0
  165. package/build/services/router/error-handling/index.d.ts +8 -0
  166. package/build/services/router/error-handling/index.js +98 -0
  167. package/build/services/router/index.d.ts +57 -0
  168. package/build/services/router/index.js +121 -0
  169. package/build/services/router/lifecycle/index.d.ts +27 -0
  170. package/build/services/router/lifecycle/index.js +80 -0
  171. package/build/services/router/telemetry/index.d.ts +11 -0
  172. package/build/services/router/telemetry/index.js +32 -0
  173. package/build/services/router/throttling/index.d.ts +23 -0
  174. package/build/services/router/throttling/index.js +76 -0
  175. package/build/services/search/factory.d.ts +7 -0
  176. package/build/services/search/factory.js +24 -0
  177. package/build/services/search/index.d.ts +23 -0
  178. package/build/services/search/index.js +10 -0
  179. package/build/services/search/providers/postgres/postgres.d.ts +25 -0
  180. package/build/services/search/providers/postgres/postgres.js +149 -0
  181. package/build/services/search/providers/redis/ioredis.d.ts +19 -0
  182. package/build/services/search/providers/redis/ioredis.js +121 -0
  183. package/build/services/search/providers/redis/redis.d.ts +19 -0
  184. package/build/services/search/providers/redis/redis.js +134 -0
  185. package/build/services/serializer/index.d.ts +42 -0
  186. package/build/services/serializer/index.js +282 -0
  187. package/build/services/store/cache.d.ts +67 -0
  188. package/build/services/store/cache.js +128 -0
  189. package/build/services/store/factory.d.ts +8 -0
  190. package/build/services/store/factory.js +24 -0
  191. package/build/services/store/index.d.ts +89 -0
  192. package/build/services/store/index.js +9 -0
  193. package/build/services/store/providers/postgres/kvsql.d.ts +168 -0
  194. package/build/services/store/providers/postgres/kvsql.js +198 -0
  195. package/build/services/store/providers/postgres/kvtables.d.ts +20 -0
  196. package/build/services/store/providers/postgres/kvtables.js +441 -0
  197. package/build/services/store/providers/postgres/kvtransaction.d.ts +36 -0
  198. package/build/services/store/providers/postgres/kvtransaction.js +248 -0
  199. package/build/services/store/providers/postgres/kvtypes/hash.d.ts +60 -0
  200. package/build/services/store/providers/postgres/kvtypes/hash.js +1287 -0
  201. package/build/services/store/providers/postgres/kvtypes/list.d.ts +33 -0
  202. package/build/services/store/providers/postgres/kvtypes/list.js +194 -0
  203. package/build/services/store/providers/postgres/kvtypes/string.d.ts +20 -0
  204. package/build/services/store/providers/postgres/kvtypes/string.js +115 -0
  205. package/build/services/store/providers/postgres/kvtypes/zset.d.ts +41 -0
  206. package/build/services/store/providers/postgres/kvtypes/zset.js +214 -0
  207. package/build/services/store/providers/postgres/postgres.d.ts +178 -0
  208. package/build/services/store/providers/postgres/postgres.js +1244 -0
  209. package/build/services/store/providers/redis/_base.d.ts +137 -0
  210. package/build/services/store/providers/redis/_base.js +980 -0
  211. package/build/services/store/providers/redis/ioredis.d.ts +20 -0
  212. package/build/services/store/providers/redis/ioredis.js +180 -0
  213. package/build/services/store/providers/redis/redis.d.ts +18 -0
  214. package/build/services/store/providers/redis/redis.js +199 -0
  215. package/build/services/store/providers/store-initializable.d.ts +5 -0
  216. package/build/services/store/providers/store-initializable.js +2 -0
  217. package/build/services/stream/factory.d.ts +8 -0
  218. package/build/services/stream/factory.js +37 -0
  219. package/build/services/stream/index.d.ts +69 -0
  220. package/build/services/stream/index.js +11 -0
  221. package/build/services/stream/providers/nats/nats.d.ts +60 -0
  222. package/build/services/stream/providers/nats/nats.js +225 -0
  223. package/build/services/stream/providers/postgres/kvtables.d.ts +3 -0
  224. package/build/services/stream/providers/postgres/kvtables.js +146 -0
  225. package/build/services/stream/providers/postgres/postgres.d.ts +107 -0
  226. package/build/services/stream/providers/postgres/postgres.js +519 -0
  227. package/build/services/stream/providers/redis/ioredis.d.ts +61 -0
  228. package/build/services/stream/providers/redis/ioredis.js +272 -0
  229. package/build/services/stream/providers/redis/redis.d.ts +61 -0
  230. package/build/services/stream/providers/redis/redis.js +305 -0
  231. package/build/services/stream/providers/stream-initializable.d.ts +4 -0
  232. package/build/services/stream/providers/stream-initializable.js +2 -0
  233. package/build/services/sub/factory.d.ts +7 -0
  234. package/build/services/sub/factory.js +29 -0
  235. package/build/services/sub/index.d.ts +22 -0
  236. package/build/services/sub/index.js +10 -0
  237. package/build/services/sub/providers/nats/nats.d.ts +19 -0
  238. package/build/services/sub/providers/nats/nats.js +105 -0
  239. package/build/services/sub/providers/postgres/postgres.d.ts +19 -0
  240. package/build/services/sub/providers/postgres/postgres.js +92 -0
  241. package/build/services/sub/providers/redis/ioredis.d.ts +17 -0
  242. package/build/services/sub/providers/redis/ioredis.js +81 -0
  243. package/build/services/sub/providers/redis/redis.d.ts +17 -0
  244. package/build/services/sub/providers/redis/redis.js +72 -0
  245. package/build/services/task/index.d.ts +48 -0
  246. package/build/services/task/index.js +253 -0
  247. package/build/services/telemetry/index.d.ts +52 -0
  248. package/build/services/telemetry/index.js +306 -0
  249. package/build/services/worker/index.d.ts +77 -0
  250. package/build/services/worker/index.js +197 -0
  251. package/package.json +1 -1
  252. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
  253. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
  254. package/typedoc.json +0 -47
  255. package/types/activity.ts +0 -268
  256. package/types/app.ts +0 -20
  257. package/types/async.ts +0 -6
  258. package/types/cache.ts +0 -1
  259. package/types/collator.ts +0 -9
  260. package/types/error.ts +0 -56
  261. package/types/exporter.ts +0 -102
  262. package/types/hook.ts +0 -44
  263. package/types/hotmesh.ts +0 -314
  264. package/types/index.ts +0 -306
  265. package/types/job.ts +0 -233
  266. package/types/logger.ts +0 -8
  267. package/types/manifest.ts +0 -70
  268. package/types/map.ts +0 -5
  269. package/types/memflow.ts +0 -645
  270. package/types/meshcall.ts +0 -235
  271. package/types/meshdata.ts +0 -278
  272. package/types/ms.d.ts +0 -7
  273. package/types/nats.ts +0 -270
  274. package/types/pipe.ts +0 -90
  275. package/types/postgres.ts +0 -114
  276. package/types/provider.ts +0 -161
  277. package/types/quorum.ts +0 -167
  278. package/types/redis.ts +0 -404
  279. package/types/serializer.ts +0 -40
  280. package/types/stats.ts +0 -117
  281. package/types/stream.ts +0 -231
  282. package/types/task.ts +0 -7
  283. package/types/telemetry.ts +0 -16
  284. package/types/transition.ts +0 -20
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Cycle = void 0;
4
+ const errors_1 = require("../../modules/errors");
5
+ const utils_1 = require("../../modules/utils");
6
+ const collator_1 = require("../collator");
7
+ const telemetry_1 = require("../telemetry");
8
+ const activity_1 = require("./activity");
9
+ class Cycle extends activity_1.Activity {
10
+ constructor(config, data, metadata, hook, engine, context) {
11
+ super(config, data, metadata, hook, engine, context);
12
+ }
13
+ //******** LEG 1 ENTRY ********//
14
+ async process() {
15
+ this.logger.debug('cycle-process', {
16
+ jid: this.context.metadata.jid,
17
+ gid: this.context.metadata.gid,
18
+ aid: this.metadata.aid,
19
+ });
20
+ let telemetry;
21
+ try {
22
+ await this.verifyEntry();
23
+ telemetry = new telemetry_1.TelemetryService(this.engine.appId, this.config, this.metadata, this.context);
24
+ telemetry.startActivitySpan(this.leg);
25
+ this.mapInputData();
26
+ //set state/status
27
+ let transaction = this.store.transact();
28
+ await this.setState(transaction);
29
+ await this.setStatus(0, transaction); //leg 1 never changes job status
30
+ const txResponse = (await transaction.exec());
31
+ telemetry.mapActivityAttributes();
32
+ const jobStatus = this.resolveStatus(txResponse);
33
+ //cycle the target ancestor
34
+ transaction = this.store.transact();
35
+ const messageId = await this.cycleAncestorActivity(transaction);
36
+ telemetry.setActivityAttributes({
37
+ 'app.activity.mid': messageId,
38
+ 'app.job.jss': jobStatus,
39
+ });
40
+ //exit early (`Cycle` activities only execute Leg 1)
41
+ await collator_1.CollatorService.notarizeEarlyExit(this, transaction);
42
+ (await transaction.exec());
43
+ return this.context.metadata.aid;
44
+ }
45
+ catch (error) {
46
+ if (error instanceof errors_1.InactiveJobError) {
47
+ this.logger.error('cycle-inactive-job-error', { error });
48
+ return;
49
+ }
50
+ else if (error instanceof errors_1.GenerationalError) {
51
+ this.logger.info('process-event-generational-job-error', { error });
52
+ return;
53
+ }
54
+ else if (error instanceof errors_1.GetStateError) {
55
+ this.logger.error('cycle-get-state-error', { error });
56
+ return;
57
+ }
58
+ else if (error instanceof errors_1.CollationError) {
59
+ if (error.fault === 'duplicate') {
60
+ this.logger.info('cycle-collation-overage', {
61
+ job_id: this.context.metadata.jid,
62
+ guid: this.context.metadata.guid,
63
+ });
64
+ return;
65
+ }
66
+ //unknown collation error
67
+ this.logger.error('cycle-collation-error', { error });
68
+ }
69
+ else {
70
+ this.logger.error('cycle-process-error', { error });
71
+ }
72
+ telemetry?.setActivityError(error.message);
73
+ throw error;
74
+ }
75
+ finally {
76
+ telemetry?.endActivitySpan();
77
+ this.logger.debug('cycle-process-end', {
78
+ jid: this.context.metadata.jid,
79
+ gid: this.context.metadata.gid,
80
+ aid: this.metadata.aid,
81
+ });
82
+ }
83
+ }
84
+ /**
85
+ * Trigger the target ancestor to execute in a cycle,
86
+ * without violating the constraints of the DAG. Immutable
87
+ * `individual activity state` will execute in a new dimensional
88
+ * thread while `shared job state` can change. This
89
+ * pattern allows for retries without violating the DAG.
90
+ */
91
+ async cycleAncestorActivity(transaction) {
92
+ //Cycle activity L1 is a standin for the target ancestor L1.
93
+ //Input data mapping (mapInputData) allows for the
94
+ //next dimensonal thread to execute with different
95
+ //input data than the current dimensional thread
96
+ this.mapInputData();
97
+ const streamData = {
98
+ metadata: {
99
+ guid: (0, utils_1.guid)(),
100
+ jid: this.context.metadata.jid,
101
+ gid: this.context.metadata.gid,
102
+ dad: collator_1.CollatorService.resolveReentryDimension(this),
103
+ aid: this.config.ancestor,
104
+ spn: this.context['$self'].output.metadata?.l1s,
105
+ trc: this.context.metadata.trc,
106
+ },
107
+ data: this.context.data,
108
+ };
109
+ return (await this.engine.router?.publishMessage(null, streamData, transaction));
110
+ }
111
+ }
112
+ exports.Cycle = Cycle;
@@ -0,0 +1,27 @@
1
+ import { EngineService } from '../engine';
2
+ import { TelemetryService } from '../telemetry';
3
+ import { ActivityData, ActivityMetadata, ActivityType, HookActivity } from '../../types/activity';
4
+ import { HookRule } from '../../types/hook';
5
+ import { JobState, JobStatus } from '../../types/job';
6
+ import { ProviderTransaction } from '../../types/provider';
7
+ import { StreamCode, StreamStatus } from '../../types/stream';
8
+ import { Activity } from './activity';
9
+ /**
10
+ * Supports `signal hook`, `time hook`, and `cycle hook` patterns
11
+ */
12
+ declare class Hook extends Activity {
13
+ config: HookActivity;
14
+ constructor(config: ActivityType, data: ActivityData, metadata: ActivityMetadata, hook: ActivityData | null, engine: EngineService, context?: JobState);
15
+ process(): Promise<string>;
16
+ /**
17
+ * does this activity use a time-hook or web-hook
18
+ */
19
+ doesHook(): boolean;
20
+ doHook(telemetry: TelemetryService): Promise<void>;
21
+ doPassThrough(telemetry: TelemetryService): Promise<void>;
22
+ getHookRule(topic: string): Promise<HookRule | undefined>;
23
+ registerHook(transaction?: ProviderTransaction): Promise<string | void>;
24
+ processWebHookEvent(status?: StreamStatus, code?: StreamCode): Promise<JobStatus | void>;
25
+ processTimeHookEvent(jobId: string): Promise<JobStatus | void>;
26
+ }
27
+ export { Hook };
@@ -0,0 +1,168 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Hook = void 0;
4
+ const enums_1 = require("../../modules/enums");
5
+ const errors_1 = require("../../modules/errors");
6
+ const collator_1 = require("../collator");
7
+ const pipe_1 = require("../pipe");
8
+ const task_1 = require("../task");
9
+ const telemetry_1 = require("../telemetry");
10
+ const stream_1 = require("../../types/stream");
11
+ const activity_1 = require("./activity");
12
+ /**
13
+ * Supports `signal hook`, `time hook`, and `cycle hook` patterns
14
+ */
15
+ class Hook extends activity_1.Activity {
16
+ constructor(config, data, metadata, hook, engine, context) {
17
+ super(config, data, metadata, hook, engine, context);
18
+ }
19
+ //******** INITIAL ENTRY POINT (A) ********//
20
+ async process() {
21
+ this.logger.debug('hook-process', {
22
+ jid: this.context.metadata.jid,
23
+ gid: this.context.metadata.gid,
24
+ aid: this.metadata.aid,
25
+ });
26
+ let telemetry;
27
+ try {
28
+ await this.verifyEntry();
29
+ telemetry = new telemetry_1.TelemetryService(this.engine.appId, this.config, this.metadata, this.context);
30
+ telemetry.startActivitySpan(this.leg);
31
+ if (this.doesHook()) {
32
+ //sleep and wait to awaken upon a signal
33
+ await this.doHook(telemetry);
34
+ }
35
+ else {
36
+ //end the activity and transition to its children
37
+ await this.doPassThrough(telemetry);
38
+ }
39
+ return this.context.metadata.aid;
40
+ }
41
+ catch (error) {
42
+ if (error instanceof errors_1.InactiveJobError) {
43
+ this.logger.error('hook-inactive-job-error', { error });
44
+ return;
45
+ }
46
+ else if (error instanceof errors_1.GenerationalError) {
47
+ this.logger.info('process-event-generational-job-error', { error });
48
+ return;
49
+ }
50
+ else if (error instanceof errors_1.GetStateError) {
51
+ this.logger.error('hook-get-state-error', { error });
52
+ return;
53
+ }
54
+ else if (error instanceof errors_1.CollationError) {
55
+ if (error.fault === 'duplicate') {
56
+ this.logger.info('hook-collation-overage', {
57
+ job_id: this.context.metadata.jid,
58
+ guid: this.context.metadata.guid,
59
+ });
60
+ return;
61
+ }
62
+ //unknown collation error
63
+ this.logger.error('hook-collation-error', { error });
64
+ }
65
+ else {
66
+ this.logger.error('hook-process-error', { error });
67
+ }
68
+ telemetry?.setActivityError(error.message);
69
+ throw error;
70
+ }
71
+ finally {
72
+ telemetry?.endActivitySpan();
73
+ this.logger.debug('hook-process-end', {
74
+ jid: this.context.metadata.jid,
75
+ gid: this.context.metadata.gid,
76
+ aid: this.metadata.aid,
77
+ });
78
+ }
79
+ }
80
+ /**
81
+ * does this activity use a time-hook or web-hook
82
+ */
83
+ doesHook() {
84
+ if (this.config.sleep) {
85
+ const duration = pipe_1.Pipe.resolve(this.config.sleep, this.context);
86
+ return !isNaN(duration) && Number(duration) > 0;
87
+ }
88
+ return !!this.config.hook?.topic;
89
+ }
90
+ async doHook(telemetry) {
91
+ const transaction = this.store.transact();
92
+ //call registerHook separately if in cluster mode
93
+ //(ok to run this command multiple times if it fails),
94
+ //but the commands that follow must exec as a transaction
95
+ await this.registerHook(enums_1.HMSH_IS_CLUSTER ? undefined : transaction);
96
+ this.mapOutputData();
97
+ this.mapJobData();
98
+ await this.setState(transaction);
99
+ await collator_1.CollatorService.authorizeReentry(this, transaction);
100
+ await this.setStatus(0, transaction);
101
+ await transaction.exec();
102
+ telemetry.mapActivityAttributes();
103
+ }
104
+ async doPassThrough(telemetry) {
105
+ const transaction = this.store.transact();
106
+ let multiResponse;
107
+ this.adjacencyList = await this.filterAdjacent();
108
+ this.mapOutputData();
109
+ this.mapJobData();
110
+ await this.setState(transaction);
111
+ await collator_1.CollatorService.notarizeEarlyCompletion(this, transaction);
112
+ await this.setStatus(this.adjacencyList.length - 1, transaction);
113
+ multiResponse = (await transaction.exec());
114
+ telemetry.mapActivityAttributes();
115
+ const jobStatus = this.resolveStatus(multiResponse);
116
+ const attrs = { 'app.job.jss': jobStatus };
117
+ const messageIds = await this.transition(this.adjacencyList, jobStatus);
118
+ if (messageIds.length) {
119
+ attrs['app.activity.mids'] = messageIds.join(',');
120
+ }
121
+ telemetry.setActivityAttributes(attrs);
122
+ }
123
+ async getHookRule(topic) {
124
+ const rules = await this.store.getHookRules();
125
+ return rules?.[topic]?.[0];
126
+ }
127
+ async registerHook(transaction) {
128
+ if (this.config.hook?.topic) {
129
+ return await this.engine.taskService.registerWebHook(this.config.hook.topic, this.context, this.resolveDad(), this.context.metadata.expire, transaction);
130
+ }
131
+ else if (this.config.sleep) {
132
+ const duration = pipe_1.Pipe.resolve(this.config.sleep, this.context);
133
+ await this.engine.taskService.registerTimeHook(this.context.metadata.jid, this.context.metadata.gid, `${this.metadata.aid}${this.metadata.dad || ''}`, 'sleep', duration, this.metadata.dad || '');
134
+ return this.context.metadata.jid;
135
+ }
136
+ }
137
+ //******** SIGNAL RE-ENTRY POINT ********//
138
+ async processWebHookEvent(status = stream_1.StreamStatus.SUCCESS, code = 200) {
139
+ this.logger.debug('hook-process-web-hook-event', {
140
+ topic: this.config.hook.topic,
141
+ aid: this.metadata.aid,
142
+ status,
143
+ code,
144
+ });
145
+ const taskService = new task_1.TaskService(this.store, this.logger);
146
+ const data = { ...this.data };
147
+ const signal = await taskService.processWebHookSignal(this.config.hook.topic, data);
148
+ if (signal) {
149
+ const [jobId, _aid, dad, gId] = signal;
150
+ this.context.metadata.jid = jobId;
151
+ this.context.metadata.gid = gId;
152
+ this.context.metadata.dad = dad;
153
+ await this.processEvent(status, code, 'hook');
154
+ if (code === 200) {
155
+ await taskService.deleteWebHookSignal(this.config.hook.topic, data);
156
+ } //else => 202/keep alive
157
+ } //else => already resolved
158
+ }
159
+ async processTimeHookEvent(jobId) {
160
+ this.logger.debug('hook-process-time-hook-event', {
161
+ jid: jobId,
162
+ gid: this.context.metadata.gid,
163
+ aid: this.metadata.aid,
164
+ });
165
+ await this.processEvent(stream_1.StreamStatus.SUCCESS, 200, 'hook');
166
+ }
167
+ }
168
+ exports.Hook = Hook;
@@ -0,0 +1,19 @@
1
+ import { Activity } from './activity';
2
+ import { Await } from './await';
3
+ import { Cycle } from './cycle';
4
+ import { Hook } from './hook';
5
+ import { Interrupt } from './interrupt';
6
+ import { Signal } from './signal';
7
+ import { Trigger } from './trigger';
8
+ import { Worker } from './worker';
9
+ declare const _default: {
10
+ activity: typeof Activity;
11
+ await: typeof Await;
12
+ cycle: typeof Cycle;
13
+ hook: typeof Hook;
14
+ interrupt: typeof Interrupt;
15
+ signal: typeof Signal;
16
+ trigger: typeof Trigger;
17
+ worker: typeof Worker;
18
+ };
19
+ export default _default;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const activity_1 = require("./activity");
4
+ const await_1 = require("./await");
5
+ const cycle_1 = require("./cycle");
6
+ const hook_1 = require("./hook");
7
+ const interrupt_1 = require("./interrupt");
8
+ const signal_1 = require("./signal");
9
+ const trigger_1 = require("./trigger");
10
+ const worker_1 = require("./worker");
11
+ exports.default = {
12
+ activity: activity_1.Activity,
13
+ await: await_1.Await,
14
+ cycle: cycle_1.Cycle,
15
+ hook: hook_1.Hook,
16
+ interrupt: interrupt_1.Interrupt,
17
+ signal: signal_1.Signal,
18
+ trigger: trigger_1.Trigger,
19
+ worker: worker_1.Worker,
20
+ };
@@ -0,0 +1,16 @@
1
+ import { EngineService } from '../engine';
2
+ import { TelemetryService } from '../telemetry';
3
+ import { ActivityData, ActivityMetadata, ActivityType, InterruptActivity } from '../../types/activity';
4
+ import { JobInterruptOptions, JobState } from '../../types/job';
5
+ import { Activity } from './activity';
6
+ declare class Interrupt extends Activity {
7
+ config: InterruptActivity;
8
+ constructor(config: ActivityType, data: ActivityData, metadata: ActivityMetadata, hook: ActivityData | null, engine: EngineService, context?: JobState);
9
+ process(): Promise<string>;
10
+ interruptSelf(telemetry: TelemetryService): Promise<string>;
11
+ interruptAnother(telemetry: TelemetryService): Promise<string>;
12
+ isInterruptingSelf(): boolean;
13
+ resolveInterruptOptions(): JobInterruptOptions;
14
+ interrupt(): Promise<string>;
15
+ }
16
+ export { Interrupt };
@@ -0,0 +1,158 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Interrupt = void 0;
4
+ const errors_1 = require("../../modules/errors");
5
+ const collator_1 = require("../collator");
6
+ const pipe_1 = require("../pipe");
7
+ const telemetry_1 = require("../telemetry");
8
+ const activity_1 = require("./activity");
9
+ class Interrupt extends activity_1.Activity {
10
+ constructor(config, data, metadata, hook, engine, context) {
11
+ super(config, data, metadata, hook, engine, context);
12
+ }
13
+ //******** LEG 1 ENTRY ********//
14
+ async process() {
15
+ this.logger.debug('interrupt-process', {
16
+ jid: this.context.metadata.jid,
17
+ gid: this.context.metadata.gid,
18
+ aid: this.metadata.aid,
19
+ });
20
+ let telemetry;
21
+ try {
22
+ await this.verifyEntry();
23
+ telemetry = new telemetry_1.TelemetryService(this.engine.appId, this.config, this.metadata, this.context);
24
+ telemetry.startActivitySpan(this.leg);
25
+ if (this.isInterruptingSelf()) {
26
+ await this.interruptSelf(telemetry);
27
+ }
28
+ else {
29
+ await this.interruptAnother(telemetry);
30
+ }
31
+ }
32
+ catch (error) {
33
+ if (error instanceof errors_1.InactiveJobError) {
34
+ this.logger.error('interrupt-inactive-job-error', { error });
35
+ return;
36
+ }
37
+ else if (error instanceof errors_1.GenerationalError) {
38
+ this.logger.info('process-event-generational-job-error', { error });
39
+ return;
40
+ }
41
+ else if (error instanceof errors_1.GetStateError) {
42
+ this.logger.error('interrupt-get-state-error', { error });
43
+ return;
44
+ }
45
+ else if (error instanceof errors_1.CollationError) {
46
+ if (error.fault === 'duplicate') {
47
+ this.logger.info('interrupt-collation-overage', {
48
+ job_id: this.context.metadata.jid,
49
+ guid: this.context.metadata.guid,
50
+ });
51
+ return;
52
+ }
53
+ //unknown collation error
54
+ this.logger.error('interrupt-collation-error', { error });
55
+ }
56
+ else {
57
+ this.logger.error('interrupt-process-error', { error });
58
+ }
59
+ telemetry?.setActivityError(error.message);
60
+ throw error;
61
+ }
62
+ finally {
63
+ telemetry?.endActivitySpan();
64
+ this.logger.debug('interrupt-process-end', {
65
+ jid: this.context.metadata.jid,
66
+ gid: this.context.metadata.gid,
67
+ aid: this.metadata.aid,
68
+ });
69
+ }
70
+ }
71
+ async interruptSelf(telemetry) {
72
+ // Apply final updates to THIS job's state
73
+ if (this.config.job?.maps) {
74
+ this.mapJobData();
75
+ await this.setState();
76
+ }
77
+ // Interrupt THIS job
78
+ const messageId = await this.interrupt();
79
+ // Notarize completion and log
80
+ telemetry.mapActivityAttributes();
81
+ const transaction = this.store.transact();
82
+ await collator_1.CollatorService.notarizeEarlyCompletion(this, transaction);
83
+ await this.setStatus(-1, transaction);
84
+ const txResponse = (await transaction.exec());
85
+ const jobStatus = this.resolveStatus(txResponse);
86
+ telemetry.setActivityAttributes({
87
+ 'app.activity.mid': messageId,
88
+ 'app.job.jss': jobStatus,
89
+ });
90
+ return this.context.metadata.aid;
91
+ }
92
+ async interruptAnother(telemetry) {
93
+ // Interrupt ANOTHER job
94
+ const messageId = await this.interrupt();
95
+ const attrs = { 'app.activity.mid': messageId };
96
+ // Apply updates to THIS job's state
97
+ telemetry.mapActivityAttributes();
98
+ this.adjacencyList = await this.filterAdjacent();
99
+ if (this.config.job?.maps || this.config.output?.maps) {
100
+ this.mapOutputData();
101
+ this.mapJobData();
102
+ const transaction = this.store.transact();
103
+ await this.setState(transaction);
104
+ }
105
+ // Notarize completion
106
+ const transaction = this.store.transact();
107
+ await collator_1.CollatorService.notarizeEarlyCompletion(this, transaction);
108
+ await this.setStatus(this.adjacencyList.length - 1, transaction);
109
+ const txResponse = (await transaction.exec());
110
+ const jobStatus = this.resolveStatus(txResponse);
111
+ attrs['app.job.jss'] = jobStatus;
112
+ // Transition next generation and log
113
+ const messageIds = await this.transition(this.adjacencyList, jobStatus);
114
+ if (messageIds.length) {
115
+ attrs['app.activity.mids'] = messageIds.join(',');
116
+ }
117
+ telemetry.setActivityAttributes(attrs);
118
+ return this.context.metadata.aid;
119
+ }
120
+ isInterruptingSelf() {
121
+ if (!this.config.target) {
122
+ return true;
123
+ }
124
+ const resolvedJob = pipe_1.Pipe.resolve(this.config.target, this.context);
125
+ return resolvedJob == this.context.metadata.jid;
126
+ }
127
+ resolveInterruptOptions() {
128
+ return {
129
+ reason: this.config.reason !== undefined
130
+ ? pipe_1.Pipe.resolve(this.config.reason, this.context)
131
+ : undefined,
132
+ throw: this.config.throw !== undefined
133
+ ? pipe_1.Pipe.resolve(this.config.throw, this.context)
134
+ : undefined,
135
+ descend: this.config.descend !== undefined
136
+ ? pipe_1.Pipe.resolve(this.config.descend, this.context)
137
+ : undefined,
138
+ code: this.config.code !== undefined
139
+ ? pipe_1.Pipe.resolve(this.config.code, this.context)
140
+ : undefined,
141
+ expire: this.config.expire !== undefined
142
+ ? pipe_1.Pipe.resolve(this.config.expire, this.context)
143
+ : undefined,
144
+ stack: this.config.stack !== undefined
145
+ ? pipe_1.Pipe.resolve(this.config.stack, this.context)
146
+ : undefined,
147
+ };
148
+ }
149
+ async interrupt() {
150
+ const options = this.resolveInterruptOptions();
151
+ return await this.engine.interrupt(this.config.topic !== undefined
152
+ ? pipe_1.Pipe.resolve(this.config.topic, this.context)
153
+ : this.context.metadata.tpc, this.config.target !== undefined
154
+ ? pipe_1.Pipe.resolve(this.config.target, this.context)
155
+ : this.context.metadata.jid, options);
156
+ }
157
+ }
158
+ exports.Interrupt = Interrupt;
@@ -0,0 +1,20 @@
1
+ import { EngineService } from '../engine';
2
+ import { ActivityData, ActivityMetadata, ActivityType, SignalActivity } from '../../types/activity';
3
+ import { JobState } from '../../types/job';
4
+ import { Activity } from './activity';
5
+ declare class Signal extends Activity {
6
+ config: SignalActivity;
7
+ constructor(config: ActivityType, data: ActivityData, metadata: ActivityMetadata, hook: ActivityData | null, engine: EngineService, context?: JobState);
8
+ process(): Promise<string>;
9
+ mapSignalData(): Record<string, any>;
10
+ mapResolverData(): Record<string, any>;
11
+ /**
12
+ * The signal activity will hook one
13
+ */
14
+ hookOne(): Promise<string>;
15
+ /**
16
+ * The signal activity will hook all paused jobs that share the same job key.
17
+ */
18
+ hookAll(): Promise<string[]>;
19
+ }
20
+ export { Signal };
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Signal = void 0;
4
+ const errors_1 = require("../../modules/errors");
5
+ const collator_1 = require("../collator");
6
+ const mapper_1 = require("../mapper");
7
+ const pipe_1 = require("../pipe");
8
+ const telemetry_1 = require("../telemetry");
9
+ const activity_1 = require("./activity");
10
+ class Signal extends activity_1.Activity {
11
+ constructor(config, data, metadata, hook, engine, context) {
12
+ super(config, data, metadata, hook, engine, context);
13
+ }
14
+ //******** LEG 1 ENTRY ********//
15
+ async process() {
16
+ this.logger.debug('signal-process', {
17
+ jid: this.context.metadata.jid,
18
+ gid: this.context.metadata.gid,
19
+ aid: this.metadata.aid,
20
+ });
21
+ let telemetry;
22
+ try {
23
+ await this.verifyEntry();
24
+ telemetry = new telemetry_1.TelemetryService(this.engine.appId, this.config, this.metadata, this.context);
25
+ telemetry.startActivitySpan(this.leg);
26
+ //save state and notarize early completion (signals only run leg1)
27
+ const transaction = this.store.transact();
28
+ this.adjacencyList = await this.filterAdjacent();
29
+ this.mapOutputData();
30
+ this.mapJobData();
31
+ await this.setState(transaction);
32
+ await collator_1.CollatorService.notarizeEarlyCompletion(this, transaction);
33
+ await this.setStatus(this.adjacencyList.length - 1, transaction);
34
+ const multiResponse = (await transaction.exec());
35
+ //todo: this should execute BEFORE the status is decremented
36
+ if (this.config.subtype === 'all') {
37
+ await this.hookAll();
38
+ }
39
+ else {
40
+ await this.hookOne();
41
+ }
42
+ //transition to adjacent activities
43
+ const jobStatus = this.resolveStatus(multiResponse);
44
+ const attrs = { 'app.job.jss': jobStatus };
45
+ const messageIds = await this.transition(this.adjacencyList, jobStatus);
46
+ if (messageIds.length) {
47
+ attrs['app.activity.mids'] = messageIds.join(',');
48
+ }
49
+ telemetry.mapActivityAttributes();
50
+ telemetry.setActivityAttributes(attrs);
51
+ return this.context.metadata.aid;
52
+ }
53
+ catch (error) {
54
+ if (error instanceof errors_1.InactiveJobError) {
55
+ this.logger.error('signal-inactive-job-error', { error });
56
+ return;
57
+ }
58
+ else if (error instanceof errors_1.GenerationalError) {
59
+ this.logger.info('process-event-generational-job-error', { error });
60
+ return;
61
+ }
62
+ else if (error instanceof errors_1.GetStateError) {
63
+ this.logger.error('signal-get-state-error', { error });
64
+ return;
65
+ }
66
+ else if (error instanceof errors_1.CollationError) {
67
+ if (error.fault === 'duplicate') {
68
+ this.logger.info('signal-collation-overage', {
69
+ job_id: this.context.metadata.jid,
70
+ guid: this.context.metadata.guid,
71
+ });
72
+ return;
73
+ }
74
+ //unknown collation error
75
+ this.logger.error('signal-collation-error', { error });
76
+ }
77
+ else {
78
+ this.logger.error('signal-process-error', { error });
79
+ }
80
+ telemetry?.setActivityError(error.message);
81
+ throw error;
82
+ }
83
+ finally {
84
+ telemetry?.endActivitySpan();
85
+ this.logger.debug('signal-process-end', {
86
+ jid: this.context.metadata.jid,
87
+ gid: this.context.metadata.gid,
88
+ aid: this.metadata.aid,
89
+ });
90
+ }
91
+ }
92
+ mapSignalData() {
93
+ if (this.config.signal?.maps) {
94
+ const mapper = new mapper_1.MapperService(this.config.signal.maps, this.context);
95
+ return mapper.mapRules();
96
+ }
97
+ }
98
+ mapResolverData() {
99
+ if (this.config.resolver?.maps) {
100
+ const mapper = new mapper_1.MapperService(this.config.resolver.maps, this.context);
101
+ return mapper.mapRules();
102
+ }
103
+ }
104
+ /**
105
+ * The signal activity will hook one
106
+ */
107
+ async hookOne() {
108
+ const topic = pipe_1.Pipe.resolve(this.config.topic, this.context);
109
+ const signalInputData = this.mapSignalData();
110
+ const status = pipe_1.Pipe.resolve(this.config.status, this.context);
111
+ const code = pipe_1.Pipe.resolve(this.config.code, this.context);
112
+ return await this.engine.hook(topic, signalInputData, status, code);
113
+ }
114
+ /**
115
+ * The signal activity will hook all paused jobs that share the same job key.
116
+ */
117
+ async hookAll() {
118
+ //prep 1) generate `input signal data` (essentially the webhook payload)
119
+ const signalInputData = this.mapSignalData();
120
+ //prep 2) generate data that resolves the job key (per the YAML config)
121
+ const keyResolverData = this.mapResolverData();
122
+ if (this.config.scrub) {
123
+ //self-clean the indexes upon use if configured
124
+ keyResolverData.scrub = true;
125
+ }
126
+ //prep 3) jobKeys can contain multiple indexes (per the YAML config)
127
+ const key_name = pipe_1.Pipe.resolve(this.config.key_name, this.context);
128
+ const key_value = pipe_1.Pipe.resolve(this.config.key_value, this.context);
129
+ const indexQueryFacets = [`${key_name}:${key_value}`];
130
+ //execute: `hookAll` will now resume all paused jobs that share the same job key
131
+ return await this.engine.hookAll(this.config.topic, signalInputData, keyResolverData, indexQueryFacets);
132
+ }
133
+ }
134
+ exports.Signal = Signal;