@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,14 @@
1
+ import { Context } from './common';
2
+ /**
3
+ * Returns a context session handle for interacting with the workflow's JSONB context storage.
4
+ * @returns {Promise<Context>} A context session for workflow data.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * const context = await workflow.context();
9
+ * await context.set({ user: { id: 123 } });
10
+ * await context.merge({ user: { name: "John" } });
11
+ * const user = await context.get("user");
12
+ * ```
13
+ */
14
+ export declare function context(): Promise<Context>;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.context = void 0;
4
+ const common_1 = require("./common");
5
+ /**
6
+ * Returns a context session handle for interacting with the workflow's JSONB context storage.
7
+ * @returns {Promise<Context>} A context session for workflow data.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * const context = await workflow.context();
12
+ * await context.set({ user: { id: 123 } });
13
+ * await context.merge({ user: { name: "John" } });
14
+ * const user = await context.get("user");
15
+ * ```
16
+ */
17
+ async function context() {
18
+ const store = common_1.asyncLocalStorage.getStore();
19
+ const workflowId = store.get('workflowId');
20
+ const workflowDimension = store.get('workflowDimension') ?? '';
21
+ const workflowTopic = store.get('workflowTopic');
22
+ const connection = store.get('connection');
23
+ const namespace = store.get('namespace');
24
+ const COUNTER = store.get('counter');
25
+ const execIndex = COUNTER.counter = COUNTER.counter + 1;
26
+ const hotMeshClient = await common_1.WorkerService.getHotMesh(workflowTopic, {
27
+ connection,
28
+ namespace,
29
+ });
30
+ const contextSessionId = `-context${workflowDimension}-${execIndex}`;
31
+ return new common_1.Context(workflowId, hotMeshClient, contextSessionId);
32
+ }
33
+ exports.context = context;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Determines if a replayed execution result already exists for the given prefix.
3
+ * @private
4
+ * @param {string} prefix - Identifier prefix (e.g., 'proxy', 'child', 'start', 'wait', etc.)
5
+ * @returns {Promise<[boolean, number, any]>} A tuple: [alreadyRan, executionIndex, restoredData]
6
+ */
7
+ export declare function didRun(prefix: string): Promise<[boolean, number, any]>;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.didRun = void 0;
4
+ const common_1 = require("./common");
5
+ const context_1 = require("./context");
6
+ /**
7
+ * Determines if a replayed execution result already exists for the given prefix.
8
+ * @private
9
+ * @param {string} prefix - Identifier prefix (e.g., 'proxy', 'child', 'start', 'wait', etc.)
10
+ * @returns {Promise<[boolean, number, any]>} A tuple: [alreadyRan, executionIndex, restoredData]
11
+ */
12
+ async function didRun(prefix) {
13
+ const { COUNTER, replay, workflowDimension } = (0, context_1.getContext)();
14
+ const execIndex = COUNTER.counter = COUNTER.counter + 1;
15
+ const sessionId = `-${prefix}${workflowDimension}-${execIndex}-`;
16
+ if (sessionId in replay) {
17
+ const restored = common_1.SerializerService.fromString(replay[sessionId]);
18
+ return [true, execIndex, restored];
19
+ }
20
+ return [false, execIndex, null];
21
+ }
22
+ exports.didRun = didRun;
@@ -0,0 +1,11 @@
1
+ import { StringAnyType } from './common';
2
+ /**
3
+ * Emits events to the event bus provider. Topics are prefixed with the quorum namespace.
4
+ *
5
+ * @param {StringAnyType} events - A mapping of topic => message to publish.
6
+ * @param {{ once: boolean }} [config={ once: true }] - If `once` is true, events are emitted only once.
7
+ * @returns {Promise<boolean>} True after emission completes.
8
+ */
9
+ export declare function emit(events: StringAnyType, config?: {
10
+ once: boolean;
11
+ }): Promise<boolean>;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.emit = void 0;
4
+ const common_1 = require("./common");
5
+ const isSideEffectAllowed_1 = require("./isSideEffectAllowed");
6
+ /**
7
+ * Emits events to the event bus provider. Topics are prefixed with the quorum namespace.
8
+ *
9
+ * @param {StringAnyType} events - A mapping of topic => message to publish.
10
+ * @param {{ once: boolean }} [config={ once: true }] - If `once` is true, events are emitted only once.
11
+ * @returns {Promise<boolean>} True after emission completes.
12
+ */
13
+ async function emit(events, config = { once: true }) {
14
+ const store = common_1.asyncLocalStorage.getStore();
15
+ const workflowTopic = store.get('workflowTopic');
16
+ const connection = store.get('connection');
17
+ const namespace = store.get('namespace');
18
+ const hotMeshClient = await common_1.WorkerService.getHotMesh(workflowTopic, {
19
+ connection,
20
+ namespace,
21
+ });
22
+ if (!config.once || await (0, isSideEffectAllowed_1.isSideEffectAllowed)(hotMeshClient, 'emit')) {
23
+ for (const [topic, message] of Object.entries(events)) {
24
+ await hotMeshClient.quorum.pub({ topic, message });
25
+ }
26
+ }
27
+ return true;
28
+ }
29
+ exports.emit = emit;
@@ -0,0 +1,9 @@
1
+ import { StringStringType } from './common';
2
+ /**
3
+ * Adds custom user data to the backend workflow record (writes to HASH).
4
+ * Runs exactly once during workflow execution.
5
+ *
6
+ * @param {StringStringType} fields - Key-value fields to enrich the workflow record.
7
+ * @returns {Promise<boolean>} True when enrichment is completed.
8
+ */
9
+ export declare function enrich(fields: StringStringType): Promise<boolean>;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.enrich = void 0;
4
+ const searchMethods_1 = require("./searchMethods");
5
+ /**
6
+ * Adds custom user data to the backend workflow record (writes to HASH).
7
+ * Runs exactly once during workflow execution.
8
+ *
9
+ * @param {StringStringType} fields - Key-value fields to enrich the workflow record.
10
+ * @returns {Promise<boolean>} True when enrichment is completed.
11
+ */
12
+ async function enrich(fields) {
13
+ const searchSession = await (0, searchMethods_1.search)();
14
+ await searchSession.set(fields);
15
+ return true;
16
+ }
17
+ exports.enrich = enrich;
@@ -0,0 +1,18 @@
1
+ import { WorkflowOptions } from './common';
2
+ /**
3
+ * Spawns a child workflow and awaits the result, or if `await` is false, returns immediately.
4
+ * @template T
5
+ * @param {WorkflowOptions} options - Workflow options.
6
+ * @returns {Promise<T>} Result of the child workflow.
7
+ */
8
+ export declare function execChild<T>(options: WorkflowOptions): Promise<T>;
9
+ /**
10
+ * Alias for execChild.
11
+ */
12
+ export declare const executeChild: typeof execChild;
13
+ /**
14
+ * Spawns a child workflow and returns the child Job ID without awaiting its completion.
15
+ * @param {WorkflowOptions} options - Workflow options.
16
+ * @returns {Promise<string>} The child job ID.
17
+ */
18
+ export declare function startChild(options: WorkflowOptions): Promise<string>;
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.startChild = exports.executeChild = exports.execChild = void 0;
4
+ const common_1 = require("./common");
5
+ const context_1 = require("./context");
6
+ const didRun_1 = require("./didRun");
7
+ /**
8
+ * Constructs the payload necessary to spawn a child workflow.
9
+ * @private
10
+ */
11
+ function getChildInterruptPayload(context, options, execIndex) {
12
+ const { workflowId, originJobId, workflowDimension, expire } = context;
13
+ let childJobId;
14
+ if (options.workflowId) {
15
+ childJobId = options.workflowId;
16
+ }
17
+ else if (options.entity) {
18
+ childJobId = `${options.entity}-${(0, common_1.guid)()}-${workflowDimension}-${execIndex}`;
19
+ }
20
+ else {
21
+ childJobId = `-${options.workflowName}-${(0, common_1.guid)()}-${workflowDimension}-${execIndex}`;
22
+ }
23
+ const parentWorkflowId = workflowId;
24
+ const taskQueueName = options.taskQueue ?? options.entity;
25
+ const workflowName = options.entity ?? options.workflowName;
26
+ const workflowTopic = `${taskQueueName}-${workflowName}`;
27
+ return {
28
+ arguments: [...(options.args || [])],
29
+ await: options?.await ?? true,
30
+ backoffCoefficient: options?.config?.backoffCoefficient ?? common_1.HMSH_MEMFLOW_EXP_BACKOFF,
31
+ index: execIndex,
32
+ maximumAttempts: options?.config?.maximumAttempts ?? common_1.HMSH_MEMFLOW_MAX_ATTEMPTS,
33
+ maximumInterval: (0, common_1.s)(options?.config?.maximumInterval ?? common_1.HMSH_MEMFLOW_MAX_INTERVAL),
34
+ originJobId: originJobId ?? workflowId,
35
+ expire: options.expire ?? expire,
36
+ persistent: options.persistent,
37
+ signalIn: options.signalIn,
38
+ parentWorkflowId,
39
+ workflowDimension: workflowDimension,
40
+ workflowId: childJobId,
41
+ workflowTopic,
42
+ };
43
+ }
44
+ /**
45
+ * Spawns a child workflow and awaits the result, or if `await` is false, returns immediately.
46
+ * @template T
47
+ * @param {WorkflowOptions} options - Workflow options.
48
+ * @returns {Promise<T>} Result of the child workflow.
49
+ */
50
+ async function execChild(options) {
51
+ const isStartChild = options.await === false;
52
+ const prefix = isStartChild ? 'start' : 'child';
53
+ const [didRunAlready, execIndex, result] = await (0, didRun_1.didRun)(prefix);
54
+ const context = (0, context_1.getContext)();
55
+ const { canRetry, interruptionRegistry } = context;
56
+ if (didRunAlready) {
57
+ if (result?.$error && (!result.$error.is_stream_error || !canRetry)) {
58
+ if (options?.config?.throwOnError !== false) {
59
+ const code = result.$error.code;
60
+ const message = result.$error.message;
61
+ const stack = result.$error.stack;
62
+ if (code === common_1.HMSH_CODE_MEMFLOW_FATAL) {
63
+ throw new common_1.MemFlowFatalError(message, stack);
64
+ }
65
+ else if (code === common_1.HMSH_CODE_MEMFLOW_MAXED) {
66
+ throw new common_1.MemFlowMaxedError(message, stack);
67
+ }
68
+ else if (code === common_1.HMSH_CODE_MEMFLOW_TIMEOUT) {
69
+ throw new common_1.MemFlowTimeoutError(message, stack);
70
+ }
71
+ else {
72
+ throw new common_1.MemFlowRetryError(message, stack);
73
+ }
74
+ }
75
+ return result.$error;
76
+ }
77
+ else if (!result?.$error) {
78
+ return result.data;
79
+ }
80
+ }
81
+ const interruptionMessage = getChildInterruptPayload(context, options, execIndex);
82
+ interruptionRegistry.push({
83
+ code: common_1.HMSH_CODE_MEMFLOW_CHILD,
84
+ ...interruptionMessage,
85
+ });
86
+ await (0, common_1.sleepImmediate)();
87
+ throw new common_1.MemFlowChildError(interruptionMessage);
88
+ }
89
+ exports.execChild = execChild;
90
+ /**
91
+ * Alias for execChild.
92
+ */
93
+ exports.executeChild = execChild;
94
+ /**
95
+ * Spawns a child workflow and returns the child Job ID without awaiting its completion.
96
+ * @param {WorkflowOptions} options - Workflow options.
97
+ * @returns {Promise<string>} The child job ID.
98
+ */
99
+ async function startChild(options) {
100
+ return execChild({ ...options, await: false });
101
+ }
102
+ exports.startChild = startChild;
@@ -0,0 +1,65 @@
1
+ import { HookOptions } from './common';
2
+ /**
3
+ * Extended hook options that include signal configuration
4
+ */
5
+ export interface ExecHookOptions extends HookOptions {
6
+ /** Signal ID to send after hook execution */
7
+ signalId: string;
8
+ }
9
+ /**
10
+ * Executes a hook function and awaits the signal response.
11
+ * This is a convenience method that combines `hook()` and `waitFor()` operations.
12
+ *
13
+ * **Signal Injection**: The `signalId` is automatically injected as the LAST argument
14
+ * to the hooked function. The hooked function should check for this signal parameter
15
+ * and emit the signal when processing is complete.
16
+ *
17
+ * This behaves like `execChild` but targets the existing workflow instead of
18
+ * spawning a new workflow.
19
+ *
20
+ * @template T
21
+ * @param {ExecHookOptions} options - Hook configuration with signal ID.
22
+ * @returns {Promise<T>} The signal result from the hooked function.
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * // Execute a hook and await its signal response
27
+ * const result = await MemFlow.workflow.execHook({
28
+ * taskQueue: 'processing',
29
+ * workflowName: 'processData',
30
+ * args: ['user123', 'batch-process'],
31
+ * signalId: 'processing-complete'
32
+ * });
33
+ *
34
+ * // The hooked function receives the signal as the last argument:
35
+ * export async function processData(userId: string, processType: string, signalInfo?: { signal: string }) {
36
+ * // ... do processing work ...
37
+ * const result = { userId, processType, status: 'completed' };
38
+ *
39
+ * // Check if called via execHook (signalInfo will be present)
40
+ * if (signalInfo?.signal) {
41
+ * await MemFlow.workflow.signal(signalInfo.signal, result);
42
+ * }
43
+ *
44
+ * return result;
45
+ * }
46
+ * ```
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * // Alternative pattern - check if last arg is signal object
51
+ * export async function myHookFunction(arg1: string, arg2: number, ...rest: any[]) {
52
+ * // ... process arg1 and arg2 ...
53
+ * const result = { processed: true, data: [arg1, arg2] };
54
+ *
55
+ * // Check if last argument is a signal object
56
+ * const lastArg = rest[rest.length - 1];
57
+ * if (lastArg && typeof lastArg === 'object' && lastArg.signal) {
58
+ * await MemFlow.workflow.signal(lastArg.signal, result);
59
+ * }
60
+ *
61
+ * return result;
62
+ * }
63
+ * ```
64
+ */
65
+ export declare function execHook<T>(options: ExecHookOptions): Promise<T>;
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.execHook = void 0;
4
+ const hook_1 = require("./hook");
5
+ const waitFor_1 = require("./waitFor");
6
+ /**
7
+ * Executes a hook function and awaits the signal response.
8
+ * This is a convenience method that combines `hook()` and `waitFor()` operations.
9
+ *
10
+ * **Signal Injection**: The `signalId` is automatically injected as the LAST argument
11
+ * to the hooked function. The hooked function should check for this signal parameter
12
+ * and emit the signal when processing is complete.
13
+ *
14
+ * This behaves like `execChild` but targets the existing workflow instead of
15
+ * spawning a new workflow.
16
+ *
17
+ * @template T
18
+ * @param {ExecHookOptions} options - Hook configuration with signal ID.
19
+ * @returns {Promise<T>} The signal result from the hooked function.
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * // Execute a hook and await its signal response
24
+ * const result = await MemFlow.workflow.execHook({
25
+ * taskQueue: 'processing',
26
+ * workflowName: 'processData',
27
+ * args: ['user123', 'batch-process'],
28
+ * signalId: 'processing-complete'
29
+ * });
30
+ *
31
+ * // The hooked function receives the signal as the last argument:
32
+ * export async function processData(userId: string, processType: string, signalInfo?: { signal: string }) {
33
+ * // ... do processing work ...
34
+ * const result = { userId, processType, status: 'completed' };
35
+ *
36
+ * // Check if called via execHook (signalInfo will be present)
37
+ * if (signalInfo?.signal) {
38
+ * await MemFlow.workflow.signal(signalInfo.signal, result);
39
+ * }
40
+ *
41
+ * return result;
42
+ * }
43
+ * ```
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * // Alternative pattern - check if last arg is signal object
48
+ * export async function myHookFunction(arg1: string, arg2: number, ...rest: any[]) {
49
+ * // ... process arg1 and arg2 ...
50
+ * const result = { processed: true, data: [arg1, arg2] };
51
+ *
52
+ * // Check if last argument is a signal object
53
+ * const lastArg = rest[rest.length - 1];
54
+ * if (lastArg && typeof lastArg === 'object' && lastArg.signal) {
55
+ * await MemFlow.workflow.signal(lastArg.signal, result);
56
+ * }
57
+ *
58
+ * return result;
59
+ * }
60
+ * ```
61
+ */
62
+ async function execHook(options) {
63
+ // Create hook options with signal field added to args
64
+ const hookOptions = {
65
+ ...options,
66
+ args: [...options.args, { signal: options.signalId }]
67
+ };
68
+ // Execute the hook with the signal information
69
+ await (0, hook_1.hook)(hookOptions);
70
+ // Wait for the signal response and return it
71
+ return await (0, waitFor_1.waitFor)(options.signalId);
72
+ }
73
+ exports.execHook = execHook;
@@ -0,0 +1,9 @@
1
+ import { HookOptions } from './common';
2
+ /**
3
+ * Spawns a hook from the main thread or a hook thread.
4
+ * If entity/workflowName are not provided, defaults to the current workflow.
5
+ *
6
+ * @param {HookOptions} options - Hook configuration options.
7
+ * @returns {Promise<string>} The resulting hook/stream ID.
8
+ */
9
+ export declare function hook(options: HookOptions): Promise<string>;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hook = void 0;
4
+ const common_1 = require("./common");
5
+ const context_1 = require("./context");
6
+ const isSideEffectAllowed_1 = require("./isSideEffectAllowed");
7
+ /**
8
+ * Spawns a hook from the main thread or a hook thread.
9
+ * If entity/workflowName are not provided, defaults to the current workflow.
10
+ *
11
+ * @param {HookOptions} options - Hook configuration options.
12
+ * @returns {Promise<string>} The resulting hook/stream ID.
13
+ */
14
+ async function hook(options) {
15
+ const { workflowId, connection, namespace, workflowTopic } = (0, context_1.getContext)();
16
+ const hotMeshClient = await common_1.WorkerService.getHotMesh(workflowTopic, {
17
+ connection,
18
+ namespace,
19
+ });
20
+ if (await (0, isSideEffectAllowed_1.isSideEffectAllowed)(hotMeshClient, 'hook')) {
21
+ const targetWorkflowId = options.workflowId ?? workflowId;
22
+ let targetTopic;
23
+ if (options.entity || (options.taskQueue && options.workflowName)) {
24
+ targetTopic = `${options.taskQueue ?? options.entity}-${options.entity ?? options.workflowName}`;
25
+ }
26
+ else {
27
+ targetTopic = workflowTopic;
28
+ }
29
+ // DEFENSIVE CHECK: Prevent infinite loops
30
+ if (targetTopic === workflowTopic && !options.entity && !options.taskQueue) {
31
+ throw new Error(`MemFlow Hook Error: Potential infinite loop detected!\n\n` +
32
+ `The hook would target the same workflow topic ('${workflowTopic}') as the current workflow, ` +
33
+ `creating an infinite loop.\n\n` +
34
+ `To fix this, provide either:\n` +
35
+ `1. 'taskQueue' parameter: MemFlow.workflow.hook({ taskQueue: 'your-queue', workflowName: '${options.workflowName}', args: [...] })\n` +
36
+ `2. 'entity' parameter: MemFlow.workflow.hook({ entity: 'your-entity', args: [...] })\n\n` +
37
+ `Current workflow topic: ${workflowTopic}\n` +
38
+ `Target topic would be: ${targetTopic}\n` +
39
+ `Provided options: ${JSON.stringify({
40
+ workflowName: options.workflowName,
41
+ taskQueue: options.taskQueue,
42
+ entity: options.entity
43
+ }, null, 2)}`);
44
+ }
45
+ const payload = {
46
+ arguments: [...options.args],
47
+ id: targetWorkflowId,
48
+ workflowTopic: targetTopic,
49
+ backoffCoefficient: options.config?.backoffCoefficient || common_1.HMSH_MEMFLOW_EXP_BACKOFF,
50
+ maximumAttempts: options.config?.maximumAttempts || common_1.HMSH_MEMFLOW_MAX_ATTEMPTS,
51
+ maximumInterval: (0, common_1.s)(options?.config?.maximumInterval ?? common_1.HMSH_MEMFLOW_MAX_INTERVAL),
52
+ };
53
+ return await hotMeshClient.hook(`${namespace}.flow.signal`, payload, common_1.StreamStatus.PENDING, 202);
54
+ }
55
+ }
56
+ exports.hook = hook;
@@ -0,0 +1,74 @@
1
+ import { getContext } from './context';
2
+ import { didRun } from './didRun';
3
+ import { isSideEffectAllowed } from './isSideEffectAllowed';
4
+ import { trace } from './trace';
5
+ import { enrich } from './enrich';
6
+ import { emit } from './emit';
7
+ import { execChild, startChild } from './execChild';
8
+ import { execHook } from './execHook';
9
+ import { proxyActivities } from './proxyActivities';
10
+ import { search } from './searchMethods';
11
+ import { random } from './random';
12
+ import { signal } from './signal';
13
+ import { hook } from './hook';
14
+ import { interrupt } from './interrupt';
15
+ import { all } from './all';
16
+ import { sleepFor } from './sleepFor';
17
+ import { waitFor } from './waitFor';
18
+ import { HotMesh } from './common';
19
+ import { context } from './contextMethods';
20
+ /**
21
+ * The WorkflowService class provides a set of static methods to be used within a workflow function.
22
+ * These methods ensure deterministic replay, persistence of state, and error handling across
23
+ * re-entrant workflow executions.
24
+ *
25
+ * By refactoring the original single-file implementation into submodules,
26
+ * we maintain clear separation of concerns and improved maintainability,
27
+ * while preserving type information and full functionality.
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * import { MemFlow } from '@hotmeshio/hotmesh';
32
+ *
33
+ * export async function waitForExample(): Promise<[boolean, number]> {
34
+ * const [s1, s2] = await Promise.all([
35
+ * MemFlow.workflow.waitFor<boolean>('my-sig-nal-1'),
36
+ * MemFlow.workflow.waitFor<number>('my-sig-nal-2')
37
+ * ]);
38
+ * return [s1, s2];
39
+ * }
40
+ * ```
41
+ */
42
+ export declare class WorkflowService {
43
+ /**
44
+ * @private
45
+ * The constructor is private to prevent instantiation;
46
+ * all methods are static.
47
+ */
48
+ private constructor();
49
+ static getContext: typeof getContext;
50
+ static didRun: typeof didRun;
51
+ static isSideEffectAllowed: typeof isSideEffectAllowed;
52
+ static trace: typeof trace;
53
+ static enrich: typeof enrich;
54
+ static emit: typeof emit;
55
+ static execChild: typeof execChild;
56
+ static executeChild: typeof execChild;
57
+ static startChild: typeof startChild;
58
+ static execHook: typeof execHook;
59
+ static proxyActivities: typeof proxyActivities;
60
+ static search: typeof search;
61
+ static context: typeof context;
62
+ static random: typeof random;
63
+ static signal: typeof signal;
64
+ static hook: typeof hook;
65
+ static interrupt: typeof interrupt;
66
+ static all: typeof all;
67
+ static sleepFor: typeof sleepFor;
68
+ static waitFor: typeof waitFor;
69
+ /**
70
+ * Return a handle to the HotMesh client hosting the workflow execution.
71
+ * @returns {Promise<HotMesh>} The HotMesh client instance.
72
+ */
73
+ static getHotMesh(): Promise<HotMesh>;
74
+ }
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WorkflowService = void 0;
4
+ const context_1 = require("./context");
5
+ const didRun_1 = require("./didRun");
6
+ const isSideEffectAllowed_1 = require("./isSideEffectAllowed");
7
+ const trace_1 = require("./trace");
8
+ const enrich_1 = require("./enrich");
9
+ const emit_1 = require("./emit");
10
+ const execChild_1 = require("./execChild");
11
+ const execHook_1 = require("./execHook");
12
+ const proxyActivities_1 = require("./proxyActivities");
13
+ const searchMethods_1 = require("./searchMethods");
14
+ const random_1 = require("./random");
15
+ const signal_1 = require("./signal");
16
+ const hook_1 = require("./hook");
17
+ const interrupt_1 = require("./interrupt");
18
+ const all_1 = require("./all");
19
+ const sleepFor_1 = require("./sleepFor");
20
+ const waitFor_1 = require("./waitFor");
21
+ const common_1 = require("./common");
22
+ const contextMethods_1 = require("./contextMethods");
23
+ /**
24
+ * The WorkflowService class provides a set of static methods to be used within a workflow function.
25
+ * These methods ensure deterministic replay, persistence of state, and error handling across
26
+ * re-entrant workflow executions.
27
+ *
28
+ * By refactoring the original single-file implementation into submodules,
29
+ * we maintain clear separation of concerns and improved maintainability,
30
+ * while preserving type information and full functionality.
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * import { MemFlow } from '@hotmeshio/hotmesh';
35
+ *
36
+ * export async function waitForExample(): Promise<[boolean, number]> {
37
+ * const [s1, s2] = await Promise.all([
38
+ * MemFlow.workflow.waitFor<boolean>('my-sig-nal-1'),
39
+ * MemFlow.workflow.waitFor<number>('my-sig-nal-2')
40
+ * ]);
41
+ * return [s1, s2];
42
+ * }
43
+ * ```
44
+ */
45
+ class WorkflowService {
46
+ /**
47
+ * @private
48
+ * The constructor is private to prevent instantiation;
49
+ * all methods are static.
50
+ */
51
+ constructor() { }
52
+ /**
53
+ * Return a handle to the HotMesh client hosting the workflow execution.
54
+ * @returns {Promise<HotMesh>} The HotMesh client instance.
55
+ */
56
+ static async getHotMesh() {
57
+ const store = common_1.asyncLocalStorage.getStore();
58
+ const workflowTopic = store.get('workflowTopic');
59
+ const connection = store.get('connection');
60
+ const namespace = store.get('namespace');
61
+ return await common_1.WorkerService.getHotMesh(workflowTopic, {
62
+ connection,
63
+ namespace,
64
+ });
65
+ }
66
+ }
67
+ WorkflowService.getContext = context_1.getContext;
68
+ WorkflowService.didRun = didRun_1.didRun;
69
+ WorkflowService.isSideEffectAllowed = isSideEffectAllowed_1.isSideEffectAllowed;
70
+ WorkflowService.trace = trace_1.trace;
71
+ WorkflowService.enrich = enrich_1.enrich;
72
+ WorkflowService.emit = emit_1.emit;
73
+ WorkflowService.execChild = execChild_1.execChild;
74
+ WorkflowService.executeChild = execChild_1.executeChild;
75
+ WorkflowService.startChild = execChild_1.startChild;
76
+ WorkflowService.execHook = execHook_1.execHook;
77
+ WorkflowService.proxyActivities = proxyActivities_1.proxyActivities;
78
+ WorkflowService.search = searchMethods_1.search;
79
+ WorkflowService.context = contextMethods_1.context;
80
+ WorkflowService.random = random_1.random;
81
+ WorkflowService.signal = signal_1.signal;
82
+ WorkflowService.hook = hook_1.hook;
83
+ WorkflowService.interrupt = interrupt_1.interrupt;
84
+ WorkflowService.all = all_1.all;
85
+ WorkflowService.sleepFor = sleepFor_1.sleepFor;
86
+ WorkflowService.waitFor = waitFor_1.waitFor;
87
+ exports.WorkflowService = WorkflowService;
@@ -0,0 +1,9 @@
1
+ import { JobInterruptOptions } from './common';
2
+ /**
3
+ * Interrupts a running job by sending an interruption request.
4
+ *
5
+ * @param {string} jobId - The ID of the job to interrupt.
6
+ * @param {JobInterruptOptions} options - Additional interruption options.
7
+ * @returns {Promise<string|void>} Result of the interruption, if any.
8
+ */
9
+ export declare function interrupt(jobId: string, options?: JobInterruptOptions): Promise<string | void>;