@hotmeshio/hotmesh 0.13.0 → 0.14.0

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 (194) hide show
  1. package/README.md +18 -22
  2. package/build/modules/enums.d.ts +60 -5
  3. package/build/modules/enums.js +62 -7
  4. package/build/modules/errors.d.ts +15 -3
  5. package/build/modules/errors.js +17 -2
  6. package/build/package.json +6 -1
  7. package/build/services/activities/activity/context.d.ts +22 -0
  8. package/build/services/activities/activity/context.js +76 -0
  9. package/build/services/activities/activity/index.d.ts +116 -0
  10. package/build/services/activities/activity/index.js +299 -0
  11. package/build/services/activities/activity/mapping.d.ts +12 -0
  12. package/build/services/activities/activity/mapping.js +63 -0
  13. package/build/services/activities/activity/process.d.ts +28 -0
  14. package/build/services/activities/activity/process.js +100 -0
  15. package/build/services/activities/activity/protocol.d.ts +39 -0
  16. package/build/services/activities/activity/protocol.js +151 -0
  17. package/build/services/activities/activity/state.d.ts +40 -0
  18. package/build/services/activities/activity/state.js +143 -0
  19. package/build/services/activities/activity/transition.d.ts +23 -0
  20. package/build/services/activities/activity/transition.js +71 -0
  21. package/build/services/activities/activity/verify.d.ts +22 -0
  22. package/build/services/activities/activity/verify.js +85 -0
  23. package/build/services/activities/await.d.ts +1 -4
  24. package/build/services/activities/await.js +2 -36
  25. package/build/services/activities/cycle.d.ts +1 -11
  26. package/build/services/activities/cycle.js +3 -46
  27. package/build/services/activities/hook.d.ts +2 -11
  28. package/build/services/activities/hook.js +30 -50
  29. package/build/services/activities/interrupt.d.ts +2 -4
  30. package/build/services/activities/interrupt.js +4 -38
  31. package/build/services/activities/signal.d.ts +1 -11
  32. package/build/services/activities/signal.js +3 -48
  33. package/build/services/activities/trigger.d.ts +1 -3
  34. package/build/services/activities/trigger.js +0 -3
  35. package/build/services/activities/worker.d.ts +3 -6
  36. package/build/services/activities/worker.js +4 -40
  37. package/build/services/connector/factory.d.ts +6 -0
  38. package/build/services/connector/factory.js +24 -0
  39. package/build/services/durable/activity.d.ts +1 -1
  40. package/build/services/durable/activity.js +2 -2
  41. package/build/services/durable/client.d.ts +24 -29
  42. package/build/services/durable/client.js +24 -29
  43. package/build/services/durable/connection.d.ts +13 -7
  44. package/build/services/durable/connection.js +13 -7
  45. package/build/services/durable/handle.d.ts +58 -40
  46. package/build/services/durable/handle.js +60 -40
  47. package/build/services/durable/index.d.ts +148 -286
  48. package/build/services/durable/index.js +157 -292
  49. package/build/services/durable/interceptor.d.ts +43 -33
  50. package/build/services/durable/interceptor.js +59 -39
  51. package/build/services/durable/schemas/factory.d.ts +1 -1
  52. package/build/services/durable/schemas/factory.js +168 -38
  53. package/build/services/durable/telemetry.d.ts +80 -0
  54. package/build/services/durable/telemetry.js +137 -0
  55. package/build/services/durable/worker.d.ts +100 -21
  56. package/build/services/durable/worker.js +304 -63
  57. package/build/services/durable/workflow/all.d.ts +1 -1
  58. package/build/services/durable/workflow/all.js +1 -1
  59. package/build/services/durable/workflow/cancellationScope.d.ts +104 -0
  60. package/build/services/durable/workflow/cancellationScope.js +139 -0
  61. package/build/services/durable/workflow/common.d.ts +5 -4
  62. package/build/services/durable/workflow/common.js +6 -1
  63. package/build/services/durable/workflow/{waitFor.d.ts → condition.d.ts} +9 -8
  64. package/build/services/durable/workflow/{waitFor.js → condition.js} +44 -11
  65. package/build/services/durable/workflow/continueAsNew.d.ts +65 -0
  66. package/build/services/durable/workflow/continueAsNew.js +92 -0
  67. package/build/services/durable/workflow/didRun.d.ts +1 -1
  68. package/build/services/durable/workflow/didRun.js +3 -3
  69. package/build/services/durable/workflow/enrich.d.ts +5 -0
  70. package/build/services/durable/workflow/enrich.js +5 -0
  71. package/build/services/durable/workflow/entityMethods.d.ts +7 -0
  72. package/build/services/durable/workflow/entityMethods.js +7 -0
  73. package/build/services/durable/workflow/execHook.js +3 -3
  74. package/build/services/durable/workflow/execHookBatch.js +2 -2
  75. package/build/services/durable/workflow/{execChild.d.ts → executeChild.d.ts} +4 -40
  76. package/build/services/durable/workflow/{execChild.js → executeChild.js} +36 -45
  77. package/build/services/durable/workflow/hook.d.ts +1 -1
  78. package/build/services/durable/workflow/hook.js +4 -3
  79. package/build/services/durable/workflow/index.d.ts +45 -50
  80. package/build/services/durable/workflow/index.js +46 -51
  81. package/build/services/durable/workflow/interruption.d.ts +7 -6
  82. package/build/services/durable/workflow/interruption.js +11 -7
  83. package/build/services/durable/workflow/patched.d.ts +72 -0
  84. package/build/services/durable/workflow/patched.js +110 -0
  85. package/build/services/durable/workflow/proxyActivities.d.ts +7 -7
  86. package/build/services/durable/workflow/proxyActivities.js +50 -15
  87. package/build/services/durable/workflow/searchMethods.d.ts +7 -0
  88. package/build/services/durable/workflow/searchMethods.js +7 -0
  89. package/build/services/durable/workflow/signal.d.ts +4 -4
  90. package/build/services/durable/workflow/signal.js +4 -4
  91. package/build/services/durable/workflow/{sleepFor.d.ts → sleep.d.ts} +7 -7
  92. package/build/services/durable/workflow/{sleepFor.js → sleep.js} +39 -10
  93. package/build/services/durable/workflow/terminate.d.ts +55 -0
  94. package/build/services/durable/workflow/{interrupt.js → terminate.js} +21 -21
  95. package/build/services/durable/workflow/trace.js +2 -2
  96. package/build/services/durable/workflow/uuid4.d.ts +14 -0
  97. package/build/services/durable/workflow/uuid4.js +39 -0
  98. package/build/services/durable/workflow/{context.d.ts → workflowInfo.d.ts} +5 -5
  99. package/build/services/durable/workflow/{context.js → workflowInfo.js} +7 -7
  100. package/build/services/engine/compiler.d.ts +19 -0
  101. package/build/services/engine/compiler.js +20 -0
  102. package/build/services/engine/completion.d.ts +46 -0
  103. package/build/services/engine/completion.js +145 -0
  104. package/build/services/engine/dispatch.d.ts +24 -0
  105. package/build/services/engine/dispatch.js +98 -0
  106. package/build/services/engine/index.d.ts +49 -81
  107. package/build/services/engine/index.js +175 -573
  108. package/build/services/engine/init.d.ts +42 -0
  109. package/build/services/engine/init.js +74 -0
  110. package/build/services/engine/pubsub.d.ts +50 -0
  111. package/build/services/engine/pubsub.js +118 -0
  112. package/build/services/engine/reporting.d.ts +20 -0
  113. package/build/services/engine/reporting.js +38 -0
  114. package/build/services/engine/schema.d.ts +23 -0
  115. package/build/services/engine/schema.js +62 -0
  116. package/build/services/engine/signal.d.ts +57 -0
  117. package/build/services/engine/signal.js +117 -0
  118. package/build/services/engine/state.d.ts +35 -0
  119. package/build/services/engine/state.js +61 -0
  120. package/build/services/engine/version.d.ts +31 -0
  121. package/build/services/engine/version.js +73 -0
  122. package/build/services/hotmesh/deployment.d.ts +21 -0
  123. package/build/services/hotmesh/deployment.js +25 -0
  124. package/build/services/hotmesh/index.d.ts +141 -532
  125. package/build/services/hotmesh/index.js +222 -673
  126. package/build/services/hotmesh/init.d.ts +42 -0
  127. package/build/services/hotmesh/init.js +93 -0
  128. package/build/services/hotmesh/jobs.d.ts +67 -0
  129. package/build/services/hotmesh/jobs.js +99 -0
  130. package/build/services/hotmesh/pubsub.d.ts +38 -0
  131. package/build/services/hotmesh/pubsub.js +54 -0
  132. package/build/services/hotmesh/quorum.d.ts +30 -0
  133. package/build/services/hotmesh/quorum.js +62 -0
  134. package/build/services/hotmesh/validation.d.ts +6 -0
  135. package/build/services/hotmesh/validation.js +28 -0
  136. package/build/services/quorum/index.js +1 -0
  137. package/build/services/router/consumption/index.d.ts +11 -5
  138. package/build/services/router/consumption/index.js +24 -17
  139. package/build/services/router/error-handling/index.d.ts +2 -2
  140. package/build/services/router/error-handling/index.js +14 -14
  141. package/build/services/router/index.d.ts +1 -1
  142. package/build/services/router/index.js +2 -2
  143. package/build/services/serializer/index.d.ts +22 -0
  144. package/build/services/serializer/index.js +39 -1
  145. package/build/services/store/index.d.ts +1 -0
  146. package/build/services/store/providers/postgres/exporter-sql.d.ts +2 -2
  147. package/build/services/store/providers/postgres/exporter-sql.js +4 -4
  148. package/build/services/store/providers/postgres/kvtables.js +7 -6
  149. package/build/services/store/providers/postgres/kvtypes/hash/basic.js +67 -52
  150. package/build/services/store/providers/postgres/kvtypes/hash/jsonb.js +87 -72
  151. package/build/services/store/providers/postgres/kvtypes/hash/udata.js +106 -79
  152. package/build/services/store/providers/postgres/kvtypes/hash/utils.d.ts +16 -0
  153. package/build/services/store/providers/postgres/kvtypes/hash/utils.js +29 -16
  154. package/build/services/store/providers/postgres/postgres.d.ts +1 -0
  155. package/build/services/store/providers/postgres/postgres.js +14 -4
  156. package/build/services/stream/factory.d.ts +3 -1
  157. package/build/services/stream/factory.js +2 -2
  158. package/build/services/stream/index.d.ts +1 -0
  159. package/build/services/stream/providers/nats/nats.d.ts +1 -0
  160. package/build/services/stream/providers/nats/nats.js +1 -0
  161. package/build/services/stream/providers/postgres/credentials.d.ts +56 -0
  162. package/build/services/stream/providers/postgres/credentials.js +129 -0
  163. package/build/services/stream/providers/postgres/kvtables.js +18 -0
  164. package/build/services/stream/providers/postgres/messages.js +7 -7
  165. package/build/services/stream/providers/postgres/notifications.js +16 -2
  166. package/build/services/stream/providers/postgres/postgres.d.ts +7 -0
  167. package/build/services/stream/providers/postgres/postgres.js +35 -4
  168. package/build/services/stream/providers/postgres/procedures.d.ts +21 -0
  169. package/build/services/stream/providers/postgres/procedures.js +213 -0
  170. package/build/services/stream/providers/postgres/secured.d.ts +34 -0
  171. package/build/services/stream/providers/postgres/secured.js +146 -0
  172. package/build/services/stream/providers/postgres/stats.d.ts +1 -0
  173. package/build/services/stream/providers/postgres/stats.js +1 -0
  174. package/build/services/stream/registry.d.ts +1 -1
  175. package/build/services/stream/registry.js +5 -2
  176. package/build/services/telemetry/index.d.ts +10 -1
  177. package/build/services/telemetry/index.js +40 -7
  178. package/build/services/worker/credentials.d.ts +51 -0
  179. package/build/services/worker/credentials.js +87 -0
  180. package/build/services/worker/index.d.ts +2 -2
  181. package/build/services/worker/index.js +7 -6
  182. package/build/types/codec.d.ts +84 -0
  183. package/build/types/codec.js +2 -0
  184. package/build/types/durable.d.ts +104 -28
  185. package/build/types/error.d.ts +10 -1
  186. package/build/types/hotmesh.d.ts +67 -4
  187. package/build/types/index.d.ts +2 -1
  188. package/build/types/provider.d.ts +2 -2
  189. package/build/types/quorum.d.ts +35 -1
  190. package/build/types/stream.d.ts +12 -6
  191. package/package.json +6 -1
  192. package/build/services/activities/activity.d.ts +0 -192
  193. package/build/services/activities/activity.js +0 -786
  194. package/build/services/durable/workflow/interrupt.d.ts +0 -55
@@ -0,0 +1,145 @@
1
+ "use strict";
2
+ /**
3
+ * Job lifecycle completion — parent notification, cleanup, and expiry.
4
+ *
5
+ * When a job finishes (or is interrupted), this module:
6
+ * 1. Notifies the parent job (if this is a child via execChild)
7
+ * 2. Publishes to one-time and permanent subscribers
8
+ * 3. Registers the job for TTL-based cleanup
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.resolveExpires = exports.runJobCompletionTasks = exports.scrub = exports.interrupt = exports.resolveError = exports.hasParentJob = exports.execAdjacentParent = void 0;
12
+ const enums_1 = require("../../modules/enums");
13
+ const utils_1 = require("../../modules/utils");
14
+ const key_1 = require("../../modules/key");
15
+ const stream_1 = require("../../types/stream");
16
+ /**
17
+ * Sends the child job result back to the waiting parent activity.
18
+ * Only applies to non-severed children (execChild, not startChild).
19
+ */
20
+ async function execAdjacentParent(instance, context, jobOutput, emit = false, transaction) {
21
+ if (hasParentJob(context)) {
22
+ const error = resolveError(jobOutput.metadata);
23
+ const spn = context['$self']?.output?.metadata?.l2s ||
24
+ context['$self']?.output?.metadata?.l1s;
25
+ const streamData = {
26
+ metadata: {
27
+ guid: (0, utils_1.guid)(),
28
+ jid: context.metadata.pj,
29
+ gid: context.metadata.pg,
30
+ dad: context.metadata.pd,
31
+ aid: context.metadata.pa,
32
+ trc: context.metadata.trc,
33
+ spn,
34
+ },
35
+ type: stream_1.StreamDataType.RESULT,
36
+ data: jobOutput.data,
37
+ };
38
+ if (error && error.code) {
39
+ streamData.status = stream_1.StreamStatus.ERROR;
40
+ streamData.data = error;
41
+ streamData.code = error.code;
42
+ streamData.stack = error.stack;
43
+ }
44
+ else if (emit) {
45
+ streamData.status = stream_1.StreamStatus.PENDING;
46
+ streamData.code = enums_1.HMSH_CODE_PENDING;
47
+ }
48
+ else {
49
+ streamData.status = stream_1.StreamStatus.SUCCESS;
50
+ streamData.code = enums_1.HMSH_CODE_SUCCESS;
51
+ }
52
+ return (await instance.router?.publishMessage(null, streamData, transaction));
53
+ }
54
+ }
55
+ exports.execAdjacentParent = execAdjacentParent;
56
+ function hasParentJob(context, checkSevered = false) {
57
+ if (checkSevered) {
58
+ return Boolean(context.metadata.pj && context.metadata.pa && !context.metadata.px);
59
+ }
60
+ return Boolean(context.metadata.pj && context.metadata.pa);
61
+ }
62
+ exports.hasParentJob = hasParentJob;
63
+ function resolveError(metadata) {
64
+ if (metadata && metadata.err) {
65
+ return JSON.parse(metadata.err);
66
+ }
67
+ }
68
+ exports.resolveError = resolveError;
69
+ async function interrupt(instance, topic, jobId, options = {}) {
70
+ await instance.store.interrupt(topic, jobId, options);
71
+ const context = (await instance.getState(topic, jobId));
72
+ const completionOpts = {
73
+ interrupt: options.descend,
74
+ expire: options.expire,
75
+ };
76
+ return (await runJobCompletionTasks(instance, context, completionOpts));
77
+ }
78
+ exports.interrupt = interrupt;
79
+ async function scrub(instance, jobId) {
80
+ await instance.store.scrub(jobId);
81
+ }
82
+ exports.scrub = scrub;
83
+ /**
84
+ * Orchestrates all post-completion work for a finished job:
85
+ * notify parent, publish to subscribers, schedule cleanup.
86
+ */
87
+ async function runJobCompletionTasks(instance, context, options = {}, transaction) {
88
+ const isAwait = hasParentJob(context, true);
89
+ const isOneTimeSub = hasOneTimeSubscription(context);
90
+ const topic = await instance.getPublishesTopic(context);
91
+ let msgId;
92
+ let jobOutput;
93
+ if (isAwait || isOneTimeSub || topic) {
94
+ jobOutput = await instance.getState(context.metadata.tpc, context.metadata.jid);
95
+ if (isAwait) {
96
+ msgId = await execAdjacentParent(instance, context, jobOutput, options.emit, transaction);
97
+ }
98
+ if (transaction) {
99
+ await publishOneTimeSubscribers(instance, context, jobOutput, options.emit, transaction);
100
+ await publishPermanentSubscribers(instance, context, jobOutput, options.emit, transaction);
101
+ }
102
+ else {
103
+ publishOneTimeSubscribers(instance, context, jobOutput, options.emit);
104
+ publishPermanentSubscribers(instance, context, jobOutput, options.emit);
105
+ }
106
+ }
107
+ if (!options.emit) {
108
+ if (transaction) {
109
+ await instance.taskService.registerJobForCleanup(context.metadata.jid, resolveExpires(context, options), options, transaction);
110
+ }
111
+ else {
112
+ instance.taskService.registerJobForCleanup(context.metadata.jid, resolveExpires(context, options), options);
113
+ }
114
+ }
115
+ return msgId;
116
+ }
117
+ exports.runJobCompletionTasks = runJobCompletionTasks;
118
+ function resolveExpires(context, options) {
119
+ return options.expire ?? context.metadata.expire ?? enums_1.HMSH_EXPIRE_JOB_SECONDS;
120
+ }
121
+ exports.resolveExpires = resolveExpires;
122
+ function hasOneTimeSubscription(context) {
123
+ return Boolean(context.metadata.ngn);
124
+ }
125
+ async function publishOneTimeSubscribers(instance, context, jobOutput, emit = false, transaction) {
126
+ if (hasOneTimeSubscription(context)) {
127
+ const message = {
128
+ type: 'job',
129
+ topic: context.metadata.jid,
130
+ job: (0, utils_1.restoreHierarchy)(jobOutput),
131
+ };
132
+ await instance.subscribe.publish(key_1.KeyType.QUORUM, message, instance.appId, context.metadata.ngn, transaction);
133
+ }
134
+ }
135
+ async function publishPermanentSubscribers(instance, context, jobOutput, emit = false, transaction) {
136
+ const topic = await instance.getPublishesTopic(context);
137
+ if (topic) {
138
+ const message = {
139
+ type: 'job',
140
+ topic,
141
+ job: (0, utils_1.restoreHierarchy)(jobOutput),
142
+ };
143
+ await instance.subscribe.publish(key_1.KeyType.QUORUM, message, instance.appId, `${topic}.${context.metadata.jid}`, transaction);
144
+ }
145
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Stream message routing — the engine's main re-entry point.
3
+ *
4
+ * Every message consumed from the engine stream arrives here.
5
+ * The dispatcher inspects the message type and delegates to the
6
+ * appropriate activity handler (Hook, Trigger, Await, Worker).
7
+ *
8
+ * Message types:
9
+ * TIMEHOOK → Hook.processTimeHookEvent (sleep/cron awaken)
10
+ * WEBHOOK → Hook.processWebHookEvent (signal-in awaken)
11
+ * TRANSITION → Activity.process (adjacent activity)
12
+ * AWAIT → Trigger.process (child job spawn)
13
+ * RESULT → Await.processEvent (child job result)
14
+ * (default) → Worker.processEvent (worker response)
15
+ */
16
+ import { ILogger } from '../logger';
17
+ import { JobState, JobData } from '../../types/job';
18
+ import { StreamDataResponse } from '../../types/stream';
19
+ interface DispatchContext {
20
+ logger: ILogger;
21
+ initActivity(topic: string, data?: JobData, context?: JobState): Promise<any>;
22
+ }
23
+ export declare function processStreamMessage(instance: DispatchContext, streamData: StreamDataResponse): Promise<void>;
24
+ export {};
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ /**
3
+ * Stream message routing — the engine's main re-entry point.
4
+ *
5
+ * Every message consumed from the engine stream arrives here.
6
+ * The dispatcher inspects the message type and delegates to the
7
+ * appropriate activity handler (Hook, Trigger, Await, Worker).
8
+ *
9
+ * Message types:
10
+ * TIMEHOOK → Hook.processTimeHookEvent (sleep/cron awaken)
11
+ * WEBHOOK → Hook.processWebHookEvent (signal-in awaken)
12
+ * TRANSITION → Activity.process (adjacent activity)
13
+ * AWAIT → Trigger.process (child job spawn)
14
+ * RESULT → Await.processEvent (child job result)
15
+ * (default) → Worker.processEvent (worker response)
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.processStreamMessage = void 0;
19
+ const stream_1 = require("../../types/stream");
20
+ async function processStreamMessage(instance, streamData) {
21
+ instance.logger.debug('engine-process', {
22
+ jid: streamData.metadata.jid,
23
+ gid: streamData.metadata.gid,
24
+ dad: streamData.metadata.dad,
25
+ aid: streamData.metadata.aid,
26
+ status: streamData.status || stream_1.StreamStatus.SUCCESS,
27
+ code: streamData.code || 200,
28
+ type: streamData.type,
29
+ });
30
+ const context = {
31
+ metadata: {
32
+ guid: streamData.metadata.guid,
33
+ jid: streamData.metadata.jid,
34
+ gid: streamData.metadata.gid,
35
+ dad: streamData.metadata.dad,
36
+ aid: streamData.metadata.aid,
37
+ },
38
+ data: streamData.data,
39
+ };
40
+ if (streamData.type === stream_1.StreamDataType.TIMEHOOK) {
41
+ await dispatchTimeHook(instance, streamData, context);
42
+ }
43
+ else if (streamData.type === stream_1.StreamDataType.WEBHOOK) {
44
+ await dispatchWebHook(instance, streamData, context);
45
+ }
46
+ else if (streamData.type === stream_1.StreamDataType.TRANSITION) {
47
+ await dispatchTransition(instance, streamData, context);
48
+ }
49
+ else if (streamData.type === stream_1.StreamDataType.AWAIT) {
50
+ await dispatchAwait(instance, streamData, context);
51
+ }
52
+ else if (streamData.type === stream_1.StreamDataType.RESULT) {
53
+ await dispatchResult(instance, streamData, context);
54
+ }
55
+ else {
56
+ await dispatchWorkerResult(instance, streamData, context);
57
+ }
58
+ instance.logger.debug('engine-process-end', {
59
+ jid: streamData.metadata.jid,
60
+ gid: streamData.metadata.gid,
61
+ aid: streamData.metadata.aid,
62
+ });
63
+ }
64
+ exports.processStreamMessage = processStreamMessage;
65
+ async function dispatchTimeHook(instance, streamData, context) {
66
+ const handler = (await instance.initActivity(`.${streamData.metadata.aid}`, context.data, context));
67
+ await handler.processTimeHookEvent(streamData.metadata.jid);
68
+ }
69
+ async function dispatchWebHook(instance, streamData, context) {
70
+ const handler = (await instance.initActivity(`.${streamData.metadata.aid}`, context.data, context));
71
+ await handler.processWebHookEvent(streamData.status, streamData.code);
72
+ }
73
+ async function dispatchTransition(instance, streamData, context) {
74
+ const handler = await instance.initActivity(`.${streamData.metadata.aid}`, context.data, context);
75
+ await handler.process();
76
+ }
77
+ async function dispatchAwait(instance, streamData, context) {
78
+ context.metadata = {
79
+ ...context.metadata,
80
+ pj: streamData.metadata.jid,
81
+ pg: streamData.metadata.gid,
82
+ pd: streamData.metadata.dad,
83
+ pa: streamData.metadata.aid,
84
+ px: streamData.metadata.await === false,
85
+ trc: streamData.metadata.trc,
86
+ spn: streamData.metadata.spn,
87
+ };
88
+ const handler = (await instance.initActivity(streamData.metadata.topic, streamData.data, context));
89
+ await handler.process();
90
+ }
91
+ async function dispatchResult(instance, streamData, context) {
92
+ const handler = (await instance.initActivity(`.${context.metadata.aid}`, streamData.data, context));
93
+ await handler.processEvent(streamData.status, streamData.code);
94
+ }
95
+ async function dispatchWorkerResult(instance, streamData, context) {
96
+ const handler = (await instance.initActivity(`.${streamData.metadata.aid}`, streamData.data, context));
97
+ await handler.processEvent(streamData.status, streamData.code, 'output');
98
+ }
@@ -1,10 +1,25 @@
1
- import { Await } from '../activities/await';
2
- import { Cycle } from '../activities/cycle';
3
- import { Hook } from '../activities/hook';
4
- import { Interrupt } from '../activities/interrupt';
5
- import { Signal } from '../activities/signal';
6
- import { Worker } from '../activities/worker';
7
- import { Trigger } from '../activities/trigger';
1
+ /**
2
+ * EngineService the workflow execution engine.
3
+ *
4
+ * Consumes stream messages from the router and dispatches them
5
+ * to the appropriate activity handler (Trigger, Worker, Hook, …).
6
+ *
7
+ * Each section delegates to a purpose-specific module inside `engine/`.
8
+ * Open the module when you need implementation detail; read this file
9
+ * when you need the big picture.
10
+ *
11
+ * Lifecycle (maps to modules):
12
+ * 1. INIT → init.ts (channel setup, router, config)
13
+ * 2. VERSION → version.ts (app version resolution, caching)
14
+ * 3. SCHEMA → schema.ts (activity lookup, handler factory)
15
+ * 4. COMPILE → compiler.ts (YAML plan & deploy)
16
+ * 5. REPORT → reporting.ts (stats, IDs, query resolution)
17
+ * 6. DISPATCH → dispatch.ts (stream message → activity handler)
18
+ * 7. COMPLETION → completion.ts (parent notify, cleanup, expiry)
19
+ * 8. SIGNAL → signal.ts (webhook/timehook delivery, fan-out)
20
+ * 9. PUB/SUB → pubsub.ts (topic messaging, subscriptions)
21
+ * 10. STATE → state.ts (job state retrieval, export)
22
+ */
8
23
  import { ExporterService } from '../exporter';
9
24
  import { ILogger } from '../logger';
10
25
  import { Router } from '../router';
@@ -17,19 +32,20 @@ import { AppVID } from '../../types/app';
17
32
  import { ActivityType } from '../../types/activity';
18
33
  import { CacheMode } from '../../types/cache';
19
34
  import { ExportOptions, JobExport } from '../../types/exporter';
20
- import { JobState, JobData, JobMetadata, JobOutput, JobStatus, JobInterruptOptions, JobCompletionOptions, ExtensionType } from '../../types/job';
35
+ import { JobState, JobData, JobOutput, JobStatus, JobInterruptOptions, JobCompletionOptions, ExtensionType } from '../../types/job';
21
36
  import { HotMeshApps, HotMeshConfig, HotMeshManifest, HotMeshSettings } from '../../types/hotmesh';
22
37
  import { ProviderClient, ProviderTransaction } from '../../types/provider';
23
38
  import { JobMessageCallback } from '../../types/quorum';
24
39
  import { StringAnyType, StringStringType } from '../../types/serializer';
25
40
  import { GetStatsOptions, IdsResponse, JobStatsInput, StatsResponse } from '../../types/stats';
26
- import { StreamCode, StreamData, StreamDataResponse, StreamError, StreamStatus } from '../../types/stream';
41
+ import { StreamCode, StreamData, StreamDataResponse, StreamStatus } from '../../types/stream';
27
42
  import { WorkListTaskType } from '../../types/task';
28
43
  declare class EngineService {
29
44
  namespace: string;
30
45
  apps: HotMeshApps | null;
31
46
  appId: string;
32
47
  guid: string;
48
+ inited: string;
33
49
  exporter: ExporterService | null;
34
50
  /** @hidden */
35
51
  search: SearchService<ProviderClient> | null;
@@ -47,9 +63,6 @@ declare class EngineService {
47
63
  cacheMode: CacheMode;
48
64
  untilVersion: string | null;
49
65
  jobCallbacks: Record<string, JobMessageCallback>;
50
- reporting: boolean;
51
- jobId: number;
52
- inited: string;
53
66
  /**
54
67
  * @private
55
68
  */
@@ -61,33 +74,10 @@ declare class EngineService {
61
74
  /**
62
75
  * @private
63
76
  */
64
- verifyEngineFields(config: HotMeshConfig): void;
65
- /**
66
- * @private
67
- */
68
- initSearchChannel(search: ProviderClient, store?: ProviderClient): Promise<void>;
69
- /**
70
- * @private
71
- */
72
- initStoreChannel(store: ProviderClient): Promise<void>;
73
- /**
74
- * @private
75
- */
76
- initSubChannel(sub: ProviderClient, store: ProviderClient): Promise<void>;
77
- /**
78
- * @private
79
- */
80
- initStreamChannel(stream: ProviderClient, store: ProviderClient): Promise<void>;
81
- /**
82
- * @private
83
- */
84
- initRouter(config: HotMeshConfig): Promise<Router<StreamService<ProviderClient, ProviderTransaction>>>;
77
+ getSettings(): Promise<HotMeshSettings>;
85
78
  /**
86
- * resolves the distributed executable version using a delay
87
- * to allow deployment race conditions to resolve
88
79
  * @private
89
80
  */
90
- fetchAndVerifyVID(vid: AppVID, count?: number): Promise<AppVID>;
91
81
  getVID(vid?: AppVID): Promise<AppVID>;
92
82
  /**
93
83
  * @private
@@ -96,28 +86,11 @@ declare class EngineService {
96
86
  /**
97
87
  * @private
98
88
  */
99
- routeToSubscribers(topic: string, message: JobOutput): Promise<void>;
89
+ initActivity(topic: string, data?: JobData, context?: JobState): Promise<any>;
100
90
  /**
101
91
  * @private
102
92
  */
103
- processWebHooks(): Promise<void>;
104
- /**
105
- * @private
106
- */
107
- processTimeHooks(): Promise<void>;
108
- /**
109
- * @private
110
- */
111
- throttle(delayInMillis: number): Promise<void>;
112
- /**
113
- * @private
114
- */
115
- initActivity(topic: string, data?: JobData, context?: JobState): Promise<Await | Cycle | Hook | Signal | Trigger | Worker | Interrupt>;
116
93
  getSchema(topic: string): Promise<[activityId: string, schema: ActivityType]>;
117
- /**
118
- * @private
119
- */
120
- getSettings(): Promise<HotMeshSettings>;
121
94
  /**
122
95
  * @private
123
96
  */
@@ -137,7 +110,7 @@ declare class EngineService {
137
110
  /**
138
111
  * @private
139
112
  */
140
- getIds(topic: string, query: JobStatsInput, queryFacets?: any[]): Promise<IdsResponse>;
113
+ getIds(topic: string, query: JobStatsInput, queryFacets?: string[]): Promise<IdsResponse>;
141
114
  /**
142
115
  * @private
143
116
  */
@@ -157,22 +130,16 @@ declare class EngineService {
157
130
  /**
158
131
  * @private
159
132
  */
160
- resolveError(metadata: JobMetadata): StreamError | undefined;
133
+ interrupt(topic: string, jobId: string, options?: JobInterruptOptions): Promise<string>;
161
134
  /**
162
135
  * @private
163
136
  */
164
- interrupt(topic: string, jobId: string, options?: JobInterruptOptions): Promise<string>;
137
+ scrub(jobId: string): Promise<void>;
165
138
  /**
166
139
  * @private
167
140
  */
168
- scrub(jobId: string): Promise<void>;
141
+ runJobCompletionTasks(context: JobState, options?: JobCompletionOptions, transaction?: ProviderTransaction): Promise<string | void>;
169
142
  /**
170
- * Delivers a signal (data payload) to a paused hook activity,
171
- * resuming its Leg 2 execution. The `topic` must match a hook rule
172
- * defined in the YAML graph's `hooks` section. The engine locates
173
- * the target activity and dimension for reentry based on the hook
174
- * rule's match conditions.
175
- *
176
143
  * @private
177
144
  */
178
145
  signal(topic: string, data: JobData, status?: StreamStatus, code?: StreamCode, transaction?: ProviderTransaction): Promise<string>;
@@ -181,13 +148,25 @@ declare class EngineService {
181
148
  */
182
149
  hookTime(jobId: string, gId: string, topicOrActivity: string, type?: WorkListTaskType): Promise<string | void>;
183
150
  /**
184
- * Fan-out variant of `signal()` that delivers data to **all**
185
- * paused workflows matching a search query. Useful for resuming
186
- * a batch of workflows waiting on the same external event.
187
- *
188
151
  * @private
189
152
  */
190
153
  signalAll(hookTopic: string, data: JobData, keyResolver: JobStatsInput, queryFacets?: string[]): Promise<string[]>;
154
+ /**
155
+ * @private
156
+ */
157
+ routeToSubscribers(topic: string, message: JobOutput): Promise<void>;
158
+ /**
159
+ * @private
160
+ */
161
+ processWebHooks(): Promise<void>;
162
+ /**
163
+ * @private
164
+ */
165
+ processTimeHooks(): Promise<void>;
166
+ /**
167
+ * @private
168
+ */
169
+ throttle(delayInMillis: number): Promise<void>;
191
170
  /**
192
171
  * @private
193
172
  */
@@ -219,11 +198,11 @@ declare class EngineService {
219
198
  /**
220
199
  * @private
221
200
  */
222
- getPublishesTopic(context: JobState): Promise<string>;
201
+ pubPermSubs(context: JobState, jobOutput: JobOutput, emit?: boolean, transaction?: ProviderTransaction): Promise<void>;
223
202
  /**
224
203
  * @private
225
204
  */
226
- pubPermSubs(context: JobState, jobOutput: JobOutput, emit?: boolean, transaction?: ProviderTransaction): Promise<void>;
205
+ getPublishesTopic(context: JobState): Promise<string>;
227
206
  /**
228
207
  * @private
229
208
  */
@@ -240,17 +219,6 @@ declare class EngineService {
240
219
  * @private
241
220
  */
242
221
  hasOneTimeSubscription(context: JobState): boolean;
243
- /**
244
- * @private
245
- */
246
- runJobCompletionTasks(context: JobState, options?: JobCompletionOptions, transaction?: ProviderTransaction): Promise<string | void>;
247
- /**
248
- * Job hash expiration is typically reliant on the metadata field
249
- * if the activity concludes normally. However, if the job is `interrupted`,
250
- * it will be expired immediately.
251
- * @private
252
- */
253
- resolveExpires(context: JobState, options: JobCompletionOptions): number;
254
222
  /**
255
223
  * @private
256
224
  */